keystone 0.0.29
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 +3 -0
- data/README +3 -0
- data/Rakefile +26 -0
- data/VERSION +1 -0
- data/doc/classes/Dir.html +139 -0
- data/doc/classes/Dir.src/M000003.html +25 -0
- data/doc/classes/FlagSetMaker.html +138 -0
- data/doc/classes/FlagSetMaker.src/M000018.html +18 -0
- data/doc/classes/FlagSetMaker/FlagSet.html +186 -0
- data/doc/classes/FlagSetMaker/FlagSet.src/M000019.html +24 -0
- data/doc/classes/FlagSetMaker/FlagSet.src/M000020.html +26 -0
- data/doc/classes/FlagSetMaker/FlagSet.src/M000021.html +18 -0
- data/doc/classes/FlagSetMaker/FlagSet.src/M000022.html +18 -0
- data/doc/classes/FlagSetMaker/Flags.html +304 -0
- data/doc/classes/FlagSetMaker/Flags.src/M000023.html +19 -0
- data/doc/classes/FlagSetMaker/Flags.src/M000024.html +18 -0
- data/doc/classes/FlagSetMaker/Flags.src/M000025.html +18 -0
- data/doc/classes/FlagSetMaker/Flags.src/M000026.html +18 -0
- data/doc/classes/FlagSetMaker/Flags.src/M000027.html +18 -0
- data/doc/classes/FlagSetMaker/Flags.src/M000029.html +18 -0
- data/doc/classes/FlagSetMaker/Flags.src/M000030.html +18 -0
- data/doc/classes/FlagSetMaker/Flags.src/M000031.html +18 -0
- data/doc/classes/FlagSetMaker/Flags.src/M000032.html +18 -0
- data/doc/classes/FlagSetMaker/Flags.src/M000033.html +18 -0
- data/doc/classes/Hoge.html +113 -0
- data/doc/classes/Keystone.html +174 -0
- data/doc/classes/Keystone/Base.html +191 -0
- data/doc/classes/Keystone/Base.src/M000054.html +22 -0
- data/doc/classes/Keystone/Base.src/M000055.html +18 -0
- data/doc/classes/Keystone/Base.src/M000056.html +25 -0
- data/doc/classes/Keystone/Base.src/M000057.html +18 -0
- data/doc/classes/Keystone/Base.src/M000058.html +20 -0
- data/doc/classes/Keystone/Batch.html +115 -0
- data/doc/classes/Keystone/Batch/Base.html +208 -0
- data/doc/classes/Keystone/Batch/Base.src/M000052.html +54 -0
- data/doc/classes/Keystone/Batch/Base.src/M000053.html +30 -0
- data/doc/classes/Keystone/CoreExt.html +105 -0
- data/doc/classes/Keystone/Mail.html +115 -0
- data/doc/classes/Keystone/Mail/Send.html +171 -0
- data/doc/classes/Keystone/Mail/Send.src/M000034.html +18 -0
- data/doc/classes/Keystone/Mail/Send.src/M000035.html +42 -0
- data/doc/classes/Keystone/Mail/Send.src/M000036.html +18 -0
- data/doc/classes/Keystone/Os.html +184 -0
- data/doc/classes/Keystone/Os.src/M000037.html +18 -0
- data/doc/classes/Keystone/Os.src/M000038.html +27 -0
- data/doc/classes/Keystone/Os/AbstractOs.html +227 -0
- data/doc/classes/Keystone/Os/AbstractOs.src/M000046.html +17 -0
- data/doc/classes/Keystone/Os/AbstractOs.src/M000047.html +17 -0
- data/doc/classes/Keystone/Os/AbstractOs.src/M000048.html +17 -0
- data/doc/classes/Keystone/Os/AbstractOs.src/M000049.html +17 -0
- data/doc/classes/Keystone/Os/AbstractOs.src/M000050.html +17 -0
- data/doc/classes/Keystone/Os/AbstractOs.src/M000051.html +25 -0
- data/doc/classes/Keystone/Os/Centos.html +113 -0
- data/doc/classes/Keystone/Os/Darwin.html +139 -0
- data/doc/classes/Keystone/Os/Darwin.src/M000039.html +18 -0
- data/doc/classes/Keystone/Os/Linux.html +139 -0
- data/doc/classes/Keystone/Os/Linux.src/M000045.html +26 -0
- data/doc/classes/Keystone/Os/Osx.html +113 -0
- data/doc/classes/Keystone/Os/Unix.html +199 -0
- data/doc/classes/Keystone/Os/Unix.src/M000040.html +27 -0
- data/doc/classes/Keystone/Os/Unix.src/M000041.html +18 -0
- data/doc/classes/Keystone/Os/Unix.src/M000042.html +18 -0
- data/doc/classes/Keystone/Os/Unix.src/M000043.html +18 -0
- data/doc/classes/Keystone/Os/Unix.src/M000044.html +18 -0
- data/doc/classes/Keystone/Rails.html +105 -0
- data/doc/classes/Keystone/StringUtil.html +226 -0
- data/doc/classes/Keystone/StringUtil.src/M000059.html +43 -0
- data/doc/classes/Keystone/StringUtil.src/M000060.html +25 -0
- data/doc/classes/Keystone/StringUtil.src/M000061.html +24 -0
- data/doc/classes/Keystone/StringUtil.src/M000062.html +18 -0
- data/doc/classes/Keystone/StringUtil.src/M000063.html +21 -0
- data/doc/classes/Object.html +240 -0
- data/doc/classes/Object.src/M000012.html +18 -0
- data/doc/classes/Object.src/M000013.html +20 -0
- data/doc/classes/Object.src/M000014.html +18 -0
- data/doc/classes/Object.src/M000015.html +18 -0
- data/doc/classes/Object.src/M000016.html +18 -0
- data/doc/classes/Object.src/M000017.html +19 -0
- data/doc/classes/Tempfile.html +139 -0
- data/doc/classes/Tempfile.src/M000011.html +25 -0
- data/doc/classes/TestCoreExt.html +152 -0
- data/doc/classes/TestCoreExt.src/M000009.html +17 -0
- data/doc/classes/TestCoreExt.src/M000010.html +21 -0
- data/doc/classes/TestStringUtilBase.html +197 -0
- data/doc/classes/TestStringUtilBase.src/M000004.html +17 -0
- data/doc/classes/TestStringUtilBase.src/M000005.html +23 -0
- data/doc/classes/TestStringUtilBase.src/M000006.html +22 -0
- data/doc/classes/TestStringUtilBase.src/M000007.html +25 -0
- data/doc/classes/TestStringUtilBase.src/M000008.html +34 -0
- data/doc/classes/Uri.html +158 -0
- data/doc/classes/Uri.src/M000001.html +18 -0
- data/doc/classes/Uri.src/M000002.html +18 -0
- data/doc/created.rid +1 -0
- data/doc/files/example/batch_sample_rb.html +134 -0
- data/doc/files/example/os_rb.html +109 -0
- data/doc/files/example/string_util_rb.html +109 -0
- data/doc/files/lib/keystone/base_rb.html +101 -0
- data/doc/files/lib/keystone/batch/base_rb.html +108 -0
- data/doc/files/lib/keystone/batch_rb.html +101 -0
- data/doc/files/lib/keystone/core_ext/array_rb.html +101 -0
- data/doc/files/lib/keystone/core_ext/blank_rb.html +101 -0
- data/doc/files/lib/keystone/core_ext/dir_rb.html +101 -0
- data/doc/files/lib/keystone/core_ext/object_rb.html +101 -0
- data/doc/files/lib/keystone/core_ext/tempfile_rb.html +108 -0
- data/doc/files/lib/keystone/core_ext/uri_rb.html +101 -0
- data/doc/files/lib/keystone/core_ext_rb.html +113 -0
- data/doc/files/lib/keystone/mail/send_rb.html +115 -0
- data/doc/files/lib/keystone/mail_rb.html +101 -0
- data/doc/files/lib/keystone/os/abstract_os_rb.html +101 -0
- data/doc/files/lib/keystone/os/centos_rb.html +101 -0
- data/doc/files/lib/keystone/os/darwin_rb.html +101 -0
- data/doc/files/lib/keystone/os/linux_rb.html +101 -0
- data/doc/files/lib/keystone/os/osx_rb.html +101 -0
- data/doc/files/lib/keystone/os/unix_rb.html +101 -0
- data/doc/files/lib/keystone/os_rb.html +108 -0
- data/doc/files/lib/keystone/string_util_rb.html +101 -0
- data/doc/files/lib/keystone_rb.html +116 -0
- data/doc/files/test/test_core_ext_rb.html +110 -0
- data/doc/files/test/test_string_util_rb.html +112 -0
- data/doc/files/vendor/flag_set_maker_rb.html +108 -0
- data/doc/files/vendor/moji_rb.html +118 -0
- data/doc/fr_class_index.html +52 -0
- data/doc/fr_file_index.html +54 -0
- data/doc/fr_method_index.html +89 -0
- data/doc/index.html +24 -0
- data/doc/rdoc-style.css +208 -0
- data/example/batch_sample.rb +24 -0
- data/example/os.rb +4 -0
- data/example/sendmail.rb +21 -0
- data/example/string_util.rb +15 -0
- data/keystone.gemspec +209 -0
- data/lib/keystone.rb +25 -0
- data/lib/keystone/base.rb +75 -0
- data/lib/keystone/batch.rb +5 -0
- data/lib/keystone/batch/base.rb +217 -0
- data/lib/keystone/core_ext.rb +18 -0
- data/lib/keystone/core_ext/array.rb +29 -0
- data/lib/keystone/core_ext/blank.rb +44 -0
- data/lib/keystone/core_ext/dir.rb +16 -0
- data/lib/keystone/core_ext/ipaddr.rb +18 -0
- data/lib/keystone/core_ext/object.rb +34 -0
- data/lib/keystone/core_ext/tempfile.rb +14 -0
- data/lib/keystone/core_ext/uri.rb +14 -0
- data/lib/keystone/mail.rb +8 -0
- data/lib/keystone/mail/address.rb +92 -0
- data/lib/keystone/mail/content_type.rb +60 -0
- data/lib/keystone/mail/message.rb +102 -0
- data/lib/keystone/mail/message_factory.rb +18 -0
- data/lib/keystone/mail/message_iso2022jp.rb +126 -0
- data/lib/keystone/mail/message_sjis.rb +23 -0
- data/lib/keystone/mail/receive.rb +320 -0
- data/lib/keystone/mail/send.rb +83 -0
- data/lib/keystone/os.rb +26 -0
- data/lib/keystone/os/abstract_os.rb +36 -0
- data/lib/keystone/os/centos.rb +6 -0
- data/lib/keystone/os/darwin.rb +9 -0
- data/lib/keystone/os/linux.rb +15 -0
- data/lib/keystone/os/osx.rb +18 -0
- data/lib/keystone/os/unix.rb +43 -0
- data/lib/keystone/string_util.rb +85 -0
- data/test/test_core_ext.rb +15 -0
- data/test/test_string_util.rb +60 -0
- data/util/README +1 -0
- data/util/bin/command_broadcast.rb +137 -0
- data/util/bin/disk_size_check.rb +54 -0
- data/util/bin/notice +93 -0
- data/util/bin/ve2tar.rb +80 -0
- data/vendor/flag_set_maker.rb +121 -0
- data/vendor/moji.rb +502 -0
- metadata +236 -0
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
module Keystone
|
|
2
|
+
module Mail
|
|
3
|
+
class MessageFactory
|
|
4
|
+
def self.create(opt)
|
|
5
|
+
message = MessageIso2022jp.new(opt)
|
|
6
|
+
if opt.key?(:encoding)
|
|
7
|
+
case opt[:encoding]
|
|
8
|
+
when :sjis
|
|
9
|
+
message = MessageSjis.new(opt)
|
|
10
|
+
else
|
|
11
|
+
raise "encoding '#{opt[:encoding]}' is not supported"
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
return message
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
require 'kconv'
|
|
2
|
+
|
|
3
|
+
module Keystone
|
|
4
|
+
module Mail
|
|
5
|
+
#
|
|
6
|
+
# encoding 未実装
|
|
7
|
+
#
|
|
8
|
+
#
|
|
9
|
+
class MessageIso2022jp < Keystone::Mail::Message
|
|
10
|
+
def encode_mime(st)
|
|
11
|
+
Kconv.tojis(st)
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def mime_header_string
|
|
15
|
+
"=?ISO-2022-JP?B?"
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def encode_body
|
|
19
|
+
Kconv.tojis(@body)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
# #
|
|
23
|
+
# # 普通なことをしたいならTMailを使いましょう
|
|
24
|
+
# # class Send
|
|
25
|
+
# def initialize(opt={})
|
|
26
|
+
# @smtp_addr, @smtp_port = "127.0.0.1", 25
|
|
27
|
+
# @subject, @mail_from_text = "" ,nil
|
|
28
|
+
# @retry_cnt, @encoding = 0, :iso2022jp
|
|
29
|
+
# set_option(opt)
|
|
30
|
+
# end
|
|
31
|
+
#
|
|
32
|
+
# #
|
|
33
|
+
# # from could be String or Array
|
|
34
|
+
# # opt
|
|
35
|
+
# # :smtp_addr
|
|
36
|
+
# # :smtp_port
|
|
37
|
+
# # :retry
|
|
38
|
+
# # :mail_from_text
|
|
39
|
+
# # :encoding
|
|
40
|
+
# #
|
|
41
|
+
# def self.send(from, to, subject, body, opt={})
|
|
42
|
+
# queue = self.new(opt)
|
|
43
|
+
# queue.mail_to = to
|
|
44
|
+
# queue.mail_from = from
|
|
45
|
+
# queue.subject = subject
|
|
46
|
+
# queue.body = body
|
|
47
|
+
# queue.send
|
|
48
|
+
# end
|
|
49
|
+
#
|
|
50
|
+
# def send
|
|
51
|
+
# raise "mail_to must not be blank!" if @mail_to.blank?
|
|
52
|
+
# raise "mail_from must not be blank!" if @mail_from.blank?
|
|
53
|
+
# header = ""
|
|
54
|
+
# header += create_mailfrom_header(@mail_from,@mail_from_text)
|
|
55
|
+
# header += create_mailto_header(@mail_to)
|
|
56
|
+
# header += create_subject_header(@subject)
|
|
57
|
+
#
|
|
58
|
+
# case @encoding
|
|
59
|
+
# when :iso2022jp
|
|
60
|
+
# body_encoded = Kconv.tojis(@body)
|
|
61
|
+
# else
|
|
62
|
+
# raise "encoding #{encoding.to_s} can not use"
|
|
63
|
+
# end
|
|
64
|
+
#
|
|
65
|
+
# src = header + "\n" + body_encoded
|
|
66
|
+
# debug src
|
|
67
|
+
# try_cnt = 0
|
|
68
|
+
# begin
|
|
69
|
+
# m = Net::SMTPSession.new(smtp_addr, smtp_port)
|
|
70
|
+
# m.start()
|
|
71
|
+
# m.sendmail(src ,@mail_from ,@mail_to)
|
|
72
|
+
# m.finish
|
|
73
|
+
# rescue => e
|
|
74
|
+
# debug "try_cnt:#{try_cnt}"
|
|
75
|
+
# try_cnt += 1
|
|
76
|
+
# sleep 1
|
|
77
|
+
# retry if @retry_cnt >= try_cnt
|
|
78
|
+
# raise e
|
|
79
|
+
# end
|
|
80
|
+
# end
|
|
81
|
+
#
|
|
82
|
+
# def set_option(opt)
|
|
83
|
+
# @smtp_addr = opt[:smtp_addr] if opt.key?(:smtp_addr)
|
|
84
|
+
# @smtp_port = opt[:smtp_port] if opt.key?(:smtp_port)
|
|
85
|
+
# @retry_cnt = Integer(opt[:retry_cnt]) if opt.key?(:retry_cnt)
|
|
86
|
+
# @mail_from_text = opt[:mail_from_text] if opt.key?(:mail_from_text)
|
|
87
|
+
# @encoding = opt[:encoding] if opt.key?(:encoding)
|
|
88
|
+
# end
|
|
89
|
+
#
|
|
90
|
+
# private
|
|
91
|
+
#
|
|
92
|
+
# def to_mail_header(header_name, plain_text)
|
|
93
|
+
# ret = ""
|
|
94
|
+
# str = plain_text.clone
|
|
95
|
+
# str.gsub!(/(\r|\n)/,"")
|
|
96
|
+
# str.split(//).split_by(10).each do |ar|
|
|
97
|
+
# st = ar.join('')
|
|
98
|
+
# st = Kconv.tojis(st)
|
|
99
|
+
# st = st.split(//,1).pack('m'); st = st.chomp
|
|
100
|
+
# ret += " =?ISO-2022-JP?B?#{st}?=\n"
|
|
101
|
+
# end
|
|
102
|
+
# return "#{header_name}:"+ret
|
|
103
|
+
# end
|
|
104
|
+
#
|
|
105
|
+
# def create_mailfrom_header(from, from_text)
|
|
106
|
+
# if from_text.blank?
|
|
107
|
+
# return "From: #{from}\n"
|
|
108
|
+
# else
|
|
109
|
+
# return to_mail_header("From", from_text).chomp + "<#{from}>\n"
|
|
110
|
+
# end
|
|
111
|
+
# end
|
|
112
|
+
#
|
|
113
|
+
# def create_subject_header(subject)
|
|
114
|
+
# to_mail_header("Subject",subject)
|
|
115
|
+
# end
|
|
116
|
+
#
|
|
117
|
+
# def create_mailto_header(to)
|
|
118
|
+
# if to.class.to_s == 'Array'
|
|
119
|
+
# return "To: #{to.join(',')}\n"
|
|
120
|
+
# else
|
|
121
|
+
# return "To: #{to.to_s}\n"
|
|
122
|
+
# end
|
|
123
|
+
# end
|
|
124
|
+
end
|
|
125
|
+
end
|
|
126
|
+
end
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
require 'kconv'
|
|
2
|
+
|
|
3
|
+
module Keystone
|
|
4
|
+
module Mail
|
|
5
|
+
#
|
|
6
|
+
# encoding 未実装
|
|
7
|
+
#
|
|
8
|
+
#
|
|
9
|
+
class MessageSjis < Keystone::Mail::Message
|
|
10
|
+
def encode_mime(st)
|
|
11
|
+
Kconv.tosjis(st)
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def mime_header_string
|
|
15
|
+
"=?ShiftJIS?B?"
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def encode_body
|
|
19
|
+
Kconv.tosjis(@body)
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
@@ -0,0 +1,320 @@
|
|
|
1
|
+
require 'net/smtp'
|
|
2
|
+
require 'kconv'
|
|
3
|
+
require 'tempfile'
|
|
4
|
+
if __FILE__ ==$0
|
|
5
|
+
$: << '../..'
|
|
6
|
+
require 'keystone'
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
module Keystone
|
|
10
|
+
module Mail
|
|
11
|
+
# kopipe shimasita
|
|
12
|
+
|
|
13
|
+
class KmContentType
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
class KmMessage
|
|
20
|
+
|
|
21
|
+
include KmClassBase
|
|
22
|
+
|
|
23
|
+
attr_accessor :header,:charset,:file_path,:file_name,
|
|
24
|
+
attr_accessor :content_type,:body,:depth
|
|
25
|
+
attr_accessor :file_handle,:file_stream,:is_header,
|
|
26
|
+
attr_accessor :content_transfer_encoding,:messages,:is_finish_parsing
|
|
27
|
+
|
|
28
|
+
def initialize(depth)
|
|
29
|
+
@depth = depth
|
|
30
|
+
@is_parsing_header = true
|
|
31
|
+
@header = {}
|
|
32
|
+
@body = ""
|
|
33
|
+
@content_transfer_encoding = nil
|
|
34
|
+
@messages = []
|
|
35
|
+
@is_finish_parsing = false
|
|
36
|
+
@last_header = nil
|
|
37
|
+
$is_save_file = true
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def set_parse_finish_messages
|
|
41
|
+
@messages.each{|m|
|
|
42
|
+
m.is_finish_parsing = true
|
|
43
|
+
begin
|
|
44
|
+
# TODO motitto iikannji
|
|
45
|
+
m.file_stream.close
|
|
46
|
+
rescue
|
|
47
|
+
end
|
|
48
|
+
}
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def parse(line)
|
|
52
|
+
if @is_finish_parsing
|
|
53
|
+
return false
|
|
54
|
+
end
|
|
55
|
+
line.chomp!
|
|
56
|
+
|
|
57
|
+
if @is_parsing_header == true && line.strip == ""
|
|
58
|
+
# header end
|
|
59
|
+
@is_parsing_header = false
|
|
60
|
+
reshape_header
|
|
61
|
+
set_special_attrs
|
|
62
|
+
|
|
63
|
+
@content_type = KmContentType.new(@header["content-type"])
|
|
64
|
+
return true
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
if @is_parsing_header
|
|
68
|
+
parse_and_set_header(line)
|
|
69
|
+
return true
|
|
70
|
+
else
|
|
71
|
+
if @content_type.boundary != nil
|
|
72
|
+
if line == "--#{@content_type.boundary}"
|
|
73
|
+
set_parse_finish_messages
|
|
74
|
+
@messages.push(KmMessage.new(@depth + 1))
|
|
75
|
+
debug "new multipart start"
|
|
76
|
+
return true
|
|
77
|
+
end
|
|
78
|
+
if line == "--#{@content_type.boundary}--"
|
|
79
|
+
set_parse_finish_messages
|
|
80
|
+
@is_finish_parsing = true
|
|
81
|
+
debug "multipart end"
|
|
82
|
+
if @file_handle != nil
|
|
83
|
+
begin
|
|
84
|
+
@file_stream.close
|
|
85
|
+
rescue => e
|
|
86
|
+
error e
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
return true
|
|
90
|
+
end
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
@messages.each{|message|
|
|
94
|
+
if message.parse(line)
|
|
95
|
+
return true
|
|
96
|
+
end
|
|
97
|
+
}
|
|
98
|
+
return parse_and_set_body(line)
|
|
99
|
+
end
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
def set_special_attrs
|
|
103
|
+
# do not create file for top node KmMessage
|
|
104
|
+
debug "depth=#{@depth}"
|
|
105
|
+
if @depth != 1
|
|
106
|
+
if @content_type.content_type != :multipart_mixed && @content_type.content_type != :multipart_related && @content_type.content_type != :multipart_alternative
|
|
107
|
+
if $is_save_file
|
|
108
|
+
debug "!!!!!!!! create file handle [content_type=#{@content_type.content_type}]"
|
|
109
|
+
$save_folder ||= "/tmp"
|
|
110
|
+
tmp_file = Tempfile.new("KmReceiveMail",$save_folder)
|
|
111
|
+
@file_path = tmp_file.path
|
|
112
|
+
@file_handle =tmp_file
|
|
113
|
+
@file_stream =tmp_file.open
|
|
114
|
+
debug "@file_path=#{@file_path}"
|
|
115
|
+
end
|
|
116
|
+
end
|
|
117
|
+
end
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
def reshape_header
|
|
121
|
+
|
|
122
|
+
header["to"] = KmMailAddress::get_addresses(header["to"]) if header["to"] != nil
|
|
123
|
+
header["cc"] = KmMailAddress::get_addresses(header["cc"]) if header["cc"] != nil
|
|
124
|
+
header["return-path"] = KmMailAddress::get_addresses(header["return-path"])[0] if header["return-path"] != nil
|
|
125
|
+
header["delivered-to"] = KmMailAddress::get_addresses(header["delivered-to"]) if header["delivered-to"] != nil
|
|
126
|
+
header["from"] = KmMailAddress::get_addresses(header["from"])[0] if header["from"] != nil
|
|
127
|
+
|
|
128
|
+
if @header["content-type"] != nil
|
|
129
|
+
debug "reshape_header set content-type"
|
|
130
|
+
@content_type = KmContentType.new(@header["content-type"])
|
|
131
|
+
debug "@content_type=#{@content_type.inspect}"
|
|
132
|
+
debug "get file"
|
|
133
|
+
else
|
|
134
|
+
warn "content-type not fond"
|
|
135
|
+
warn @header.inspect
|
|
136
|
+
end
|
|
137
|
+
if @header["content-transfer-encoding"] != nil
|
|
138
|
+
if /base64/i =~ @header["content-transfer-encoding"]
|
|
139
|
+
@content_transfer_encoding = :base64
|
|
140
|
+
elsif /7bit/i =~ @header["content-transfer-encoding"]
|
|
141
|
+
@content_transfer_encoding = :_7bit
|
|
142
|
+
elsif /8bit/i =~ @header["content-transfer-encoding"]
|
|
143
|
+
@content_transfer_encoding = :_8bit
|
|
144
|
+
elsif /binary/i =~ @header["content-transfer-encoding"]
|
|
145
|
+
@content_transfer_encoding = :binary
|
|
146
|
+
elsif /quoted\-printable/i =~ @header["content-transfer-encoding"]
|
|
147
|
+
@content_transfer_encoding = :quoted_printable
|
|
148
|
+
else
|
|
149
|
+
error "transfer encoding not supported [#{@header["content-transfer-encoding"]}]"
|
|
150
|
+
end
|
|
151
|
+
end
|
|
152
|
+
end
|
|
153
|
+
|
|
154
|
+
def convert(data)
|
|
155
|
+
return Kconv.toutf8(data)
|
|
156
|
+
end
|
|
157
|
+
|
|
158
|
+
def set_header(key,val)
|
|
159
|
+
debug "key[#{key}],val[#{val}]"
|
|
160
|
+
|
|
161
|
+
key = key.downcase
|
|
162
|
+
@header[key] ||= ""
|
|
163
|
+
if key == "subject"
|
|
164
|
+
@header[key] += convert(val)
|
|
165
|
+
elsif key == "received"
|
|
166
|
+
@header[key] = [] if @header[key] == ""
|
|
167
|
+
@header[key].push val
|
|
168
|
+
else
|
|
169
|
+
@header[key] += val
|
|
170
|
+
end
|
|
171
|
+
end
|
|
172
|
+
|
|
173
|
+
def parse_and_set_header(line)
|
|
174
|
+
if /^\s/ =~ line
|
|
175
|
+
debug "multi header:#{@last_header}"
|
|
176
|
+
set_header(@last_header,line.strip)
|
|
177
|
+
else
|
|
178
|
+
|
|
179
|
+
# harada 変更 2008/07/02
|
|
180
|
+
#if /^(.*?):(.*)/ =~ line
|
|
181
|
+
if /^(.*?):\s?(.*)/ =~ line
|
|
182
|
+
@last_header = $1
|
|
183
|
+
set_header($1,$2)
|
|
184
|
+
else
|
|
185
|
+
error "error parse header!! [#{line}]"
|
|
186
|
+
end
|
|
187
|
+
end
|
|
188
|
+
end
|
|
189
|
+
|
|
190
|
+
def parse_and_set_body(line)
|
|
191
|
+
|
|
192
|
+
if @content_type.content_type == :text_plain || @content_type.content_type == :text_html
|
|
193
|
+
cline = ""
|
|
194
|
+
if @content_type.charset == :iso_2022_jp
|
|
195
|
+
cline = convert(line)
|
|
196
|
+
else
|
|
197
|
+
cline = line
|
|
198
|
+
end
|
|
199
|
+
|
|
200
|
+
cline = "\n"+cline if @body != ""
|
|
201
|
+
# cline += "\n"
|
|
202
|
+
@body += cline
|
|
203
|
+
@file_stream.write(cline) if @file_handle != nil
|
|
204
|
+
elsif @content_transfer_encoding == :base64
|
|
205
|
+
debug "content_type=#{@content_type.content_type.to_s}"
|
|
206
|
+
debug "boundary=#{@content_type.boundary}"
|
|
207
|
+
debug "size=#{@file_handle.size}"
|
|
208
|
+
debug "file_path=#{@file_path}"
|
|
209
|
+
debug "!!!!!!!!!writing[#{line}]"
|
|
210
|
+
@file_stream.write(Base64::decode64(line)) if @file_handle != nil
|
|
211
|
+
end
|
|
212
|
+
return true
|
|
213
|
+
end
|
|
214
|
+
end
|
|
215
|
+
|
|
216
|
+
class Receive
|
|
217
|
+
|
|
218
|
+
# @subject & @body is short cut to @message.###
|
|
219
|
+
attr_reader :original
|
|
220
|
+
|
|
221
|
+
def subject
|
|
222
|
+
return @message.header["subject"]
|
|
223
|
+
end
|
|
224
|
+
|
|
225
|
+
def body_text_all
|
|
226
|
+
@body_all = ""
|
|
227
|
+
get_bodies(@message)
|
|
228
|
+
return @body_all
|
|
229
|
+
end
|
|
230
|
+
|
|
231
|
+
def body_text_html
|
|
232
|
+
# TODO 以下のプレーンテキストを集めたやつを帰す
|
|
233
|
+
@body_all = ""
|
|
234
|
+
get_bodies(@message,:text_html)
|
|
235
|
+
return @body_all
|
|
236
|
+
end
|
|
237
|
+
|
|
238
|
+
def body_text_plain
|
|
239
|
+
# TODO 以下のプレーンテキストを集めたやつを帰す
|
|
240
|
+
@body_all = ""
|
|
241
|
+
get_bodies(@message,:text_plain)
|
|
242
|
+
return @body_all
|
|
243
|
+
end
|
|
244
|
+
|
|
245
|
+
def get_bodies(message,content_type = nil)
|
|
246
|
+
if content_type == nil || message.content_type.content_type == content_type
|
|
247
|
+
@body_all += message.body
|
|
248
|
+
end
|
|
249
|
+
message.messages.each{|m|
|
|
250
|
+
get_bodies(m,content_type)
|
|
251
|
+
}
|
|
252
|
+
end
|
|
253
|
+
|
|
254
|
+
def from
|
|
255
|
+
return @message.header["from"]
|
|
256
|
+
end
|
|
257
|
+
|
|
258
|
+
def to
|
|
259
|
+
return @message.header["to"]
|
|
260
|
+
end
|
|
261
|
+
|
|
262
|
+
def return_path
|
|
263
|
+
return @message.header["return-path"]
|
|
264
|
+
end
|
|
265
|
+
|
|
266
|
+
def part_count
|
|
267
|
+
i = [0]
|
|
268
|
+
part_count_inner(@message,i)
|
|
269
|
+
i[0]
|
|
270
|
+
end
|
|
271
|
+
|
|
272
|
+
def part_count_inner(message,i)
|
|
273
|
+
i[0] += 1
|
|
274
|
+
message.messages.each{|m|
|
|
275
|
+
part_count_inner(m,i)
|
|
276
|
+
}
|
|
277
|
+
end
|
|
278
|
+
|
|
279
|
+
def initialize(save_original = true)
|
|
280
|
+
$KCODE = "u"
|
|
281
|
+
@save_original = save_original
|
|
282
|
+
@original = ""
|
|
283
|
+
@message = KmMessage.new(1)
|
|
284
|
+
end
|
|
285
|
+
|
|
286
|
+
def parse(io_stream)
|
|
287
|
+
while line = io_stream.gets
|
|
288
|
+
@message.parse(line)
|
|
289
|
+
if @save_original
|
|
290
|
+
@original += line
|
|
291
|
+
end
|
|
292
|
+
end
|
|
293
|
+
end
|
|
294
|
+
|
|
295
|
+
def parse_from_file(file_path)
|
|
296
|
+
open(file_path){|file|
|
|
297
|
+
parse(file)
|
|
298
|
+
}
|
|
299
|
+
end
|
|
300
|
+
|
|
301
|
+
def dump
|
|
302
|
+
dump_inner(@message)
|
|
303
|
+
info "=========== body =============="
|
|
304
|
+
info(@message.body)
|
|
305
|
+
end
|
|
306
|
+
|
|
307
|
+
def dump_inner(message)
|
|
308
|
+
info(("-" * message.depth) + "content-type=" + message.content_type.content_type.to_s)
|
|
309
|
+
info(("-" * message.depth) + "boundary=" + message.content_type.boundary.to_s) if message.content_type.boundary != nil
|
|
310
|
+
info(("-" * message.depth) + "file_path=" + message.file_path) if message.file_path != nil
|
|
311
|
+
info(("-" * message.depth) + "content_transfer_encoding=" + message.content_transfer_encoding.to_s) if message.content_transfer_encoding != nil
|
|
312
|
+
info(("-" * message.depth) + "header=" + message.header.inspect)
|
|
313
|
+
message.messages.each{|m|
|
|
314
|
+
dump_inner(m)
|
|
315
|
+
}
|
|
316
|
+
end
|
|
317
|
+
end
|
|
318
|
+
end
|
|
319
|
+
end
|
|
320
|
+
|