Skip to content

Instantly share code, notes, and snippets.

@matoken matoken/ml2lingr.pl
Last active Aug 29, 2015

Embed
What would you like to do?
#!/usr/bin/perl
use strict;
use warnings;
use Encode;
use Email::MIME;
use Email::MIME::ContentType;
use LWP::Simple;
my $ROOM = 'kagolug';
my $BOT_NAME = 'KagolugML_bot';
my $BOT_VERIFIER = 'b3c03556dca8dfffb8c509cb709817044c98ad87';
my @month = ( 'January',
'February',
'March',
'April',
'May',
'June',
'July',
'August',
'September',
'October',
'November',
'December'
);
my ($second, $minute, $hour, $mday, $mon, $year) = localtime;
$year += 1900;
my $mail='';
while(my $line=<STDIN>){
$mail .= $line;
}
my $parsed = Email::MIME->new($mail);
my $Subject = encode( 'utf8', $parsed->header('Subject') ) . "\n";
my $ListArchive = $parsed->header('List-Archive');
$ListArchive =~s/[<|>]//g;
my $msgid = $Subject;
$msgid =~s/^.+?://;
print "msgid : $msgid\n";
$msgid =~s/\].*?$//;
$msgid -= 1;
$msgid = sprintf "%06d", $msgid;
$ListArchive = "$ListArchive$year-$month[$mon]/$msgid.html";
my $url = "http://lingr.com/api/room/say?room=$ROOM&bot=$BOT_NAME&text=$Subject$ListArchive&bot_verifier=$BOT_VERIFIER";
print get("$url");
@matoken

This comment has been minimized.

Copy link
Owner Author

commented Jul 1, 2014

@matoken

This comment has been minimized.

Copy link
Owner Author

commented Jul 1, 2014

Revisions 3
Archive へのURL も投稿するように修正

@matoken

This comment has been minimized.

Copy link
Owner Author

commented Jul 2, 2014

月跨ぎのメールはもしかしたら間違ったURL生成するかも

mailmanのURL を生成する月とこのScriptが動く月にズレがあったら間違ったURLが生成される.
回避するには月またぎに近かったらURL2つ作ってアクセスできる方を採用とかしないといけ無さそう.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.