gems-status 0.61.0 → 0.62.0

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.61.0
1
+ 0.62.0
@@ -24,25 +24,9 @@ module GemsStatus
24
24
  @email_to = conf["email_to"]
25
25
  @emails = {}
26
26
  @gem = nil
27
- download_emails
27
+ @emails = Utils.download_emails(@email_username, @email_password, @mailing_lists)
28
28
  end
29
29
 
30
- def download_emails
31
- #TODO: only download new emails and keep the old ones in a database
32
- #puts "Security email alerts from #{mailing_list} #{gmail.inbox.count(:unread, :to => mailing_list}"
33
- Gmail.new(@email_username, @email_password) do |gmail|
34
- @mailing_lists.each do |mailing_list|
35
- @emails[mailing_list] = []
36
- Utils::log_debug "Security email alerts from #{mailing_list} #{gmail.inbox.count( :to => mailing_list)}"
37
- #TODO: only read new emails
38
- #gmail.inbox.emails(:unread, :to => "rubyonrails-security@googlegroups.com").each do |email|
39
- gmail.inbox.emails(:to => mailing_list).each do |email|
40
- Utils::log_debug "Read #{email.subject}"
41
- @emails[mailing_list] << email
42
- end
43
- end
44
- end
45
- end
46
30
 
47
31
  def message(gem)
48
32
  return unless gem
@@ -2,15 +2,89 @@ require "openssl"
2
2
  OpenSSL::SSL::VERIFY_PEER = OpenSSL::SSL::VERIFY_NONE
3
3
 
4
4
  module GemsStatus
5
+ class Mail
6
+ attr_accessor :uid, :subject
7
+ end
8
+
5
9
 
6
10
  class Utils
7
11
  attr_accessor :errors
12
+ EMAIL_TMP_PATH = "tmp/utils/mail"
8
13
  @@errors = {}
9
14
  @@md5_sums = {}
10
15
  @@licenses = {}
11
16
  @@keys = {}
12
17
  @@gems = {}
13
18
  @@known_licenses = {}
19
+ @@emails = nil
20
+
21
+ def Utils.get_emails_from_fs
22
+ @@emails = {}
23
+ Dir.glob("#{EMAIL_TMP_PATH}/**/*").each do |filename|
24
+ next unless File.file?(filename)
25
+ open(filename, "r") do |file|
26
+ mail = GemsStatus::Mail.new
27
+ mailing_list = File.dirname(filename).split("/").pop
28
+ mail.uid = File.basename(filename)
29
+ mail.subject = file.read
30
+
31
+ if @@emails[mailing_list]
32
+ @@emails[mailing_list] << mail
33
+ else
34
+ @@emails[mailing_list] = [mail]
35
+ end
36
+ self.log_debug "email from filesystem #{filename}"
37
+ end
38
+ end
39
+ end
40
+
41
+ def Utils.save_email_to_fs(listname, mail)
42
+ dirname = "#{EMAIL_TMP_PATH}/#{listname}"
43
+ filename = "#{dirname}/#{mail.uid}"
44
+ if File.exists?(filename)
45
+ self.log_debug "email had already been downloaded #{mail.uid} - skipping"
46
+ return
47
+ end
48
+ Dir.mkdir(dirname) unless File.exists?(dirname)
49
+ open(filename, "w") do |f|
50
+ self.log_debug "writing email to fs #{mail.uid}"
51
+ f.write(mail.subject)
52
+ end
53
+ end
54
+
55
+ def Utils.download_emails(email_username, email_password, mailing_lists)
56
+ begin
57
+ self.get_emails_from_fs if @@emails.nil?
58
+ rescue Exception => e
59
+ self.log_error "", "There was a problem getting emails from filesystem #{e.message}"
60
+ end
61
+ if @@emails.nil?
62
+ self.log_error "", "There was a problem getting emails from filesystem"
63
+ @@emails = {}
64
+ end
65
+ self.log_debug "Emails read from filesystem #{@@emails.flatten(-1).length}"
66
+ Gmail.new(email_username, email_password) do |gmail|
67
+ mailing_lists.each do |mailing_list|
68
+ @@emails[mailing_list] = [] unless @@emails[mailing_list]
69
+ Utils::log_debug "New security email alerts from #{mailing_list} #{gmail.inbox.count( :unread, :to => mailing_list)}"
70
+ gmail.inbox.emails(:unread, :to => mailing_list).each do |email|
71
+ mail = GemsStatus::Mail.new
72
+ mail.uid = email.uid
73
+ mail.subject = email.subject
74
+ Utils::log_debug "Read #{mail.subject}"
75
+ @@emails[mailing_list] << mail
76
+ begin
77
+ self.save_email_to_fs(mailing_list, mail)
78
+ email.read!
79
+ rescue Exception => e
80
+ self.log_error "", "Error saving mail to filesystem #{e.message}"
81
+ email.unread!
82
+ end
83
+ end
84
+ end
85
+ end
86
+ return @@emails
87
+ end
14
88
 
15
89
  def Utils.known_licenses=(licenses)
16
90
  @@known_licenses = licenses
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gems-status
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.61.0
4
+ version: 0.62.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-05-31 00:00:00.000000000 Z
12
+ date: 2013-07-12 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: xml-simple
@@ -228,7 +228,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
228
228
  version: '0'
229
229
  segments:
230
230
  - 0
231
- hash: 75355838619519243
231
+ hash: 1285213534956026905
232
232
  required_rubygems_version: !ruby/object:Gem::Requirement
233
233
  none: false
234
234
  requirements:
@@ -237,7 +237,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
237
237
  version: '0'
238
238
  segments:
239
239
  - 0
240
- hash: 75355838619519243
240
+ hash: 1285213534956026905
241
241
  requirements: []
242
242
  rubyforge_project:
243
243
  rubygems_version: 1.8.25