.\" -*- mode: troff; coding: utf-8 -*- .\" Automatically generated by Pod::Man 5.01 (Pod::Simple 3.43) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>. .ie n \{\ . ds C` "" . ds C' "" 'br\} .el\{\ . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "Sisimai::Message 3pm" .TH Sisimai::Message 3pm 2024-03-16 "perl v5.38.2" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH NAME Sisimai::Message \- Convert bounce email text to data structure. .SH SYNOPSIS .IX Header "SYNOPSIS" .Vb 2 \& use Sisimai::Mail; \& use Sisimai::Message; \& \& my $mailbox = Sisimai::Mail\->new(\*(Aq/var/mail/root\*(Aq); \& while( my $r = $mailbox\->read ) { \& my $p = Sisimai::Message\->rise(\*(Aqdata\*(Aq => $r); \& } \& \& my $notmail = \*(Aq/home/neko/Maildir/cur/22222\*(Aq; # is not a bounce email \& my $mailobj = Sisimai::Mail\->new($notmail); \& while( my $r = $mailobj\->read ) { \& my $p = Sisimai::Message\->rise(\*(Aqdata\*(Aq => $r); # $p is "undef" \& } .Ve .SH DESCRIPTION .IX Header "DESCRIPTION" Sisimai::Message convert bounce email text to data structure. It resolve email text into an UNIX From line, the header part of the mail, delivery status, and RFC822 header part. When the email given as a argument of "new" method is not a bounce email, the method returns "undef". .SH "CLASS METHODS" .IX Header "CLASS METHODS" .ie n .SS """\fBrise(Hash reference)\fP""" .el .SS "\f(CW\fP\f(CBrise(Hash reference)\fP\f(CW\fP" .IX Subsection "rise(Hash reference)" \&\f(CWrise()\fR is a constructor of Sisimai::Message .PP .Vb 2 \& my $mailtxt = \*(AqEntire email text\*(Aq; \& my $message = Sisimai::Message\->rise(\*(Aqdata\*(Aq => $mailtxt); .Ve .PP If you have implemented a custom MTA module and use it, set the value of "load" in the argument of this method as an array reference like following code: .PP .Vb 4 \& my $message = Sisimai::Message\->rise( \& \*(Aqdata\*(Aq => $mailtxt, \& \*(Aqload\*(Aq => [\*(AqYour::Custom::MTA::Module\*(Aq] \& ); .Ve .PP Beginning from v4.19.0, \f(CW\*(C`hook\*(C'\fR argument is available to callback user defined method like the following codes: .PP .Vb 7 \& my $cmethod = sub { \& my $argv = shift; \& my $data = { \& \*(Aqqueue\-id\*(Aq => \*(Aq\*(Aq, \& \*(Aqx\-mailer\*(Aq => \*(Aq\*(Aq, \& \*(Aqprecedence\*(Aq => \*(Aq\*(Aq, \& }; \& \& # Header part of the bounced mail \& for my $e ( \*(Aqx\-mailer\*(Aq, \*(Aqprecedence\*(Aq ) { \& next unless exists $argv\->{\*(Aqheaders\*(Aq}\->{ $e }; \& $data\->{ $e } = $argv\->{\*(Aqheaders\*(Aq}\->{ $e }; \& } \& \& # Message body of the bounced email \& if( $argv\->{\*(Aqmessage\*(Aq} =~ /^X\-Postfix\-Queue\-ID:\es*(.+)$/m ) { \& $data\->{\*(Aqqueue\-id\*(Aq} = $1; \& } \& \& return $data; \& }; \& \& my $message = Sisimai::Message\->rise( \& \*(Aqdata\*(Aq => $mailtxt, \& \*(Aqhook\*(Aq => $cmethod, \& ); \& print $message\->catch\->{\*(Aqx\-mailer\*(Aq}; # Apple Mail (2.1283) \& print $message\->catch\->{\*(Aqqueue\-id\*(Aq}; # 2DAEB222022E \& print $message\->catch\->{\*(Aqprecedence\*(Aq}; # bulk .Ve .SH "INSTANCE METHODS" .IX Header "INSTANCE METHODS" .ie n .SS """\fB(from)\fP""" .el .SS \f(CW\fP\f(CB(from)\fP\f(CW\fP .IX Subsection "(from)" \&\f(CWfrom()\fR returns the UNIX From line of the email. .PP .Vb 1 \& print $message\->from; .Ve .ie n .SS """\fBheader()\fP""" .el .SS \f(CW\fP\f(CBheader()\fP\f(CW\fP .IX Subsection "header()" \&\f(CWheader()\fR returns the header part of the email. .PP .Vb 1 \& print $message\->header\->{\*(Aqsubject\*(Aq}; # Returned mail: see transcript for details .Ve .ie n .SS """\fBds()\fP""" .el .SS \f(CW\fP\f(CBds()\fP\f(CW\fP .IX Subsection "ds()" \&\f(CWds()\fR returns an array reference which include contents of delivery status. .PP .Vb 4 \& for my $e ( $message\->ds\->@* ) { \& print $e\->{\*(Aqstatus\*(Aq}; # 5.1.1 \& print $e\->{\*(Aqrecipient\*(Aq};# neko@example.jp \& } .Ve .ie n .SS """\fBrfc822()\fP""" .el .SS \f(CW\fP\f(CBrfc822()\fP\f(CW\fP .IX Subsection "rfc822()" \&\f(CWrfc822()\fR returns a hash reference which include the header part of the original message. .PP .Vb 2 \& print $message\->rfc822\->{\*(Aqfrom\*(Aq}; # cat@example.com \& print $message\->rfc822\->{\*(Aqto\*(Aq}; # neko@example.jp .Ve .ie n .SS """\fBcatch()\fP""" .el .SS \f(CW\fP\f(CBcatch()\fP\f(CW\fP .IX Subsection "catch()" \&\f(CWcatch()\fR returns any data generated by user-defined method passed at the `hook` argument of \fBnew()\fR constructor. .SH AUTHOR .IX Header "AUTHOR" azumakuniyuki .SH COPYRIGHT .IX Header "COPYRIGHT" Copyright (C) 2014\-2024 azumakuniyuki, All rights reserved. .SH LICENSE .IX Header "LICENSE" This software is distributed under The BSD 2\-Clause License.