Problems saving some email attachments
| From: | C.F. Scheidecker Antunes | Date: | Fri, 16 Jul 2004 01:44:16 +0000 |
| Subject: | Problems saving some email attachments | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-190666@lists.php.net to get a copy of this message | ||
Hello all,
This is part of a code to save the attachments of an email message that I am trying to figure out.
Maybe someone can help me figuring this one out. The code is bellow. I am also including part of the emails source codes. One is not multi-part and does not work, while the second is a
multi-part one and does work.
If I have a multi-part email body I can parse it and save it easily with the code bellow, however if the message has a different body structure, not
being a multipart but something like this:
This does not work:
From: <myself@myself.com>
To: =<myself@myself.com>
Subject: =Test
Date: Thu, 15 Jul 2004 14:22:06 -0300
Message-ID: <LAEMILFJMPAANDEKJPABOEIBCMAA.info@myself.com>
MIME-Version: 1.0
Content-Type: application/x-zip-compressed;
name="nto.zip"
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
filename="nto.zip"
X-Priority: 3 (Normal)
X-MSMail-Priority: Normal
X-Mailer: Microsoft Outlook IMO, Build 9.0.2416 (9.0.2910.0)
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1409
Importance: Normal
X-yoursite-MailScanner-Information: Please contact the ISP for more information
X-yoursite-MailScanner: Found to be clean
X-yoursite-MailScanner-SpamCheck: not spam, SpamAssassin (score=-4.9,
required 6, autolearn=not spam, BAYES_00 -4.90)
X-MailScanner-From: myself@myself.com
Status: O
X-UID: 35476
Content-Length: 67371
X-Keywords:UEsDBBQAAAAIABZx7zB9XrH1WMIAAEqjBgAKAAAAUEZPMTEzLlRYVMydzXLjOtKm9xMx98Doxcyi +9j4J7maoChKpkuW1JTs4zrXfyNDQLKYkBK0kcmK+LyqRemJxA+BRCLzxeYwrAvsT6pWPr/6f4nx z4jr35OUxUe3a4p+u+/b5vC//1eSoFT7+lxcCFKpG0GUEeHxhzPMzbYqv5hCyhvTqGLT784DQvuO OZq5MTfmzczRzirYeSoozM3b5tl99Z67MfW190jM4/HteeOuzKnt2pKZOmWnMeS2awOZspyYVzvX Then I cannot parse it with the code bellow. The following type of message body does work though. The code bellow only works with a message in this format: Message-ID: <000501c46ab5$2f978320$6700a8c0@myself.com> From: "Me" <me@myself.com> To: "You" <myself@myself.com> Subject: estoque Date: Thu, 15 Jul 2004 18:46:26 -0300 MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----=_NextPart_000_0001_01C46A9C.08A6AD40" X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2800.1409 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1409 X-Virus-Scanned: by MAV X-Mav-Antispam: pontos X-yoursite-MailScanner-Information: Please contact the ISP for more information X-yoursite-MailScanner: Found to be clean X-yoursite-MailScanner-SpamCheck: not spam, SpamAssassin (score=1.034, required 6, BAYES_30 -0.90, HTML_MESSAGE 0.10, MIME_MISSING_BOUNDARY 1.84) X-yoursite-MailScanner-SpamScore: 1 X-MailScanner-From: me@myself.com X-IMAPbase: 1086548203 35629 Status: O X-UID: 35629 Content-Length: 147519
X-Keywords:This is a multi-part message in MIME format. ------=_NextPart_000_0001_01C46A9C.08A6AD40 Content-Type: multipart/alternative; boundary="----=_NextPart_001_0002_01C46A9C.08AFD500" ------=_NextPart_001_0002_01C46A9C.08AFD500 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable ------=_NextPart_001_0002_01C46A9C.08AFD500 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML><HEAD> <META http-equiv=3DContent-Type content=3D"text/html; = charset=3Diso-8859-1"> <META content=3D"MSHTML 6.00.2800.1400" name=3DGENERATOR> <STYLE></STYLE> </HEAD> <BODY bgColor=3D#ffffff> <DIV> </DIV></BODY></HTML> ------=_NextPart_001_0002_01C46A9C.08AFD500-- ------=_NextPart_000_0001_01C46A9C.08A6AD40 Content-Type: application/x-zip-compressed; name="not.zip" Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename="not.zip" UEsDBBQAAgAIAOSU7zCWW3IuFacBALfKBwAKAAAAcHYwNzU3LnR4dKSd23LjtrJA389X8O2kUhwL DTRuj5RMe5RIlkPJ3jr5/w85ACWL3U0CtGvPruyaVLwGt743wGmaptmkf5qtUnrT3X7fqPxLO/X1 C7C14eXwsX8+Nc998zL0+1Ojnuz/NHcclfJ6owzBFdxhnX7bevx7f2neh9Px5XRtdhMIaGHj1QME xX61gOf+cGq65/68/zw1Q/+5P3cnwjvFeGU5r/zLaTg+pZFfn7rP7rDvdhyPnuF0Bqhb4w5p3tvT The contentParts for the first message is zero, while for the second (the multipart) it has more than 2. Code for Multipart parsing: $struct = imap_fetchstructure($mbox,$msgno); $contentParts = count($struct->parts);
show_msg("\tContentParts $contentParts \n",$debug);
if ($contentParts >= 2) {
for ($i = 2; $i <= $contentParts; $i++) {
$att[$i-2] = imap_bodystruct($mbox,$msgno,$i);
}
for ($k = 0; $k < sizeof($att); $k++) {
if (strtolower($att[$k]->parameters[0]->value) == "us-ascii") {
if ($att[$k]->parameters[1]->value != "") {
$filenames[$k] = $att[$k]->parameters[1]->value);
}
}
else if (strtolower($att[$k]->parameters[0]->value) != "iso-8859-1") {
if ($att[$k]->parameters[0]->value != "") {
$filenames[$k] = $att[$k]->parameters[0]->value);
}
if ($att[$k]->parameters[1]->value != "") {
$filenames[$k] = $att[$k]->parameters[1]->value);
}
}
else if (strtolower($att[$k]->parameters[0]->value) == "iso-8859-1") {
if ($att[$k]->parameters[0]->value != "") {
$filenames[$k] = $att[$k]->parameters[0]->value);
}
if ($att[$k]->parameters[1]->value != "") {
$aux = corrigir_filename1($att[$k]->parameters[1]->value);
$filenames[$k] = $att[$k]->parameters[1]->value);
}
}
} // for ($k = 0;
if (sizeof($filenames) > 0) {
for ($j = 0; $j < sizeof($filenames); $j++) {
show_msg("\t\t".$filenames[$j]."\n",$debug);
$fname = corrigir_filename1(strtolower($att[$j]->parameters[0]->value));
$filetype = strrev(substr(strrev($fname),0,4));
$filecontent = imap_fetchbody($mbox,$msgno,$j+2);
downloadfile($filetype,$fname,$filecontent);
}
}
An input is much appreciated.
Thanks in advance.