getairmail 0.0.2 → 0.0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,5 @@
1
+ source 'https://rubygems.org'
2
+ gem 'mail'
3
+ gem 'nokogiri'
4
+ # Specify your gem's dependencies in getairmail.gemspec
5
+ gemspec
data/README.md CHANGED
@@ -1,6 +1,7 @@
1
1
  # Getairmail
2
2
 
3
3
  TODO: Write a gem description
4
+ This gem read all emails from getairmail.com
4
5
 
5
6
  ## Installation
6
7
 
@@ -19,6 +20,17 @@ Or install it yourself as:
19
20
  ## Usage
20
21
 
21
22
  TODO: Write usage instructions here
23
+ First Time use:
24
+
25
+ If you have not any getairmail URL then call:
26
+
27
+ Getairmail::Email.new
28
+
29
+ It will return email and its url
30
+
31
+ Read email from getairmail. It will return Json of emails
32
+
33
+ Getairmail::Email.new(getairmail_url)
22
34
 
23
35
  ## Contributing
24
36
 
@@ -0,0 +1,41 @@
1
+ # Getairmail
2
+
3
+ TODO: Write a gem description
4
+ This gem read all emails from getairmail.com.
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ gem 'getairmail'
11
+
12
+ And then execute:
13
+
14
+ $ bundle
15
+
16
+ Or install it yourself as:
17
+
18
+ $ gem install getairmail
19
+
20
+ ## Usage
21
+
22
+ TODO: Write usage instructions here
23
+ First Time use:
24
+
25
+ If you have not any getairmail URL then call:
26
+
27
+ Getairmail::Email.new
28
+
29
+ It will return email and its url
30
+
31
+ Read email from getairmail. It will return Json of emails
32
+
33
+ Getairmail::Email.new(getairmail_url)
34
+
35
+ ## Contributing
36
+
37
+ 1. Fork it
38
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
39
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
40
+ 4. Push to the branch (`git push origin my-new-feature`)
41
+ 5. Create new Pull Request
@@ -2,10 +2,10 @@
2
2
  require File.expand_path('../lib/getairmail/version', __FILE__)
3
3
 
4
4
  Gem::Specification.new do |gem|
5
- gem.authors = ["vijay"]
6
- gem.email = ["vchouhan@isystango.com"]
5
+ gem.authors = ["vijay chouhan"]
6
+ gem.email = ["vijaychouhan.exams@gmail.com"]
7
7
  gem.description = "Read getairmail email"
8
- gem.summary = "Read getairmail email"
8
+ gem.summary = "This gem read all emails from getairmail.com"
9
9
  gem.homepage = ""
10
10
 
11
11
  gem.files = `git ls-files`.split($\)
