new(pattern => '%a, %d %b %Y %H:%M:%S %z', on_error => 'croak' ); $dt = $strp->parse_datetime($hdate); $date = DateTime::Format::MySQL->format_datetime($dt); $addr = $addr || $mib->{'_address'}; $addr = &main::LowerDomain($addr); $ml = $mib->{'_ml_acct'}; &main::Log("$mib->{'_action'} $addr"); $body = $e->{'Body'}; $subject = $e->{'h:Subject:'}; $res = $dbh->prepare("insert into article values (?, ?, ?, ?,?)"); $res->execute($mib->{'_article_id'}, $body, $addr, $subject,$date); if ($mib->{'error'}) { return $NULL;} } " />

itoigawabass

itoigawaのブログ

メールをデータベースに

2015-06-01

fmlをmysqlと連動させるのところで日付処理ができていなかった。
今日のメール日付でMon, 1 Jun 2015 16:23:44 +0900 (JST)
日付1の前に空白が2つあるのでエラーになっていた

#メールをmysqlに書き込む
sub store_article
{
    my ($mib, $e) = @_;
    my ($subject,$body,$date,$hdate);
    my ($ml, $query, $res,$dt);
    $hdate = $e->{'h:Date:'};
#次の正規表現で対応
  $hdate =~ s/(\s)\1{1}/ /;
    $hdate =~ s/ (JST) //;
    $date = " ";
    use DateTime::Format::Strptime;
    use DateTime::Format::MySQL;
    my $strp = DateTime::Format::Strptime->new(pattern => '%a, %d %b %Y %H:%M:%S %z', on_error => 'croak' );
    $dt = $strp->parse_datetime($hdate);
    
    $date = DateTime::Format::MySQL->format_datetime($dt);
    $addr = $addr || $mib->{'_address'};
    $addr = &main::LowerDomain($addr);
    $ml   = $mib->{'_ml_acct'};

    &main::Log("$mib->{'_action'} $addr");
    $body = $e->{'Body'};
    $subject = $e->{'h:Subject:'};
    $res = $dbh->prepare("insert into article values (?, ?, ?, ?,?)");
    $res->execute($mib->{'_article_id'}, $body, $addr, $subject,$date);
    if ($mib->{'error'}) { return $NULL;}

}

カテゴリー:サーバー
タグ: