#!/usr/bin/perl # 漢字コード:EUC # ===================================================================== # webpop3.pl for perl(ver.4 and later) Written by T.Hamano 1999 # 更新履歴 # 1999-04-16 Ver. 1.02.00 指定した全サーバに一度にアクセスする機能付加 # 1999-04-14 Ver. 1.01.00 HTML 化 # 1999-03-22 Ver. 1.00.00 Created # --------------------------------------------------------------------- ##改変・・・なかにし 2009/11/27 blog.hachikobrass.com require '/virtual/YOUR-ID/public_html/このプログラムを設置したフォルダ/mailsubs.cgi'; require '/virtual/YOUR-ID/public_html/このプログラムを設置したフォルダ/cgisubs.cgi'; require '/virtual/YOUR-ID/public_html/このプログラムを設置したフォルダ/jcode.pl'; # sendmailへのパス $sendmail = '/usr/sbin/sendmail'; #メール関係 $sflag=1; $host='sXXX.xrea.com'; $mailID='XREAのメールアドレス'; $mailPass='XREAのメールパスワード'; # 広域定数の設定 $script = $ENV{'SCRIPT_NAME'}; # このスクリプトのURL $referer = $ENV{'HTTP_REFERER'}; # このスクリプトの呼出元 $base = (&splitFileName($script))[1]; # 基本ファイル名 $title1 = 'WebPOP3'; $title2 = 'ウェブPOP3'; $homeURL = "http://YOUR-ID.sXXX.xrea.com/このプログラムを設置したフォルダ"; $backColor="bgcolor=\"silver\""; # 背景色 # HTML Header Footer $html_header =<<_Header_; Content-type: text/html
メール・・・$log[0]
\n"; if ($log[0] =~ /^OK, (\d+) mail/) { local(@head, @msg, $idx, $idx1, $idx2, $mess); for ($idx = 1; $idx <= $1; $idx++) { $idx1 = &listIndex("^RETR $idx", @log); $idx2 = &listIndex("[\\-]+\\( END_OF_MAIL_$idx \\)[\\-]+", @log); @msg = splice(@log, $idx1+2, $idx2-$idx1-2); $idx1 = &listIndex('^$', @msg); @head = splice(@msg, 0, $idx1); # 受信メッセージのヘッダ情報取得 $subfla=0; foreach (@head) { chop; s/=\?.+\?B\?(.+)\?=/&decodeBase64($1)/ge; &jcode'jis2euc(*_); s/</g; s/>/>/g; s/"/"/g; #print "test| $_\n"; if (/^To: /) {$to = substr($_, 4);} elsif (/^From: /) {$from = substr($_, 6); $subfla=0;} elsif (/^Date: /) { $date = substr($_, 6); $date = &numeral_date($date); } elsif (/^Subject: /) { $subj = substr($_, 9); $subfla = 1; } elsif ($subfla) { $subj = $subj . substr($_,1); } } #end of foreach loop #通知メールのタイトルの末尾に(カレンダーの名前)が表示されるのでそれをトリムする。 #カレンダーのバイト数:全角2バイト、半角1バイトで換算して、 #calname = バイト数+9 でたぶんぴったり・・・ここらへんは試行錯誤してください。 $calname=21 $subject = substr($subj,6,length($subj)-$calname); ($yotei, $dat) = split( /@/ , $subject ); $ldat = length($dat); #($sty,$stm,$std,$stt,$tp,$edy,$edm,$edd,$edt) = split( /// , $dat ); $dayformat = 0; if ($ldat == 37){ #2009/11/27 14:05 〜 2009/11/28 15:05 --37 $dayformat = 1; ($sty,$stm,$std,$edm,$edd) = split( /\// , $dat ); ($std,$stt,$tp,$edy) = split( / / , $std ); ($edd,$edt) = split( / / , $edd ); $stweek = &GetWeekDay($sty, $stm, $std, 1); $edweek = &GetWeekDay($edy, $edm, $edd, 1); } elsif ($ldat == 26){ #2009/11/27 12:26 〜 13:26 --26 $dayformat = 2; ($sty,$stm,$std) = split( /\// , $dat ); ($std,$stt,$tp,$edt) = split( / / , $std ); $stweek = &GetWeekDay($sty, $stm, $std, 1); } elsif ($ldat == 25){ #2009/11/26 〜 2009/11/27 --25 $dayformat = 3; ($sty,$stm,$std,$edm,$edd) = split( /\// , $dat ); ($std,$tp,$edy) = split( / / , $std ); $stweek = &GetWeekDay($sty, $stm, $std, 1); $edweek = &GetWeekDay($edy, $edm, $edd, 1); } elsif ($ldat == 11){ #2009/11/27 --11 $dayformat = 4; ($sty,$stm,$std) = split( /\// , $dat ); $stweek = &GetWeekDay($sty, $stm, $std, 1); } if ($from =~ /calendar-notification/) { if($dayformat == 1){ $twit = "$sty/$stm/$std($stweek) $stt $tp $edy/$edm/$edd($edweek) $edt"; } elsif($dayformat == 2){ $twit = "$sty/$stm/$std($stweek) $stt $tp $edt"; } elsif($dayformat == 3){ $twit = "$sty/$stm/$std($stweek) $tp $edy/$edm/$edd($edweek)"; } elsif($dayformat == 4){ $twit = "$sty/$stm/$std($stweek)"; } print "No.$idx: $twit $yotei
\n"; &send_twit; } #end of if } #end of for } #end of if } exit; sub send_twit{ $mail_body = ""; $mail_body .= "つ\n$twit $yotei"; $mail_body =~ s/\x0D\x0A|\x0D|\x0A/\n/g; $mail_body =~ s/(\n)\.(\n)/\1\.\.\2/g; $subject = ''; &jcode'convert(*mail_body,'jis'); open(MAIL,"| $sendmail -t") || print "sendmailの起動に失敗しました。"; $mail = 'ついぴーねの投稿メールアドレス'; $from = 'XREAのメールアドレス'; #$cc = '任意のCC(使いたいなら、print MAIL "Cc〜の行もコメントはずしてください。)'; print MAIL "To: $mail \n"; #print MAIL "Cc: $cc\n"; print MAIL "From: $from\n"; print MAIL "MIME-Version: 1.0\n"; print MAIL "Content-type: text/plain; charset=ISO-2022-JP\n"; print MAIL "Content-Transfer-Encoding: 7bit\n"; print MAIL "Subject: $subject\n\n"; print MAIL "$mail_body\n"; close(MAIL) || print "メールの送信に失敗しました。"; } sub GetWeekDay { my($year, $mon, $day, $flag) = @_; if($year == 1582) { if($mon < 10) { return -1; } elsif($mon == 10) { if($day < 15) { return -1; } } } elsif($year < 1582) { return -1; } if($mon == 1 || $mon == 2) { $year --; $mon += 12; } my $week = ($year + int($year/4) - int($year/100) + int($year/400) + int((13*$mon+8)/5) + $day) % 7; if($flag) { my @map = ('日', '月', '火', '水', '木', '金', '土'); return $map[$week]; } else { return $week; } } sub numeral_date { local($week, $temp) = split(/\,/, $_[0]); local($dummy, $day, $mon_, $year, $time, $offset, $country) = split(/ /, $temp); local($mon) = (index("Jan Feb Mar Apr May Jun Jul Aug Sep Nov Oct Dec ", $mon_) / 4) +2; return sprintf("%04d/%02d/%02d",$year,$mon,$day) . "[$time]"; # return sprintf("%04d/%02d/%02d",$year,$mon,$day) . "($week) $time $offset $country"; } sub error { print "$_[0]
\n"; exit; } # End of Script --