-
Notifications
You must be signed in to change notification settings - Fork 1
/
shituf.rb
80 lines (77 loc) · 1.72 KB
/
shituf.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# encoding: UTF-8
require 'rubygems'
gem 'ruby-gmail'
class Shituf
def initialize(username,password)
@username = username
@password = password
@registered =[]
end
attr_accessor :registered
Commands = {
"ADD ME" => ->(name){name.each do |n|; @registered << n if !@registered.include? n; end },
"REMOVE ME" => ->(name){ name.each do |n|; @registered.delete n;end },
"OTHER" => ->(n=0){puts "Do Nothing" }
}
def run_command(cmd,*param)
instance_exec(param, &Commands[cmd]) if Commands.key?(cmd)
end
def loadRegistered(path)
File.open(path).each_line{ |line|
@registered << line
}
rescue
end
def saveRegistered(path)
file = File.open(path,"w+")
@registered.each do |address|
file << address
end
file.close
end
def saveAttachments(attlist)
attlist.each do |a|
file = File.new(".\\attach\\" + a.filename, "w+")
file << a.decoded
file.close
end
end
def foreward(msg)
if msg.attachments
saveAttachments(msg.attachments)
#msg.save_attachments_to('./attach/')
end
forwarded = msg.clone
@registered.each do |addr|
#forwarded = Mail.new do
# to addr
# subject msg.subject
# html_part do
# content_type 'text/html; charset=UTF-8'
# body msg.html_part.decoded
# end
# msg.attachments.each do |att|
# add_file (".\\attach\\"+att.filename)
# end
#end
forwarded.to = addr
@gmail.deliver(forwarded)
end
end
def action(msg)
if Commands.key? msg.subject.upcase
run_command(msg.subject.upcase,msg.from.first)
else
foreward(msg)
end
end
def shareMail
@gmail = Gmail.new(@username,@password)
loadRegistered("list.txt")
(@gmail.inbox.emails(:unread)).each do |msg|
puts msg.subject
action(msg)
end
saveRegistered("list.txt")
end
end