• R/O
  • SSH
  • HTTPS

dietmemorer: Commit


Commit MetaInfo

Revision29 (tree)
Time2008-02-12 15:31:44
Authoryaggy

Log Message

ボディーに「まとめ」などの特殊リクエストを書いてもOKにした

Change Summary

Incremental Difference

--- trunk/src/mail_control.rb (revision 28)
+++ trunk/src/mail_control.rb (revision 29)
@@ -13,72 +13,71 @@
1313
1414
1515 class MailControl
16-
16+
1717 def self.receivemail(pop3server, user, pass, smtpserver, smtpfrom)
18-
18+
1919 dbh = MysqlConnect.connect
20-
20+
2121 Net::POP3.start( pop3server, 110,
2222 user, pass){|pop|
23-
23+
2424 ma = MailAnalizer.new(dbh)
25-
25+
2626 if pop.mails.empty? then
27-# Debug.p 'no mail.'
27+ # Debug.p 'no mail.'
2828 else
2929 pop.each_mail do |m|
30-
30+
3131 mail = TMail::Mail.parse(m.pop)
32-begin
33- ma.analize(mail, smtpserver, smtpfrom)
34-rescue => exc
35- p exc
36- p "mail error... next..."
37-ensure
38- m.delete
39-end
32+ begin
33+ ma.analize(mail, smtpserver, smtpfrom)
34+ rescue => exc
35+ p exc
36+ p "mail error... next..."
37+ ensure
38+ m.delete
39+ end
4040 end
4141 Debug.p "#{pop.mails.size} mails popped."
4242 end
4343 }
44-
44+
4545 MysqlConnect.disconnect
46-
46+
4747 end
48-
48+
4949 def self.sendmail(smtpserver, to, from, subject, body)
5050 mail = TMail::Mail.new
51-
51+
5252 mail.to = to
5353 mail.from = from
5454 mail.reply_to = from
55-
55+
5656 work = Kconv.tojis(subject).split(//,1).pack('m').chomp
5757 mail.subject = "=?ISO-2022-JP?B?"+work.gsub('\n', '')+"?="
5858 mail.body = Kconv.tojis(body)
59-
59+
6060 Debug.p "mailbody = '" + mail.body + "'"
61-
61+
6262 mail.date = Time.now
6363 # mail.mime_version = '1.0'
6464 # mail.set_content_type 'text', 'plain', {'charset'=>'iso-2022-jp'}
65-
65+
6666 mail.write_back
67-
67+
6868 Debug.p "mailencoded = '" + mail.encoded + "'"
69-
69+
7070 sendmail_smtp(smtpserver, mail)
7171 end
72-
72+
7373 def self.sendmail_smtp( host, mail )
7474 msg = mail.encoded
75-
75+
7676 smtp = Net::SMTP.new(host, 25)
7777 smtp.start {
7878 smtp.send_mail msg, mail.from_address, mail.destinations
7979 }
8080 end
81-
82-
81+
82+
8383 end
84-
--- trunk/src/mail_analizer.rb (revision 28)
+++ trunk/src/mail_analizer.rb (revision 29)
@@ -278,9 +278,9 @@
278278
279279 if "" != detail then
280280 if mode == @@ReplyModeNormal then
281- rep = Kconv::kconv(fileread(@@repmail_memo), Kconv::UTF8)
282- else
283- rep = Kconv::kconv(fileread(@@repmail_sum), Kconv::UTF8)
281+ rep = Kconv::kconv(fileread(@@repmail_memo), Kconv::UTF8)
282+ else
283+ rep = Kconv::kconv(fileread(@@repmail_sum), Kconv::UTF8)
284284 end
285285 repsub = getfilesubject(rep)
286286 repbody = getfilebody(rep) + detail + Kconv::kconv(fileread(@@repmail_footer), Kconv::UTF8)
@@ -420,6 +420,12 @@
420420 mailsub = "empty..."
421421 end
422422
423+ mailsub.strip!
424+
425+ if nil == mailbody then
426+ mailbody = ""
427+ end
428+
423429 mailfrom = mail.from.to_s
424430
425431 # エラーメールっぽかったら無視
@@ -443,7 +449,7 @@
443449 end
444450
445451 # ヘルプ要求っぽかったら、ヘルプ送信
446- if MailAnalizer.in_ary(@@sub_help, mailsub) then
452+ if MailAnalizer.in_ary(@@sub_help, mailsub) or MailAnalizer.in_ary(@@sub_help, mailbody) then
447453 sth.finish
448454 Debug.p "send help."
449455 send_help(mailfrom, smtpserver, smtpfrom)
@@ -451,7 +457,7 @@
451457 end
452458
453459 # グラフ要求っぽかったら、グラフ送信
454- if MailAnalizer.in_ary(@@sub_graph, mailsub) then
460+ if MailAnalizer.in_ary(@@sub_graph, mailsub) or MailAnalizer.in_ary(@@sub_graph, mailbody) then
455461 sth.finish
456462 Debug.p "send graph."
457463 send_graph(mailfrom, smtpserver, smtpfrom)
@@ -459,7 +465,7 @@
459465 end
460466
461467 # 体重グラフ要求っぽかったら、体重グラフ送信
462- if MailAnalizer.in_ary(@@sub_wgraph, mailsub) then
468+ if MailAnalizer.in_ary(@@sub_wgraph, mailsub) or MailAnalizer.in_ary(@@sub_wgraph, mailbody) then
463469 sth.finish
464470 Debug.p "send weight graph."
465471 send_wgraph(mailfrom, smtpserver, smtpfrom)
@@ -467,7 +473,7 @@
467473 end
468474
469475 # 体脂肪グラフ要求っぽかったら、体脂肪グラフ送信
470- if MailAnalizer.in_ary(@@sub_fgraph, mailsub) then
476+ if MailAnalizer.in_ary(@@sub_fgraph, mailsub) or MailAnalizer.in_ary(@@sub_fgraph, mailbody) then
471477 sth.finish
472478 Debug.p "send fat graph."
473479 send_fgraph(mailfrom, smtpserver, smtpfrom)
@@ -475,7 +481,7 @@
475481 end
476482
477483 # エネルギーグラフ要求っぽかったら、体脂肪グラフ送信
478- if MailAnalizer.in_ary(@@sub_egraph, mailsub) then
484+ if MailAnalizer.in_ary(@@sub_egraph, mailsub) or MailAnalizer.in_ary(@@sub_egraph, mailbody) then
479485 sth.finish
480486 Debug.p "send energy graph."
481487 send_egraph(mailfrom, smtpserver, smtpfrom)
@@ -483,7 +489,7 @@
483489 end
484490
485491 # リセット要求っぽかったら、当日のデータ全消去
486- if MailAnalizer.in_ary(@@sub_reset, mailsub) then
492+ if MailAnalizer.in_ary(@@sub_reset, mailsub) or MailAnalizer.in_ary(@@sub_reset, mailbody) then
487493 sth.finish
488494 Debug.p "send reset."
489495 send_reset(mailfrom, smtpserver, smtpfrom)
@@ -491,7 +497,7 @@
491497 end
492498
493499 # まとめ要求っぽかったら、それを送信
494- if MailAnalizer.in_ary(@@sub_detail, mailsub) then
500+ if MailAnalizer.in_ary(@@sub_detail, mailsub) or MailAnalizer.in_ary(@@sub_detail, mailbody) then
495501 sth.finish
496502 Debug.p "send detail."
497503 send_detail(@@ReplyModeSum, mailfrom, smtpserver, smtpfrom)
@@ -499,45 +505,45 @@
499505 end
500506
501507 # 今月のまとめ要求っぽかったら、それを送信
502- if MailAnalizer.in_ary(@@sub_thismonth, mailsub) then
508+ if MailAnalizer.in_ary(@@sub_thismonth, mailsub) or MailAnalizer.in_ary(@@sub_thismonth, mailbody) then
503509 sth.finish
504510 Debug.p "send thismonth."
505511 send_detail(@@ReplyModeThisMonth, mailfrom, smtpserver, smtpfrom)
506512 return
507513 end
508-
514+
509515 # 今月のまとめ詳細要求っぽかったら、それを送信
510- if MailAnalizer.in_ary(@@sub_thismonth_detail, mailsub) then
516+ if MailAnalizer.in_ary(@@sub_thismonth_detail, mailsub) or MailAnalizer.in_ary(@@sub_thismonth_detail, mailbody) then
511517 sth.finish
512518 Debug.p "send thismonth detail."
513519 send_detail(@@ReplyModeThisMonthDetail, mailfrom, smtpserver, smtpfrom)
514520 return
515521 end
516-
522+
517523 # 先月のまとめ要求っぽかったら、それを送信
518- if MailAnalizer.in_ary(@@sub_lastmonth, mailsub) then
524+ if MailAnalizer.in_ary(@@sub_lastmonth, mailsub) or MailAnalizer.in_ary(@@sub_lastmonth, mailbody) then
519525 sth.finish
520526 Debug.p "send lastmonth."
521527 send_detail(@@ReplyModeLastMonth, mailfrom, smtpserver, smtpfrom)
522528 return
523529 end
524-
530+
525531 # 先月のまとめ詳細要求っぽかったら、それを送信
526- if MailAnalizer.in_ary(@@sub_lastmonth_detail, mailsub) then
532+ if MailAnalizer.in_ary(@@sub_lastmonth_detail, mailsub) or MailAnalizer.in_ary(@@sub_lastmonth_detail, mailbody) then
527533 sth.finish
528534 Debug.p "send lastmonth detail."
529535 send_detail(@@ReplyModeLastMonthDetail, mailfrom, smtpserver, smtpfrom)
530536 return
531537 end
532-
538+
533539 # 全部のまとめ詳細要求っぽかったら、それを送信
534- if MailAnalizer.in_ary(@@sub_all_detail, mailsub) then
540+ if MailAnalizer.in_ary(@@sub_all_detail, mailsub) or MailAnalizer.in_ary(@@sub_all_detail, mailbody) then
535541 sth.finish
536542 Debug.p "send all detail."
537543 send_detail(@@ReplyModeAll, mailfrom, smtpserver, smtpfrom)
538544 return
539545 end
540-
546+
541547 # ボディが空だったら、ヘルプ送信
542548 if nil == mailbody or "" == mailbody then
543549 sth.finish
Show on old repository browser