search_mbox 0.0.2 → 0.0.3

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 49aadce29f3337443c9ff3ff40fe00fe3f19eec6
4
- data.tar.gz: 35549dbc3208ef6b31229b49ed2a30943c6a0d4c
3
+ metadata.gz: 6fc5479caa1c371d24ee9165efb0be3b14d2e366
4
+ data.tar.gz: 220acc7eccbb4ba8f27204c82c1d11f8f58db4b4
5
5
  SHA512:
6
- metadata.gz: 951bc3f1a59cfc795c36939fe3d779a751e938b6c6b6e6c17d59876e963f752fa2fcac34da24ed1a89d4b6a24861472b4cb757a44af9c75cc29d54d932560d8d
7
- data.tar.gz: 4ac0b8db43c4d7eac407dc136db405d4801acce93cd0d5be500e8e5265fd1c644f88bfeff5503c8d59d2e00d34cc9828faffc970c6cf5ee87beee7564958bd33
6
+ metadata.gz: 383c870c1db677e26d45a7b2ec700d2d6980a787689fd3eed4853d68166826033a03ddb8fccae80212ac7d3f0700c759c8f69130ac7fdd5027d0e35abdf2e169
7
+ data.tar.gz: bfe9dca0cd376c1d24694dfa8fa61402e0791a8115a095c2dfe6212fe97666e6cf05c7b544129f0bb9bee436e12d4a5186d07351ee2dfec62fbb13f11f0b5968
@@ -0,0 +1,13 @@
1
+ $:.unshift('.')
2
+ require 'search_mbox'
3
+ include SearchMbox
4
+
5
+ SearchMbox.login('example.com', 'togashik@hoge@example.com', 'hogehoge')
6
+ mails = SearchMbox.search
7
+ mails.each do |m|
8
+ puts m[:msg_id]
9
+ puts m[:date]
10
+ puts m[:from]
11
+ puts m[:subject]
12
+ puts m[:body]
13
+ end
@@ -3,11 +3,13 @@ require "net/imap"
3
3
  require "kconv"
4
4
 
5
5
  module SearchMbox
6
- def self.login(host, account, passwd)
6
+ def self.login(host, account, passwd, port = 143, imap_usessl = false)
7
+ @date_attr_name = 'INTERNALDATE'
8
+ @envelope_attr_name = 'ENVELOPE'
7
9
  @subject_attr_name = 'BODY[HEADER.FIELDS (SUBJECT)]'
8
10
  @body_attr_name = 'BODY[TEXT]'
9
- @imap_port = 143
10
- @imap_usessl = false
11
+ @imap_port = port
12
+ @imap_usessl = imap_usessl
11
13
  begin
12
14
  @imap = Net::IMAP.new(host, @imap_port, @imap_usessl)
13
15
  @imap.login(account, passwd)
@@ -23,10 +25,20 @@ module SearchMbox
23
25
  @imap.examine('INBOX')
24
26
  @imap.search(rule).each do |msg_id|
25
27
  @mail = Hash.new
26
- msg = @imap.fetch(msg_id, [@subject_attr_name, @body_attr_name]).first
28
+ msg = @imap.fetch(msg_id,
29
+ [
30
+ @date_attr_name,
31
+ @envelope_attr_name,
32
+ @subject_attr_name,
33
+ @body_attr_name
34
+ ]).first
35
+ date = msg.attr[@date_attr_name]
36
+ envelope = msg.attr[@envelope_attr_name].from[0]
27
37
  subject = msg.attr[@subject_attr_name].toutf8.strip
28
38
  body = msg.attr[@body_attr_name].toutf8.strip
29
39
  @mail[:msg_id] = msg_id
40
+ @mail[:date] = date
41
+ @mail[:from] = envelope[:mailbox] + '@' + envelope[:host]
30
42
  @mail[:subject] = subject
31
43
  @mail[:body] = body
32
44
  @mails.push(@mail)
@@ -1,3 +1,3 @@
1
1
  module SearchMbox
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: search_mbox
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - kenta.togashi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-06-02 00:00:00.000000000 Z
11
+ date: 2014-06-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -78,6 +78,7 @@ files:
78
78
  - LICENSE.txt
79
79
  - README.md
80
80
  - Rakefile
81
+ - example/test.rb
81
82
  - lib/search_mbox.rb
82
83
  - lib/search_mbox/version.rb
83
84
  - search_mbox.gemspec