YkLib 0.1.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.
Files changed (125) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +11 -0
  3. data/.rspec +3 -0
  4. data/.travis.yml +6 -0
  5. data/CODE_OF_CONDUCT.md +74 -0
  6. data/Gemfile +7 -0
  7. data/Gemfile.lock +34 -0
  8. data/LICENSE.txt +21 -0
  9. data/README.md +44 -0
  10. data/Rakefile +6 -0
  11. data/YkLib.gemspec +29 -0
  12. data/bin/console +14 -0
  13. data/bin/setup +8 -0
  14. data/lib/YkLib/Yk/__advance__.rb +151 -0
  15. data/lib/YkLib/Yk/__defun__.rb +44 -0
  16. data/lib/YkLib/Yk/__hook__.rb +244 -0
  17. data/lib/YkLib/Yk/__minmax__.rb +123 -0
  18. data/lib/YkLib/Yk/__stdlog.rb +329 -0
  19. data/lib/YkLib/Yk/adhocLiterals/email.rb +119 -0
  20. data/lib/YkLib/Yk/adhocLiterals/path.rb +402 -0
  21. data/lib/YkLib/Yk/adhocLiterals/tag.rb +19 -0
  22. data/lib/YkLib/Yk/adhocLiterals/url.rb +36 -0
  23. data/lib/YkLib/Yk/adhocLiterals.rb +199 -0
  24. data/lib/YkLib/Yk/auto_escseq.rb +5 -0
  25. data/lib/YkLib/Yk/auto_pstore.rb +179 -0
  26. data/lib/YkLib/Yk/bsearch.rb +120 -0
  27. data/lib/YkLib/Yk/clambda.rb +309 -0
  28. data/lib/YkLib/Yk/confLine.rb +423 -0
  29. data/lib/YkLib/Yk/create_tty_width_available.rb +24 -0
  30. data/lib/YkLib/Yk/crypt.rb +26 -0
  31. data/lib/YkLib/Yk/debug2 +1 -0
  32. data/lib/YkLib/Yk/debug2.rb +473 -0
  33. data/lib/YkLib/Yk/debugout.rb +139 -0
  34. data/lib/YkLib/Yk/email_tz.rb +533 -0
  35. data/lib/YkLib/Yk/enum_expect.rb +170 -0
  36. data/lib/YkLib/Yk/errlog.rb +5 -0
  37. data/lib/YkLib/Yk/escseq.rb +59 -0
  38. data/lib/YkLib/Yk/eval_alt.rb +281 -0
  39. data/lib/YkLib/Yk/expector.rb +93 -0
  40. data/lib/YkLib/Yk/fetch.rb +556 -0
  41. data/lib/YkLib/Yk/fetch_old.rb +290 -0
  42. data/lib/YkLib/Yk/fib.rb +158 -0
  43. data/lib/YkLib/Yk/file_aux.rb +843 -0
  44. data/lib/YkLib/Yk/file_aux2.rb +919 -0
  45. data/lib/YkLib/Yk/file_aux_old.rb +160 -0
  46. data/lib/YkLib/Yk/filemod.rb +19 -0
  47. data/lib/YkLib/Yk/force_escseq.rb +3 -0
  48. data/lib/YkLib/Yk/generator__.rb +144 -0
  49. data/lib/YkLib/Yk/generator__.rb.org +139 -0
  50. data/lib/YkLib/Yk/indenter/argless_case.rb +46 -0
  51. data/lib/YkLib/Yk/indenter/each_token.rb +671 -0
  52. data/lib/YkLib/Yk/indenter/free_case.rb +313 -0
  53. data/lib/YkLib/Yk/indenter/if_less.rb +53 -0
  54. data/lib/YkLib/Yk/indenter/independent_ensure.rb +23 -0
  55. data/lib/YkLib/Yk/indenter/independent_rescue.rb +23 -0
  56. data/lib/YkLib/Yk/indenter/operand_circumflex.rb +0 -0
  57. data/lib/YkLib/Yk/indenter/operand_period.rb +16 -0
  58. data/lib/YkLib/Yk/indenter/parenless_and.rb +37 -0
  59. data/lib/YkLib/Yk/indenter/post_test.rb +48 -0
  60. data/lib/YkLib/Yk/indenter/token.rb +1525 -0
  61. data/lib/YkLib/Yk/indenter.rb +1382 -0
  62. data/lib/YkLib/Yk/inot.rb +265 -0
  63. data/lib/YkLib/Yk/intf.rb +815 -0
  64. data/lib/YkLib/Yk/io_aux.rb +1332 -0
  65. data/lib/YkLib/Yk/ioctl.rb +60 -0
  66. data/lib/YkLib/Yk/ipcc.rb +87 -0
  67. data/lib/YkLib/Yk/ipcountry.rb +207 -0
  68. data/lib/YkLib/Yk/ipv4adr.rb +318 -0
  69. data/lib/YkLib/Yk/localmail.rb +276 -0
  70. data/lib/YkLib/Yk/method_chain.rb +359 -0
  71. data/lib/YkLib/Yk/misc_tz.rb +1716 -0
  72. data/lib/YkLib/Yk/missing_method.rb +50 -0
  73. data/lib/YkLib/Yk/mojiConv.rb +257 -0
  74. data/lib/YkLib/Yk/nostdlog.rb +4 -0
  75. data/lib/YkLib/Yk/on_marshal.rb +20 -0
  76. data/lib/YkLib/Yk/overrider.rb +47 -0
  77. data/lib/YkLib/Yk/path.rb +293 -0
  78. data/lib/YkLib/Yk/path_aux.rb +883 -0
  79. data/lib/YkLib/Yk/path_aux_alt.rb +0 -0
  80. data/lib/YkLib/Yk/path_rep.rb +1267 -0
  81. data/lib/YkLib/Yk/pg_setup.rb +917 -0
  82. data/lib/YkLib/Yk/procinfo.rb +314 -0
  83. data/lib/YkLib/Yk/proclist.rb +492 -0
  84. data/lib/YkLib/Yk/property.rb +863 -0
  85. data/lib/YkLib/Yk/ranger.rb +606 -0
  86. data/lib/YkLib/Yk/resolv_tz.rb +88 -0
  87. data/lib/YkLib/Yk/rlprompt.rb +73 -0
  88. data/lib/YkLib/Yk/rootexec.rb +48 -0
  89. data/lib/YkLib/Yk/rpm-packageproxy.rb +784 -0
  90. data/lib/YkLib/Yk/rpm-packageproxy2.rb +1430 -0
  91. data/lib/YkLib/Yk/rwhen.rb +21 -0
  92. data/lib/YkLib/Yk/selector.rb +124 -0
  93. data/lib/YkLib/Yk/set.rb +170 -0
  94. data/lib/YkLib/Yk/shellquote.rb +300 -0
  95. data/lib/YkLib/Yk/sio.rb +1001 -0
  96. data/lib/YkLib/Yk/sio0.rb +835 -0
  97. data/lib/YkLib/Yk/sio_aux.rb +1524 -0
  98. data/lib/YkLib/Yk/sio_inot.rb +86 -0
  99. data/lib/YkLib/Yk/sock_aux.rb +42 -0
  100. data/lib/YkLib/Yk/spipe.rb +843 -0
  101. data/lib/YkLib/Yk/sql_table.rb +565 -0
  102. data/lib/YkLib/Yk/stdlog.rb +4 -0
  103. data/lib/YkLib/Yk/syscommand.rb +173 -0
  104. data/lib/YkLib/Yk/sysinit.rb +75 -0
  105. data/lib/YkLib/Yk/ttyFontWidth.rb +46113 -0
  106. data/lib/YkLib/Yk/tty_char.dump +0 -0
  107. data/lib/YkLib/Yk/tty_char.rb +47 -0
  108. data/lib/YkLib/Yk/tty_char_create.rb +437031 -0
  109. data/lib/YkLib/Yk/tty_char_static.rb +437016 -0
  110. data/lib/YkLib/Yk/tty_rewrite.rb +142 -0
  111. data/lib/YkLib/Yk/tty_str.rb +461 -0
  112. data/lib/YkLib/Yk/tty_width.dat.rb +114 -0
  113. data/lib/YkLib/Yk/tty_width.rb +180 -0
  114. data/lib/YkLib/Yk/tty_width_available +569 -0
  115. data/lib/YkLib/Yk/tty_width_list +0 -0
  116. data/lib/YkLib/Yk/tty_width_list.linux +280 -0
  117. data/lib/YkLib/Yk/tty_width_list.windows +324 -0
  118. data/lib/YkLib/Yk/tz_tty +0 -0
  119. data/lib/YkLib/Yk/tz_tty.rb +0 -0
  120. data/lib/YkLib/Yk/uprepos.rb +94 -0
  121. data/lib/YkLib/Yk/userinfo.rb +91 -0
  122. data/lib/YkLib/Yk/with.rb +109 -0
  123. data/lib/YkLib/version.rb +3 -0
  124. data/lib/YkLib.rb +6 -0
  125. metadata +170 -0