@@ -0,0 +1,17 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/getairmail/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["vijay chouhan"]
6
+ gem.email = ["vijaychouhan.exams@gmail.com"]
7
+ gem.description = "Read getairmail email"
8
+ gem.summary = "This gem read all emails from getairmail.com"
9
+ gem.homepage = ""
10
+
11
+ gem.files = `git ls-files`.split($\)
12
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
+ gem.name = "getairmail"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = Getairmail::VERSION
17
+ end
@@ -0,0 +1,83 @@
1
+ require "getairmail/version"
2
+ require 'json'
3
+ require 'net/http'
4
+ require 'open-uri'
5
+ require 'nokogiri'
6
+ require 'mail'
7
+
8
+ module Getairmail
9
+
10
+ class Email
11
+ attr_reader :email_address, :url, :emails
12
+
13
+ # Creates a new Email object with a random email and URL
14
+ # @param [String] URL of the mail account web interface
15
+ # @return [Email] returns a new email object
16
+ def initialize(url = nil)
17
+ url ||= Net::HTTP.get(URI.parse('http://getairmail.com/random')).match(/href="([^"]+)"/)[1]
18
+ @url = url
19
+ puts "********GETAIRMAIL URL = #{@url} *************" # TODO For logging purpose need to delete it.
20
+ @email_address = Nokogiri::HTML.parse(open(@url)).css('#tempemail').first.attributes['value'].value
21
+ load_from_server
22
+ end
23
+
24
+ # Deletes the email you pass it
25
+ # @param [Mail] The email you want to delete
26
+ # @return [Boolean] Returns true if successful, else returns false
27
+ def delete(mail)
28
+ resp = Net::HTTP.new('getairmail.com').request(Net::HTTP::Delete.new("/d/#{mail.message_id}"))
29
+ if resp.code == "200"
30
+ @emails.delete_if{|email| email.message_id == mail.message_id }
31
+ true
32
+ else
33
+ false
34
+ end
35
+ end
36
+
37
+ # Deletes all emails
38
+ # @return [Boolean] Returns true if successfull, else returns false
39
+ def delete_all
40
+ count = 0
41
+ # For some reason it fails periodically, so I do it a few times
42
+ while @emails.any? and count < 3
43
+ @emails.each{|email| delete(email) }
44
+ count += 1
45
+ end
46
+ @emails.empty?
47
+ end
48
+
49
+ # Gets the emails from the web interface
50
+ # @return [Array] Array of emails (can be called with <Email>.emails)
51
+ def load_from_server
52
+ messages = JSON.parse(Nokogiri::HTML.parse(open(@url)).css('head script')[1].text.match(/messages = ({.+})/)[1])['m']
53
+ @emails = messages.map do |message|
54
+ Mail.new do
55
+ from message['f']
56
+ message_id message['u']
57
+ to @email_address
58
+ subject message['s']
59
+ body open("http://getairmail.com/html/#{message['u']}").read
60
+ end
61
+ end
62
+ end
63
+
64
+ def self.get_mail(url)
65
+ inbox_emails = self.new(url).load_from_server
66
+ if inbox_emails.blank?
67
+ wait_secs(12) #Wait for email
68
+ inbox_emails = self.new(url).load_from_server
69
+ end
70
+ return inbox_emails
71
+ end
72
+
73
+ def self.get_second_email(url)
74
+ inbox_emails = self.new(url).load_from_server
75
+ if(inbox_emails.blank? or inbox_emails.count!=2)
76
+ wait_secs(12) #Wait for email
77
+ inbox_emails = self.new(url).load_from_server
78
+ end
79
+ return inbox_emails
80
+ end
81
+
82
+ end
83
+ end
@@ -1,3 +1,3 @@
1
1
  module Getairmail
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.2.1"
3
3
  end
@@ -0,0 +1,3 @@
1
+ module Getairmail
2
+ VERSION = "0.0.2.1"
3
+ end
metadata CHANGED
@@ -1,11 +1,11 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: getairmail
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.2.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
8
- - vijay
8
+ - vijay chouhan
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
@@ -13,19 +13,24 @@ date: 2013-05-20 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: Read getairmail email
15
15
  email:
16
- - vchouhan@isystango.com
16
+ - vijaychouhan.exams@gmail.com
17
17
  executables: []
18
18
  extensions: []
19
19
  extra_rdoc_files: []
20
20
  files:
21
21
  - .gitignore
22
22
  - Gemfile
23
+ - Gemfile~
23
24
  - LICENSE
24
25
  - README.md
26
+ - README.md~
25
27
  - Rakefile
26
28
  - getairmail.gemspec
29
+ - getairmail.gemspec~
27
30
  - lib/getairmail.rb
31
+ - lib/getairmail.rb~
28
32
  - lib/getairmail/version.rb
33
+ - lib/getairmail/version.rb~
29
34
  homepage: ''
30
35
  licenses: []
31
36
  post_install_message:
@@ -49,5 +54,5 @@ rubyforge_project:
49
54
  rubygems_version: 1.8.21
50
55
  signing_key:
51
56
  specification_version: 3
52
- summary: Read getairmail email
57
+ summary: This gem read all emails from getairmail.com
53
58
  test_files: []