Perl-users.jp

メールのパーズ

受信したメールをパーズするのには Email::MIME をつかいます。

つかいかた

use strict;
use warnings;
use utf8;
use Email::MIME;
use Email::Address;
use Email::Address::Loose -override; # ドコモの RFC 違反なメアド対策

my $src = <<'...';
Delivered-To: john@example.com
Return-Path: <tom@example.com>
Date: Wed, 04 Feb 2009 20:06:30 -0700
Sender: <tom@example.com>
From: Tom <tom@example.com>
Subject: Hi, john
To: <john@example.com>
Content-Type: text/plain;
    charset="iso-8859-2"
Content-Transfer-Encoding: 8bit

how are you?
...

my $mail = Email::MIME->new($src);
print "Subject -> @{[ $mail->header('Subject') ]}\n";
print "Body -> @{[ $mail->body ]}\n";

ごく簡単です。


目次へ

Last modified: $Date: 2008-05-22T09:21:23.154313Z $