@@ -0,0 +1,533 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "net/smtp.rb"
4
+ require "base64"
5
+ require "kconv"
6
+ #require "iconv"
7
+ require 'Yk/path_aux'
8
+
9
+
10
+ ################################################################################
11
+ #
12
+ # String
13
+ #
14
+
15
+ #---------------------------------------------------------------------------
16
+ #
17
+ # mime encode
18
+ #
19
+ def __encode_for_mime slf, mode = nil
20
+ s = nil
21
+ if !mode
22
+ slf.each_char do |c|
23
+ if !" \r\n\tabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#\$%&'()=~^|`@{}*+:;<>,?/[]-\\._".include? c
24
+ mode = :non_ascii
25
+ break
26
+ end
27
+ end
28
+ if mode != :non_ascii
29
+ mode = "ascii"
30
+ else
31
+ begin
32
+ s = slf.encode(Encoding::ISO2022_JP)
33
+ mode = "jp"
34
+ rescue Encoding::InvalidByteSequenceError, Encoding::UndefinedConversionError
35
+ begin
36
+ s = slf.encode("GB2312")
37
+ mode = "zh"
38
+ rescue Encoding::InvalidByteSequenceError, Encoding::UndefinedConversionError
39
+ begin
40
+ s = slf.encode("UTF-8")
41
+ mode = "utf"
42
+ rescue Encoding::InvalidByteSequenceError
43
+ end
44
+ end
45
+ end
46
+ end
47
+ case mode
48
+ when /^ascii$/i
49
+ return slf, mode
50
+ when /^jp$/i
51
+ s ||= slf.encode(Encoding::ISO2022_JP)
52
+ return s, mode
53
+ when /^zh$/i
54
+ s ||= slf.encode("GB2312")
55
+ return s, mode
56
+ when /^utf$/i
57
+ s ||= slf.encode("UTF-8")
58
+ return s, mode
59
+ else
60
+ return slf, mode
61
+ end
62
+ end
63
+ end
64
+
65
+ class String
66
+ #---------------------------------------------------------------------------
67
+ #
68
+ # mime decode
69
+ #
70
+ def mime_decode
71
+ return self unless self =~ /^=\?(ISO-2022-JP|UTF-8|GB2312)\?B\?(.+)\?=$/i
72
+ return Base64.decode64($1)
73
+ end
74
+ def google_link
75
+ expr = self
76
+ e2, mode = __encode_for_mime expr.strip
77
+ case expr
78
+ when /^\+81/
79
+ url = "<a href='https://www.google.com/search?q=0#{$'}'>#{expr}</a>"
80
+ when /^\+86/
81
+ cnum = $'
82
+ if cnum !~ /^1[1-9]\d\d\d\d\d\d\d\d\d$/
83
+ cnum = "0" + cnum
84
+ end
85
+ url = "<a href='https://www.baidu.com/s?wd=#{cnum}'>#{expr}</a>"
86
+ else
87
+ case mode
88
+ when "zh"
89
+ url = "<a href='https://www.baidu.com/s?wd=#{cnum}'>#{expr}</a>"
90
+ else
91
+ url = "<a href='https://www.google.com/search?q=0#{$'}'>#{expr}</a>"
92
+ end
93
+ end
94
+ url
95
+ end
96
+ end
97
+
98
+ class MimeBody < String
99
+ attr :body
100
+ def initialize arg, mode = nil
101
+ type = "plain"
102
+ case arg
103
+ when /\<\s*\/\s*html\s*\>/
104
+ type = "html"
105
+ when /\<\s*\/\s*a\s*\>/
106
+ arg = "<html><pre>#{arg}</pre></html>"
107
+ type = "html"
108
+ end
109
+ @body, @mode = __encode_for_mime(arg, mode)
110
+ case @mode
111
+ when /^ascii$/i
112
+ @header = "Content-Type:text/#{type}\nContent-Transfer-Encoding: 7bit"
113
+ when /^jp$/i
114
+ @header = "Content-Type:text/#{type}; charset=\"ISO-2022-JP\"\nContent-Transfer-Encoding: 7bit"
115
+ when /^zh$/i
116
+ @header = "Content-Type:text/#{type}; charset=\"GB2312\"\nContent-Transfer-Encoding: 7bit"
117
+ when /^utf$/i
118
+ @header = "Content-Type:text/#{type}; charset=\"UTF-8\"\nContent-Transfer-Encoding: base64"
119
+ @body = Base64.encode64(@body)
120
+ end
121
+ super @header.force_encoding("ascii-8bit") + "\n\n" + @body.force_encoding("ascii-8bit")
122
+ end
123
+ end
124
+
125
+ class MimeHeader < String
126
+ def initialize arg, mode = nil
127
+ if arg =~ /:/
128
+ @title = $` + $&
129
+ @content, @mode = __encode_for_mime($', mode)
130
+ case @mode
131
+ when /^ascii$/i
132
+ when /^jp$/i
133
+ @content = "=?ISO-2022-JP?B?" + Base64.encode64(@content.chomp).gsub!(/\n/, "") + "?=\n"
134
+ when /^zh$/i
135
+ @content = "=?GB2312?B?" + Base64.encode64(@content.chomp).gsub!(/\n/, "") + "?=\n"
136
+ when /^utf$/i
137
+ @content = "=?UTF-8?B?" + Base64.encode64(@content.chomp).gsub!(/\n/, "") + "?=\n"
138
+ end
139
+ super @title.force_encoding("ascii-8bit") + @content.force_encoding("ascii-8bit")
140
+ else
141
+ super arg
142
+ end
143
+ end
144
+ end
145
+
146
+ class String
147
+ def mime_encode mode = nil
148
+ MimeHeader.new self, mode
149
+ end
150
+ end
151
+
152
+
153
+
154
+ module TZEMail
155
+ ################################################################################
156
+ #
157
+ # Email
158
+ #
159
+ class Email
160
+
161
+ attr_reader :header
162
+ attr_reader :body
163
+ attr_accessor :smtpServer
164
+
165
+ #---------------------------------------------------------------------------
166
+ #
167
+ # Initialize メールオブジェクトを生成する
168
+ #
169
+ def initialize(mail = nil) # mail = Array or IO(ex.STDIN) or nil
170
+ key = nil
171
+ @header = {}
172
+ @body = []
173
+
174
+ return if mail == nil
175
+
176
+ inBody = false
177
+ mail.each {|line|
178
+ line.chomp!
179
+ unless inBody
180
+ if line =~ /^$/ # 空行
181
+ inBody = true
182
+ elsif line =~ /^(\S+?):\s*(.*)/ # ヘッダ行
183
+ key = $1.capitalize
184
+ @header[key] = $2
185
+ elsif key # ヘッダ行が2行に渡る場合
186
+ @header[key] += "\n" + line.sub(/^\s*/, "\t")
187
+ end
188
+ else
189
+ @body.push(line)
190
+ end
191
+ }
192
+ end
193
+
194
+ #---------------------------------------------------------------------------
195
+ #
196
+ # [] ヘッダを参照
197
+ #
198
+ def [](key)
199
+ @header[key.capitalize]
200
+ end
201
+
202
+ #---------------------------------------------------------------------------
203
+ #
204
+ # []= ヘッダを設定
205
+ #
206
+ def []=(key, value)
207
+ @header[key.capitalize] = value
208
+ end
209
+
210
+ #---------------------------------------------------------------------------
211
+ #
212
+ # << ボディにテキストを追加
213
+ #
214
+ def <<(message)
215
+ @body.push message
216
+ end
217
+
218
+ #---------------------------------------------------------------------------
219
+ #
220
+ # encode メールをテキストストリームにエンコード
221
+ #
222
+ def encode
223
+ mail = ""
224
+ @header.each {|key, value|
225
+ mail += "#{key}: #{value}\n"
226
+ }
227
+ mail += "\n" # ヘッダ/ボディのセパレータ
228
+ @body.each {|message|
229
+ mail += "#{message}\n"
230
+ }
231
+ return mail
232
+ end
233
+
234
+ #---------------------------------------------------------------------------
235
+ #
236
+ # send メールを送る
237
+ #
238
+ def send server = "localhost", user = nil, passwd = nil, auth = nil
239
+ from = @header['From']
240
+ to = []
241
+ to.push @header['To']
242
+ Net::SMTP.start(server, 25, 'localhost.localdomain', user, passwd, auth) {|smtp|
243
+ smtp.send_mail(self.encode, from, *to)
244
+ }
245
+ end
246
+ end
247
+
248
+ ################################################################################
249
+ #
250
+ # EncodedEmail
251
+ #
252
+ class EncodedEmail < Email
253
+
254
+ #---------------------------------------------------------------------------
255
+ #
256
+ # Decode メールブロックをデコード
257
+ #
258
+ def decode
259
+ if self['Content-transfer-encoding'] =~ /base64/i
260
+ return Base64.decode64(@body.join)
261
+ else
262
+ return @body.join("\n")
263
+ end
264
+ end
265
+
266
+ #---------------------------------------------------------------------------
267
+ #
268
+ # << ボディにコンテントを追加
269
+ #
270
+ def <<(content)
271
+ if self['Content-transfer-encoding'] =~ /base64/i
272
+ @body = Base64.encode64(content).split("\n")
273
+ else
274
+ @body = content.split("\n")
275
+ end
276
+ end
277
+ end
278
+
279
+ ################################################################################
280
+ #
281
+ # AttachedEmail
282
+ #
283
+ class AttachedEmail < EncodedEmail
284
+
285
+ attr_reader :block
286
+
287
+ #---------------------------------------------------------------------------
288
+ #
289
+ # Initialize 添付メールオブジェクトを生成する
290
+ #
291
+ def initialize(mail = nil)
292
+
293
+ super(mail)
294
+
295
+ if mail == nil
296
+ @separator = "separator" + (rand 65536).to_s
297
+ self['MIME-Version'] = "1.0"
298
+ self['Content-Type'] = "Multipart/Mixed; boundary=\"#{@separator}\""
299
+ @block = []
300
+ return
301
+ end
302
+
303
+ return unless self['Content-Type'] =~ /^Multipart\/Mixed;\s*boundary=(["']?)(.*)\1/i
304
+ @separator = $2
305
+ @block = []
306
+
307
+ buf = []
308
+ @body.each {|line|
309
+ if line =~ /^--#{@separator}/
310
+ @block.push(EncodedEmail.new(buf))
311
+ buf = []
312
+ next
313
+ end
314
+ buf.push(line)
315
+ }
316
+
317
+ @block.shift
318
+ @body = []
319
+ end
320
+
321
+ #---------------------------------------------------------------------------
322
+ #
323
+ # << メールブロックを追加
324
+ #
325
+ def <<(block)
326
+ @block.push(block)
327
+ end
328
+
329
+ #---------------------------------------------------------------------------
330
+ #
331
+ # encode メールをテキストストリームにエンコード
332
+ #
333
+ def encode
334
+ @block.each {|block|
335
+ @body.push("--" + @separator)
336
+ @body += block.encode.split("\n")
337
+ }
338
+ @body.push("--" + @separator + "--")
339
+ super
340
+ end
341
+ end
342
+
343
+ end
344
+
345
+ class EMailSender
346
+ attr_accessor :to, :from, :subject, :text, :server, :passwd, :user, :auth
347
+ def initialize mode
348
+ case mode
349
+ when /^jp$/i
350
+ @mode = "jp"
351
+ when /^zh$/i
352
+ @mode = "zh"
353
+ end
354
+ @attachedFiles = Hash.new
355
+ end
356
+ def attach file
357
+ !file.readable_file? and raise(Exception.new("cannot read file #{f}"))
358
+ @attachedFiles[file] = true
359
+ end
360
+ def detach file
361
+ @attachedFiles.delete file
362
+ end
363
+ def getFileBlock f
364
+ if f.readable_file?
365
+ fBlock = TZEMail::EncodedEmail.new
366
+ name = f.basename.mime_encode @mode
367
+ ctype = f =~ /\.(jpg|jpeg|gif|png)$/ ? "Image/#{$1}" : "Application/Octet-Stream"
368
+ fBlock['Content-Type'] = "#{ctype}; name=\"#{name}\""
369
+ fBlock['Content-transfer-encoding'] = "base64"
370
+ fBlock << f.read
371
+ fBlock
372
+ else
373
+ raise Exception.new("cannot read file #{f}")
374
+ end
375
+ end
376
+ def charset
377
+ case @mode
378
+ when "jp"
379
+ "charset=iso-2022-jp"
380
+ when "zh"
381
+ "charset=gb2312"
382
+ else
383
+ ""
384
+ end
385
+ end
386
+ def convert t
387
+ case @mode
388
+ when "jp"
389
+ t.tojis
390
+ else
391
+ t
392
+ end
393
+ end
394
+ def getTextBlock
395
+ tBlock = TZEMail::Email.new
396
+ tBlock['Content-Type'] = "Text/Plain; #{charset}"
397
+ tBlock << convert(text)
398
+ tBlock
399
+ end
400
+ def send *args
401
+ email = TZEMail::AttachedEmail.new
402
+ to and email['To'] = @to
403
+ from and email['From'] = @from
404
+ subject and (email['Subject'] = @subject.mime_encode @mode)
405
+ if text
406
+ email << getTextBlock
407
+ end
408
+ @attachedFiles.keys.each do |file|
409
+ email << getFileBlock(file)
410
+ end
411
+ email.send(server, user, passwd, auth)
412
+ end
413
+ def EMailSender.send smtp, from, to, text, subject = nil, files = nil, xPriority = nil
414
+ sendmail smtp, files, <<END
415
+ From: #{from}
416
+ #{subject && "Subject: #{subject}\n"}To: #{to}
417
+ Date: #{Time.now.strftime("%a, %e %b %Y %T %z").gsub(/\s+/, " ")}#{xPriority && "\nX-Priority: #{xPriority}"}
418
+
419
+ #{text}
420
+ END
421
+ end
422
+ TList = []
423
+ def EMailSender.sendmail smtp, files, mail
424
+ headers = []
425
+ if mail =~ /\n\n/
426
+ h, b = $` + "\n", $'
427
+ else
428
+ h, b = mail, ""
429
+ end
430
+ h.each_line do |ln|
431
+ if ln !~ /^\s/ || headers.size == 0
432
+ headers.push ln
433
+ else
434
+ headers[-1] += ln
435
+ end
436
+ end
437
+ mail = ""
438
+ from = nil
439
+ to = nil
440
+ headers.each do |h|
441
+ if h =~ /^From:/ && h =~ /[^<\s\"]+\@[^>\s\"]+/
442
+ from = $&
443
+ end
444
+ if h =~ /^To:/ && h =~ /[^<\s\"]+\@[^>\s\"]+/
445
+ to = $&
446
+ end
447
+ mail += MimeHeader.new h
448
+ end
449
+ if files && files.size > 0
450
+ bdstr = "-------#{rand(1000000000)}#{rand(1000000000)}"
451
+ bdstrb = "--" + bdstr
452
+ mail += "Content-Type: multipart/mixed; boundary=\"#{bdstr}\"\n\n#{bdstrb}\n"
453
+ end
454
+ mail += MimeBody.new b
455
+ if bdstr
456
+ mail = mail.chomp.ln + bdstrb
457
+ files.each do |f|
458
+ case f
459
+ when /\.(png|gif|bmp)$/i
460
+ type = "image/#{$1.downcase}"
461
+ when /\.(jpg|jpeg)$/i
462
+ type = "image/jpeg"
463
+ when /\.(tiff|tif)$/i
464
+ type = "image/tiff"
465
+ when /\.(text|txt)$/i
466
+ type = "text/plain"
467
+ when /\.csv$/i
468
+ type = "text/csv"
469
+ when /\.(html|htm)$/i
470
+ type = "text/html"
471
+ when /\.pdf$/i
472
+ type = "application/pdf"
473
+ when /\.(xls|xlsx)$/i
474
+ type = "application/vnd.ms-exel"
475
+ when /\.(doc|docx)$/i
476
+ type = "application/msword"
477
+ when /\.(doc|docx)$/i
478
+ type = "application/msword"
479
+ when /\.(ppt|pptx|pptm)$/i
480
+ type = "application/vnd.ms-powerpoint"
481
+ when /\.exe$/i
482
+ type = "application/octet-stream"
483
+ when /\.tar(|.*)$/i
484
+ type = "application/x-tar"
485
+ when /\.zip$/i
486
+ type = "application/zip"
487
+ when /\.lzh$/i
488
+ type = "application/x-lzh"
489
+ when /\.mp3$/i
490
+ type = "audio/mpeg"
491
+ when /\.mp4$/i
492
+ type = "audio/mp4"
493
+ when /\.mpeg$/i
494
+ type = "video/mpeg"
495
+ else
496
+ type = "application/octet-stream"
497
+ end
498
+ mail += "\n"
499
+ mail += MimeHeader.new "Content-Type: #{type}; name = \"#{f.basename}\"\n"
500
+ mail += "Content-Transfer-Encoding: base64\n\n"
501
+ mail += Base64.encode64(f.read).chomp.ln
502
+ mail += bdstrb
503
+ end
504
+ mail += "--"
505
+ end
506
+ h, p = smtp.split(/:/)
507
+ p ||= 25
508
+ p = p.to_i
509
+ pid = fork do
510
+ fork do
511
+ Net::SMTP.start(h, p) {|smtp|
512
+ smtp.send_message(mail, from, to)
513
+ }
514
+ exit 0
515
+ end
516
+ exit 0
517
+ end
518
+ end
519
+ end
520
+
521
+
522
+ if __FILE__.basename == $0.basename
523
+ sender = EMailSender.new "jp"
524
+ # sender.text = "test"
525
+ sender.text = "XJS*C4JDBQADN1.NSBN3*2IDNEN*GTUBE-STANDARD-ANTI-UBE-TEST-EMAIL*C.34X"
526
+ sender.subject = "テスト"
527
+ # sender.attach "/root/eicar_com.zip"
528
+ sender.to = "yougain@nifty.com"
529
+ sender.from = "yuan@you.dix.asia"
530
+ sender.send
531
+ end
532
+
533
+
@@ -0,0 +1,170 @@
1
+ class RandLabel
2
+ def self.create
3
+ rand(100000000).to_s.intern
4
+ end
5
+ end
6
+
7
+ class Enumerator
8
+ class ExpectItem
9
+ attr_reader :regexp, :label, :block, :binding
10
+ def initialize this, expr, label, bl, bind
11
+ @this = this
12
+ @regexp = expr
13
+ @label = label
14
+ @block = bl
15
+ @binding = bind
16
+ end
17
+ def match isFirst
18
+ matched = @regexp && @binding.eval("#{@this.peek.inspect} =~ #{@regexp.inspect}")
19
+ if matched
20
+ @this.next
21
+ if isFirst
22
+ while true
23
+ catch @label do
24
+ @block.call
25
+ nil
26
+ end == @label or break
27
+ end
28
+ else
29
+ throw @label, @label
30
+ end
31
+ end
32
+ matched
33
+ end
34
+ def continue num = 1, &bl
35
+ num.times do
36
+ @this.expect true, &bl
37
+ end
38
+ end
39
+ end
40
+ class PararellItem < ExpectItem
41
+ Item = Struct.new :regexp, :label, ;block, :binding
42
+ def initialize this
43
+ @this = this
44
+ @items = []
45
+ end
46
+ def add expr, label, bl, bind
47
+ @items.push Item.new(expr, label, bl, bind)
48
+ end
49
+ def match isFirst
50
+ it = @items.find do |it|
51
+ it.regexp && it.binding.eval("#{@this.peek.inspect} =~ #{it.regexp.inspect}")
52
+ end
53
+ if !it
54
+ it = @items.find{_1.regexp.nil?}
55
+ end
56
+ if it
57
+ cur = @this.peek
58
+ @this.next
59
+ if isFirst
60
+ while true
61
+ ret = catch @label do
62
+ it.block.call cur
63
+ nil
64
+ end
65
+ break if ret.nil?
66
+ j = @items.find{|i| i.label == ret[0]}
67
+ if j
68
+ it = j
69
+ cur = ret[1]
70
+ next
71
+ else
72
+ break
73
+ end
74
+ end
75
+ else
76
+ throw @label, [it.label, cur]
77
+ end
78
+ end
79
+ it
80
+ end
81
+ end
82
+ def expect expr = nil, &bl
83
+ if expr == true
84
+ expr = nil
85
+ cont = true
86
+ end
87
+ if !@eItems[-1].is_a? PararellItem
88
+ @eItems.push ExpectItem.new(self, expr, RandLabel.create, bl, binding_of_caller)
89
+ it = nil
90
+ entity = ->{
91
+ isFirst = true
92
+ @eItems.reverse_each do |eItem|
93
+ it = eItem.match isFirst
94
+ break if it
95
+ isFirst = false
96
+ end
97
+ if cont
98
+ it = true
99
+ cur = peek
100
+ self.next
101
+ bl.call cur
102
+ end
103
+ }
104
+ begin
105
+ if @eItems.size == 1
106
+ begin
107
+ while true
108
+ entity.call
109
+ self.next
110
+ end
111
+ rescue StopIteration
112
+ end
113
+ else
114
+ entity.call
115
+ end
116
+ ensure
117
+ @eItems.pop
118
+ end
119
+ it
120
+ else
121
+ @exprs[-1].add expr, RandLabel.create, bl, caller_binding
122
+ end
123
+ end
124
+ def pararell
125
+ @eItems.push PararellItem.new(self)
126
+ begin
127
+ yield
128
+ if @eItems.size == 1
129
+ begin
130
+ while true
131
+ match or self.next
132
+ end
133
+ rescue StopIteration
134
+ end
135
+ else
136
+ match
137
+ end
138
+ ensure
139
+ @eItems.pop
140
+ end
141
+ end
142
+ def else &bl
143
+ if @eItems[-1].is_a? PararellItem
144
+ @exprs[-1].add nil, RandLabel.create, bl, caller_binding
145
+ end
146
+ end
147
+ end
148
+
149
+
150
+ #(e = lines.to_enum).expect /.../ do |ln|
151
+ # e.expect /a/ do
152
+ #
153
+ # end
154
+ # e.expect /b/ do
155
+ #
156
+ #
157
+ # end&.continue 5 do
158
+ #
159
+ # end
160
+ # e.pararell do
161
+ # e.expect /c/ do
162
+ # end
163
+ # e.expect /d/ do
164
+ # end
165
+ # e.else do
166
+ # end
167
+ # end
168
+ #end
169
+
170
+
@@ -0,0 +1,5 @@
1
+
2
+ ENV['ERRLOG_FUNC'] = "1"
3
+ require 'Yk/__stdlog'
4
+
5
+