getairmail 0.0.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.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +29 -0
- data/Rakefile +2 -0
- data/getairmail.gemspec +17 -0
- data/lib/getairmail.rb +83 -0
- data/lib/getairmail/version.rb +3 -0
- metadata +53 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
Copyright (c) 2013 vijay
|
|
2
|
+
|
|
3
|
+
MIT License
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
6
|
+
a copy of this software and associated documentation files (the
|
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
11
|
+
the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be
|
|
14
|
+
included in all copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# Getairmail
|
|
2
|
+
|
|
3
|
+
TODO: Write a gem description
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
Add this line to your application's Gemfile:
|
|
8
|
+
|
|
9
|
+
gem 'getairmail'
|
|
10
|
+
|
|
11
|
+
And then execute:
|
|
12
|
+
|
|
13
|
+
$ bundle
|
|
14
|
+
|
|
15
|
+
Or install it yourself as:
|
|
16
|
+
|
|
17
|
+
$ gem install getairmail
|
|
18
|
+
|
|
19
|
+
## Usage
|
|
20
|
+
|
|
21
|
+
TODO: Write usage instructions here
|
|
22
|
+
|
|
23
|
+
## Contributing
|
|
24
|
+
|
|
25
|
+
1. Fork it
|
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
|
27
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
|
29
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
data/getairmail.gemspec
ADDED
|
@@ -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"]
|
|
6
|
+
gem.email = ["vchouhan@isystango.com"]
|
|
7
|
+
gem.description = "Read getairmail email"
|
|
8
|
+
gem.summary = "Read getairmail email"
|
|
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
|
data/lib/getairmail.rb
ADDED
|
@@ -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
|
metadata
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: getairmail
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.0.1
|
|
5
|
+
prerelease:
|
|
6
|
+
platform: ruby
|
|
7
|
+
authors:
|
|
8
|
+
- vijay
|
|
9
|
+
autorequire:
|
|
10
|
+
bindir: bin
|
|
11
|
+
cert_chain: []
|
|
12
|
+
date: 2013-05-17 00:00:00.000000000 Z
|
|
13
|
+
dependencies: []
|
|
14
|
+
description: Read getairmail email
|
|
15
|
+
email:
|
|
16
|
+
- vchouhan@isystango.com
|
|
17
|
+
executables: []
|
|
18
|
+
extensions: []
|
|
19
|
+
extra_rdoc_files: []
|
|
20
|
+
files:
|
|
21
|
+
- .gitignore
|
|
22
|
+
- Gemfile
|
|
23
|
+
- LICENSE
|
|
24
|
+
- README.md
|
|
25
|
+
- Rakefile
|
|
26
|
+
- getairmail.gemspec
|
|
27
|
+
- lib/getairmail.rb
|
|
28
|
+
- lib/getairmail/version.rb
|
|
29
|
+
homepage: ''
|
|
30
|
+
licenses: []
|
|
31
|
+
post_install_message:
|
|
32
|
+
rdoc_options: []
|
|
33
|
+
require_paths:
|
|
34
|
+
- lib
|
|
35
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
36
|
+
none: false
|
|
37
|
+
requirements:
|
|
38
|
+
- - ! '>='
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: '0'
|
|
41
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
42
|
+
none: false
|
|
43
|
+
requirements:
|
|
44
|
+
- - ! '>='
|
|
45
|
+
- !ruby/object:Gem::Version
|
|
46
|
+
version: '0'
|
|
47
|
+
requirements: []
|
|
48
|
+
rubyforge_project:
|
|
49
|
+
rubygems_version: 1.8.21
|
|
50
|
+
signing_key:
|
|
51
|
+
specification_version: 3
|
|
52
|
+
summary: Read getairmail email
|
|
53
|
+
test_files: []
|