rumbster 1.0.0

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.
@@ -0,0 +1,197 @@
1
+ #
2
+ # textutils.rb
3
+ #
4
+ # Copyright (c) 1998-2004 Minero Aoki
5
+ #
6
+ # This program is free software.
7
+ # You can distribute/modify this program under the terms of
8
+ # the GNU Lesser General Public License version 2.1.
9
+ #
10
+
11
+ module TMail
12
+
13
+ class SyntaxError < StandardError; end
14
+
15
+
16
+ module TextUtils
17
+
18
+ private
19
+
20
+ def new_boundary
21
+ 'mimepart_' + random_tag()
22
+ end
23
+
24
+ @@uniq = 0
25
+
26
+ def random_tag
27
+ @@uniq += 1
28
+ t = Time.now
29
+ sprintf('%x%x_%x%x%d%x',
30
+ t.to_i, t.tv_usec,
31
+ $$, Thread.current.id, @@uniq, rand(255))
32
+ end
33
+
34
+ aspecial = '()<>[]:;.@\\,"'
35
+ tspecial = '()<>[];:@\\,"/?='
36
+ lwsp = " \t\r\n"
37
+ control = '\x00-\x1f\x7f-\xff'
38
+
39
+ ATOM_UNSAFE = /[#{Regexp.quote aspecial}#{control}#{lwsp}]/n
40
+ PHRASE_UNSAFE = /[#{Regexp.quote aspecial}#{control}]/n
41
+ TOKEN_UNSAFE = /[#{Regexp.quote tspecial}#{control}#{lwsp}]/n
42
+ CONTROL_CHAR = /[#{control}]/n
43
+ RFC2231_UNSAFE = /[#{Regexp.quote tspecial}#{control}#{lwsp}\*\'\%]/n
44
+
45
+ def atom_safe?(str)
46
+ ATOM_UNSAFE !~ str
47
+ end
48
+
49
+ def quote_atom(str)
50
+ (ATOM_UNSAFE =~ str) ? dquote(str) : str
51
+ end
52
+
53
+ def quote_phrase(str)
54
+ (PHRASE_UNSAFE =~ str) ? dquote(str) : str
55
+ end
56
+
57
+ def token_safe?(str)
58
+ TOKEN_UNSAFE !~ str
59
+ end
60
+
61
+ def quote_token(str)
62
+ (TOKEN_UNSAFE =~ str) ? dquote(str) : str
63
+ end
64
+
65
+ def dquote(str)
66
+ '"' + str.gsub(/["\\]/n) {|s| '\\' + s } + '"'
67
+ end
68
+ private :dquote
69
+
70
+ def join_domain(arr)
71
+ arr.map {|i| (/\A\[.*\]\z/ =~ i) ? i : quote_atom(i) }.join('.')
72
+ end
73
+
74
+ ZONESTR_TABLE = {
75
+ 'jst' => 9 * 60,
76
+ 'eet' => 2 * 60,
77
+ 'bst' => 1 * 60,
78
+ 'met' => 1 * 60,
79
+ 'gmt' => 0,
80
+ 'utc' => 0,
81
+ 'ut' => 0,
82
+ 'nst' => -(3 * 60 + 30),
83
+ 'ast' => -4 * 60,
84
+ 'edt' => -4 * 60,
85
+ 'est' => -5 * 60,
86
+ 'cdt' => -5 * 60,
87
+ 'cst' => -6 * 60,
88
+ 'mdt' => -6 * 60,
89
+ 'mst' => -7 * 60,
90
+ 'pdt' => -7 * 60,
91
+ 'pst' => -8 * 60,
92
+ 'a' => -1 * 60,
93
+ 'b' => -2 * 60,
94
+ 'c' => -3 * 60,
95
+ 'd' => -4 * 60,
96
+ 'e' => -5 * 60,
97
+ 'f' => -6 * 60,
98
+ 'g' => -7 * 60,
99
+ 'h' => -8 * 60,
100
+ 'i' => -9 * 60,
101
+ # j not use
102
+ 'k' => -10 * 60,
103
+ 'l' => -11 * 60,
104
+ 'm' => -12 * 60,
105
+ 'n' => 1 * 60,
106
+ 'o' => 2 * 60,
107
+ 'p' => 3 * 60,
108
+ 'q' => 4 * 60,
109
+ 'r' => 5 * 60,
110
+ 's' => 6 * 60,
111
+ 't' => 7 * 60,
112
+ 'u' => 8 * 60,
113
+ 'v' => 9 * 60,
114
+ 'w' => 10 * 60,
115
+ 'x' => 11 * 60,
116
+ 'y' => 12 * 60,
117
+ 'z' => 0 * 60
118
+ }
119
+
120
+ def timezone_string_to_unixtime(str)
121
+ if m = /([\+\-])(\d\d?)(\d\d)/.match(str)
122
+ sec = (m[2].to_i * 60 + m[3].to_i) * 60
123
+ (m[1] == '-') ? -sec : sec
124
+ else
125
+ min = ZONESTR_TABLE[str.downcase] or
126
+ raise SyntaxError, "wrong timezone format '#{str}'"
127
+ min * 60
128
+ end
129
+ end
130
+
131
+ WDAY = %w( Sun Mon Tue Wed Thu Fri Sat TMailBUG )
132
+ MONTH = %w( TMailBUG Jan Feb Mar Apr May Jun
133
+ Jul Aug Sep Oct Nov Dec TMailBUG )
134
+
135
+ def time2str(tm)
136
+ # [ruby-list:7928]
137
+ gmt = Time.at(tm.to_i)
138
+ gmt.gmtime
139
+ offset = tm.to_i - Time.local(*gmt.to_a[0,6].reverse).to_i
140
+
141
+ # DO NOT USE strftime: setlocale() breaks it
142
+ sprintf '%s, %s %s %d %02d:%02d:%02d %+.2d%.2d',
143
+ WDAY[tm.wday], tm.mday, MONTH[tm.month],
144
+ tm.year, tm.hour, tm.min, tm.sec,
145
+ *(offset / 60).divmod(60)
146
+ end
147
+
148
+ MESSAGE_ID = /<[^\@>]+\@[^>\@]+>/
149
+
150
+ def message_id?(str)
151
+ MESSAGE_ID =~ str
152
+ end
153
+
154
+ def mime_encoded?(str)
155
+ /=\?[^\s?=]+\?[QB]\?[^\s?=]+\?=/i =~ str
156
+ end
157
+
158
+ def decode_params(hash)
159
+ new = Hash.new
160
+ encoded = nil
161
+ hash.each do |key, value|
162
+ if m = /\*(?:(\d+)\*)?\z/.match(key)
163
+ ((encoded ||= {})[m.pre_match] ||= [])[(m[1] || 0).to_i] = value
164
+ else
165
+ new[key] = to_kcode(value)
166
+ end
167
+ end
168
+ if encoded
169
+ encoded.each do |key, strings|
170
+ new[key] = decode_RFC2231(strings.join(''))
171
+ end
172
+ end
173
+
174
+ new
175
+ end
176
+
177
+ NKF_FLAGS = {
178
+ 'EUC' => '-e -m',
179
+ 'SJIS' => '-s -m'
180
+ }
181
+
182
+ def to_kcode(str)
183
+ flag = NKF_FLAGS[$KCODE] or return str
184
+ NKF.nkf(flag, str)
185
+ end
186
+
187
+ RFC2231_ENCODED = /\A(?:iso-2022-jp|euc-jp|shift_jis|us-ascii)?'[a-z]*'/in
188
+
189
+ def decode_RFC2231(str)
190
+ m = RFC2231_ENCODED.match(str) or return str
191
+ NKF.nkf(NKF_FLAGS[$KCODE],
192
+ m.post_match.gsub(/%[\da-f]{2}/in) {|s| s[1,2].hex.chr })
193
+ end
194
+
195
+ end
196
+
197
+ end
@@ -0,0 +1 @@
1
+ require 'tmail'
@@ -0,0 +1,23 @@
1
+ #
2
+ # utils.rb
3
+ #
4
+ # Copyright (c) 1998-2004 Minero Aoki
5
+ #
6
+ # This program is free software.
7
+ # You can distribute/modify this program under the terms of
8
+ # the GNU Lesser General Public License version 2.1.
9
+ #
10
+
11
+ require 'tmail/textutils'
12
+ require 'socket'
13
+
14
+ module TMail
15
+
16
+ extend TextUtils
17
+
18
+ def TMail.new_message_id(fqdn = nil)
19
+ fqdn ||= ::Socket.gethostname
20
+ "<#{random_tag()}@#{fqdn}.tmail>"
21
+ end
22
+
23
+ end
metadata ADDED
@@ -0,0 +1,88 @@
1
+ --- !ruby/object:Gem::Specification
2
+ rubygems_version: 0.9.2
3
+ specification_version: 1
4
+ name: rumbster
5
+ version: !ruby/object:Gem::Version
6
+ version: 1.0.0
7
+ date: 2007-10-22 00:00:00 -05:00
8
+ summary: Rumbster is a simple SMTP server that receives email sent from a SMTP client. Received emails are published to observers that have registered with Rumbster. There are currently two observers; FileMailObserver and MailMessageObserver.
9
+ require_paths:
10
+ - lib
11
+ email: adam@esterlines.com
12
+ homepage: http://rumbster.rubyforge.org/
13
+ rubyforge_project: rumbster
14
+ description: Rumbster is a simple SMTP server that receives email sent from a SMTP client. Received emails are published to observers that have registered with Rumbster. There are currently two observers; FileMailObserver and MailMessageObserver.
15
+ autorequire:
16
+ default_executable:
17
+ bindir: bin
18
+ has_rdoc: true
19
+ required_ruby_version: !ruby/object:Gem::Version::Requirement
20
+ requirements:
21
+ - - ">"
22
+ - !ruby/object:Gem::Version
23
+ version: 0.0.0
24
+ version:
25
+ platform: ruby
26
+ signing_key:
27
+ cert_chain:
28
+ post_install_message:
29
+ authors:
30
+ - Adam Esterline
31
+ files:
32
+ - lib/message_observers.rb
33
+ - lib/rumbster.rb
34
+ - lib/smtp_protocol.rb
35
+ - lib/smtp_states.rb
36
+ - test/message_observers_test.rb
37
+ - test/rumbster_test.rb
38
+ - test/smtp_protocol_test.rb
39
+ - test/smtp_states_test.rb
40
+ - vendor/tmail/address.rb
41
+ - vendor/tmail/base64.rb
42
+ - vendor/tmail/compat.rb
43
+ - vendor/tmail/config.rb
44
+ - vendor/tmail/encode.rb
45
+ - vendor/tmail/header.rb
46
+ - vendor/tmail/info.rb
47
+ - vendor/tmail/loader.rb
48
+ - vendor/tmail/mail.rb
49
+ - vendor/tmail/mailbox.rb
50
+ - vendor/tmail/Makefile
51
+ - vendor/tmail/mbox.rb
52
+ - vendor/tmail/net.rb
53
+ - vendor/tmail/obsolete.rb
54
+ - vendor/tmail/parser.rb
55
+ - vendor/tmail/parser.y
56
+ - vendor/tmail/port.rb
57
+ - vendor/tmail/scanner.rb
58
+ - vendor/tmail/scanner_r.rb
59
+ - vendor/tmail/stringio.rb
60
+ - vendor/tmail/textutils.rb
61
+ - vendor/tmail/tmail.rb
62
+ - vendor/tmail/utils.rb
63
+ - vendor/tmail/.cvsignore
64
+ - vendor/tmail.rb
65
+ - COPYING
66
+ - Rakefile
67
+ - README
68
+ test_files:
69
+ - test/message_observers_test.rb
70
+ - test/rumbster_test.rb
71
+ - test/smtp_protocol_test.rb
72
+ - test/smtp_states_test.rb
73
+ rdoc_options:
74
+ - --title
75
+ - rumbster Documentation
76
+ - --main
77
+ - README
78
+ - -q
79
+ extra_rdoc_files:
80
+ - README
81
+ executables: []
82
+
83
+ extensions: []
84
+
85
+ requirements: []
86
+
87
+ dependencies: []
88
+