[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[mhc:02110] patch (today.in)



野口です。

生活環境は、WinXP + Meadow + Cygwin という状況です。

  localhost では smtp サーバが動いていない

場合に、 today で「ISPの smtp サーバを利用して」メールを送りたいと思い、
添付のように手を入れてみました。

私の利用している ISP では、
  ・From: がそのISPのアドレスでないとダメ
  ・まず SMTP-AUTH で認証しないとダメ
という制約がありまして、それにも対応できるようにしてみています。


-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  --mail=ToADDRESS[[ToADDRESS2,...],FromAddress]
                         send a e-mail to ToADDRESS(s) instead of listing
                         to stdout.
                         If you want to specify From:, set FromAddress.
  --smtpserver=HOSTNAME[,ACCOUNT,PASSWD,AUTHTYPE]
                         specify SMTP Server when sending e-mail.
                         If you have to use SMTP-AUTH, use below:
                            ACCOUNT:  Account for SMTP AUTH
                            PASSWD:   Passowrd for SMTP AUTH
                            AUTHTYPE: Authentication method for SMTP AUTH
                                      ("plain" or "cram_md5" or "login")
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

以上、ご検討いただければ幸いです。
-- 
NOGUCHI Yusuke <nogunogu@xxxxxxxxxxxxxxxxx>
*** mhc-current-snap20050420/today.in	Mon Jan 12 19:24:37 2004
--- mhc-current-snap20050420-new/today.in	Sun Apr 24 19:41:28 2005
***************
*** 17,24 ****
  
  $DEBUG2       = false
  
- MailServer    = 'localhost'  ## for --mail option
  MyHostName    = 'localhost'  ## for --mail option
  
  require 'mhc-schedule'
  require 'mhc-kconv'
--- 17,27 ----
  
  $DEBUG2       = false
  
  MyHostName    = 'localhost'  ## for --mail option
+ smtpServer    = 'localhost'  ## for --mail option
+ smtp_account = nil
+ smtp_passwd = nil
+ smtp_type = nil
  
  require 'mhc-schedule'
  require 'mhc-kconv'
***************
*** 49,65 ****
  def usage(do_exit = true)
    STDERR .print "usage: today [options]
    Show your today's schedules.
!   --help               show this message.
!   --format=FORMAT      change output format to one of: ps, html
!   --category=CATEGORY  pick only in CATEGORY. 
!                        '!' and space separated multiple values are allowed.
!   --date=strig[+n]     set a period of date.
!                        string is one of these:
!                          today, tomorrow, sun ... sat, yyyymmdd, yyyymm
!                        yyyymm lists all days in the month.
!                        list n+1 days of schedules if +n is given.
!                        default value is 'today+0'
!   --mail=ADDRESS       send a e-mail to ADDRESS instead of listing to stdout.\n"
    exit if do_exit
  end
  
--- 52,79 ----
  def usage(do_exit = true)
    STDERR .print "usage: today [options]
    Show your today's schedules.
!   --help                 show this message.
!   --format=FORMAT        change output format to one of: ps, html
!   --category=CATEGORY    pick only in CATEGORY. 
!                          '!' and space separated multiple values are allowed.
!   --date=strig[+n]       set a period of date.
!                          string is one of these:
!                            today, tomorrow, sun ... sat, yyyymmdd, yyyymm
!                          yyyymm lists all days in the month.
!                          list n+1 days of schedules if +n is given.
!                          default value is 'today+0'
!   --mail=ToADDRESS[[ToADDRESS2,...],FromAddress]
!                          send a e-mail to ToADDRESS(s) instead of listing 
!                          to stdout.
!                          If you want to specify From:, set FromAddress.
!   --smtpserver=HOSTNAME[,ACCOUNT,PASSWD,AUTHTYPE]
!                          specify SMTP Server when sending e-mail.
!                          If you have to use SMTP-AUTH, use below:
!                             ACCOUNT:  Account for SMTP AUTH
!                             PASSWD:   Passowrd for SMTP AUTH
!                             AUTHTYPE: Authentication method for SMTP AUTH
!                                       (\"plain\" or \"cram_md5\" or \"login\")
! \n"
    exit if do_exit
  end
  
***************
*** 235,242 ****
      date_from, date_to = string_to_date($1, $3) || usage()
  
    when /^--mail=(.+)/
!     mail_address = $1
! 
    else
      usage()
    end
--- 249,275 ----
      date_from, date_to = string_to_date($1, $3) || usage()
  
    when /^--mail=(.+)/
!     mail_address = $1 .split(',')
!     if mail_address .size > 1
!       from_addr = mail_address[-1]
!       mail_address .delete_at(-1)
!       to_addr = mail_address
!     else
!       to_addr = mail_address[0]
!       from_addr = "secretary-of-" + to_addr
!     end
!   when /^--smtpserver=(.+)/
!     smtpServer, smtp_account, smtp_passwd, smtp_type = $1 .split(',')
!     case smtp_type
!     when "plain"
!       smtp_type = :plain
!     when "login"
!       smtp_type = :login
!     when "cram_md5"
!       smtp_type = :cram_md5
!     else
!       usage()
!     end
    else
      usage()
    end
***************
*** 251,259 ****
  db = MhcScheduleDB .new
  
  if mail_address
!   header    = "To: #{mail_address}\n"
!   header   += "From: secretary-of-#{mail_address}\n"
    header   += "Subject: Today's schedule (#{date_from .to_s})\n"
    header   += "\n"
    header   += "#{user_name}'s schedule: \n\n"
    contents  = 
--- 284,294 ----
  db = MhcScheduleDB .new
  
  if mail_address
!   date = Time.now.strftime("%a, %d %b %Y %H:%M:%S %z")
!   header    = "To: #{to_addr.join(' ,')}\n"
!   header   += "From: #{from_addr}\n"
    header   += "Subject: Today's schedule (#{date_from .to_s})\n"
+   header   += "Date: #{date}\n"
    header   += "\n"
    header   += "#{user_name}'s schedule: \n\n"
    contents  = 
***************
*** 261,268 ****
  
    if contents && contents != ''
      message = MhcKconv::tomail(header + contents)
!     Net::SMTPSession .start(MailServer, 25, MyHostName) {|server|
!       server .sendmail(message, mail_address, [mail_address])
      }
    end
  else
--- 296,303 ----
  
    if contents && contents != ''
      message = MhcKconv::tomail(header + contents)
!     Net::SMTPSession .start(smtpServer, 25, MyHostName, smtp_account, smtp_passwd, smtp_type) {|server|
!       server .sendmail(message, from_addr, to_addr)
      }
    end
  else