-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmail.rb
45 lines (35 loc) · 1020 Bytes
/
mail.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# -*- coding: utf-8 -*-
%w(yaml base64 kconv).each do |lib|
require lib
end
require 'bundler'
Bundler.require
config = YAML.load_file("config.yml")
username = config["username"]
password = config["password"]
#----
filter = { to: "[email protected]", from: "-amazon"}
@reg = /^■\s*予定.*/m
module Gmail
class Message
def read
unless multipart?
body.to_s.toutf8
else
text_part.decoded
end
end
def subject
super.toutf8
end
end
end
# uidでuniqに識別可能?
# uidをファイル保存して、
gmail = Gmail.new(username, password)
@gmail = gmail
# slp_mails = gmail.inbox.emails(filter).lazy.select{ |m| m.subject.toutf8.include? "活動" }.select { |m| m.read.include? "予定" }
slp_mails = gmail.inbox.emails(filter).lazy.select{ |m| m.subject.include? "活動" }.select { |m| m.read.include? "予定" }
p slp_mails_size: slp_mails.size
@slp_mails = slp_mails
@plans = @slp_mails.take(5).to_a.map { |e| e.read.scan(@reg) }