$read = trim(substr ($bodystructure, strpos(strtolower($bodystructure), 'bodystructure') + 13));
$msg = &new message();
$read = trim(substr ($read, 0, -1));
- $msg = $msg->parseStructure($read,0);
+ $res = $msg->parseStructure($read);
+ $msg = $res[0];
$msg->setEnt('0');
if (count($flags)) {
foreach ($flags as $flag) {
$sid_s = $sid;
}
+ $body = mime_fetch_body ($imap_stream, $id, $ent_id);
+ echo decodeBody($body, $encoding);
+ return;
+/*
fputs ($imap_stream, "$sid FETCH $id BODY[$ent_id]\r\n");
$cnt = 0;
$continue = true;
// This could be bad -- if the section has sqimap_session_id() . ' OK'
// or similar, it will kill the download.
while (!ereg("^".$sid_s." (OK|BAD|NO)(.*)$", $read, $regs)) {
- if (trim($read) == ')==') {
- $read1 = $read;
- $read = fgets ($imap_stream,4096);
- if (ereg("^".$sid." (OK|BAD|NO)(.*)$", $read, $regs)) {
- return;
- } else {
- echo decodeBody($read1, $encoding) .
- decodeBody($read, $encoding);
- }
- } else if ($cnt) {
- echo decodeBody($read, $encoding);
- }
- $read = fgets ($imap_stream,4096);
- $cnt++;
+ if (trim($read) == ')==') {
+ $read1 = $read;
+ $read = fgets ($imap_stream,4096);
+ if (ereg("^".$sid." (OK|BAD|NO)(.*)$", $read, $regs)) {
+ return;
+ } else {
+ echo decodeBody($read1, $encoding) .
+ decodeBody($read, $encoding);
+ }
+ } else if ($cnt) {
+ echo decodeBody($read, $encoding);
+ }
+ $read = fgets ($imap_stream,4096);
+ $cnt++;
// break;
}
+*/
}
/* -[ END MIME DECODING ]----------------------------------------------------------- */
$att_ar = $message->getAttachments($exclude_id);
if (!count($att_ar)) return '';
-
+
$attachments = '';
-
+
$urlMailbox = urlencode($mailbox);
foreach ($att_ar as $att) {
-
$ent = urldecode($att->entity_id);
- $header = $att->header;
+ $header = $att->header;
$type0 = strtolower($header->type0);
$type1 = strtolower($header->type1);
- $name = '';
- if ($type0 =='message' && $type1 == 'rfc822') {
- $rfc822_header = $att->rfc822_header;
+ $name = '';
+ $Links['download link']['text'] = _("download");
+ $Links['download link']['href'] =
+ "../src/download.php?absolute_dl=true&passed_id=$id&mailbox=$urlMailbox&ent_id=$ent";
+ $ImageURL = '';
+ if ($type0 =='message' && $type1 == 'rfc822') {
+ $default_page = '../src/read_body.php';
+ $rfc822_header = $att->rfc822_header;
$filename = decodeHeader($rfc822_header->subject);
- $display_filename = $filename;
-
- $DefaultLink =
- "../src/read_body.php?startMessage=$startMessage&passed_id=$id&mailbox=$urlMailbox&passed_ent_id=$ent";
- if ($where && $what) {
- $DefaultLink .= '&where=' . urlencode($where) . '&what=' . urlencode($what);
- }
- $Links['download link']['text'] = _("download");
- $Links['download link']['href'] =
- "../src/download.php?absolute_dl=true&passed_id=$id&mailbox=$urlMailbox&passed_ent_id=$ent";
- $ImageURL = '';
-
- /* this executes the attachment hook with a specific MIME-type.
- * if that doens't have results, it tries if there's a rule
- * for a more generic type. */
- $HookResults = do_hook("attachment $type0/$type1", $Links,
- $startMessage, $id, $urlMailbox, $ent, $DefaultLink, $display_filename, $where, $what);
- if(count($HookResults[1]) <= 1) {
- $HookResults = do_hook("attachment $type0/*", $Links,
- $startMessage, $id, $urlMailbox, $ent, $DefaultLink,
- $display_filename, $where, $what);
- }
-
- $Links = $HookResults[1];
- $DefaultLink = $HookResults[6];
- $attachments .= '<TR><TD>' .
- "<A HREF=\"$DefaultLink\">$display_filename</A> </TD>" .
- '<TD><SMALL><b>' . show_readable_size($header->size) .
- '</b> </small></TD>' .
- "<TD><SMALL>[ $type0/$type1 ] </SMALL></TD>" .
- '<TD><SMALL>';
- $from_o = $rfc822_header->from;
- if (is_object($from_o)) {
- $from_name = $from_o->getAddress(false);
- } else {
- $from_name = _("Unknown sender");
- }
- $from_name = decodeHeader(htmlspecialchars($from_name));
- $attachments .= '<b>' . $from_name . '</b>';
- $attachments .= '</SMALL></TD><TD><SMALL> ';
-
- $SkipSpaces = 1;
- foreach ($Links as $Val) {
- if ($SkipSpaces) {
- $SkipSpaces = 0;
- } else {
- $attachments .= ' | ';
- }
- $attachments .= '<a href="' . $Val['href'] . '">' . $Val['text'] . '</a>';
+ $from_o = $rfc822_header->from;
+ if (is_object($from_o)) {
+ $from_name = $from_o->getAddress(false);
+ } else {
+ $from_name = _("Unknown sender");
}
- unset($Links);
- $attachments .= "</TD></TR>\n";
+ $from_name = decodeHeader(htmlspecialchars($from_name));
+ $description = $from_name;
} else {
- $filename = decodeHeader($header->getParameter('filename'));
- if (trim($filename) == '') {
- $name = decodeHeader($header->getParameter('name'));
- if (trim($name) == '') {
- if ( trim( $header->id ) == '' )
- $display_filename = 'untitled-[' . $ent . ']' ;
- else
- $display_filename = 'cid: ' . $header->id;
- } else {
- $display_filename = $name;
- $filename = $name;
- }
+ $default_page = '../src/download.php';
+ if (is_object($header->disposition)) {
+ $filename = decodeHeader($header->disposition->getProperty('filename'));
+ if (trim($filename) == '') {
+ $name = decodeHeader($header->disposition->getProperty('name'));
+ if (trim($name) == '') {
+ if ( trim( $header->id ) == '' )
+ $filename = 'untitled-[' . $ent . ']' ;
+ else
+ $filename = 'cid: ' . $header->id;
+ } else {
+ $filename = $name;
+ }
+ }
+ } else {
+ if ( trim( $header->id ) == '' )
+ $filename = 'untitled-[' . $ent . ']' ;
+ else
+ $filename = 'cid: ' . $header->id;
+ }
+
+ if ($header->description) {
+ $description = htmlspecialchars($header->description);
} else {
- $display_filename = $filename;
- }
+ $description = '';
+ }
+ }
- $DefaultLink =
- "../src/download.php?startMessage=$startMessage&passed_id=$id&mailbox=$urlMailbox&passed_ent_id=$ent";
- if ($where && $what) {
- $DefaultLink = '&where='. urlencode($where).'&what='.urlencode($what);
- }
- $Links['download link']['text'] = _("download");
- $Links['download link']['href'] =
- "../src/download.php?absolute_dl=true&passed_id=$id&mailbox=$urlMailbox&passed_ent_id=$ent";
- $ImageURL = '';
-
- /* this executes the attachment hook with a specific MIME-type.
- * if that doens't have results, it tries if there's a rule
- * for a more generic type. */
- $HookResults = do_hook("attachment $type0/$type1", $Links,
- $startMessage, $id, $urlMailbox, $ent, $DefaultLink,
- $display_filename, $where, $what);
- if(count($HookResults[1]) <= 1) {
- $HookResults = do_hook("attachment $type0/*", $Links,
- $startMessage, $id, $urlMailbox, $ent, $DefaultLink,
- $display_filename, $where, $what);
- }
+ $display_filename = $filename;
+ if (isset($passed_ent_id)) {
+ $passed_ent_id_link = '&passed_ent_id='.$passed_ent_id;
+ } else {
+ $passed_ent_id_link = '';
+ }
+ $DefaultLink = $default_page . "?startMessage=$startMessage"
+ . "&passed_id=$id&mailbox=$urlMailbox"
+ . '&ent_id='.$ent.$passed_ent_id_link;
+ if ($where && $what) {
+ $DefaultLink = '&where='. urlencode($where).'&what='.urlencode($what);
+ }
+ /* this executes the attachment hook with a specific MIME-type.
+ * if that doens't have results, it tries if there's a rule
+ * for a more generic type. */
+ $HookResults = do_hook("attachment $type0/$type1", $Links,
+ $startMessage, $id, $urlMailbox, $ent, $DefaultLink,
+ $display_filename, $where, $what);
+ if(count($HookResults[1]) <= 1) {
+ $HookResults = do_hook("attachment $type0/*", $Links,
+ $startMessage, $id, $urlMailbox, $ent, $DefaultLink,
+ $display_filename, $where, $what);
+ }
- $Links = $HookResults[1];
- $DefaultLink = $HookResults[6];
+ $Links = $HookResults[1];
+ $DefaultLink = $HookResults[6];
- $attachments .= '<TR><TD>' .
+ $attachments .= '<TR><TD>' .
"<A HREF=\"$DefaultLink\">$display_filename</A> </TD>" .
'<TD><SMALL><b>' . show_readable_size($header->size) .
'</b> </small></TD>' .
"<TD><SMALL>[ $type0/$type1 ] </SMALL></TD>" .
'<TD><SMALL>';
- if ($message->header->description) {
- $attachments .= '<b>' . htmlspecialchars(_($header->description)) . '</b>';
- }
- $attachments .= '</SMALL></TD><TD><SMALL> ';
+ $attachments .= '<b>' . $description . '</b>';
+ $attachments .= '</SMALL></TD><TD><SMALL> ';
- $SkipSpaces = 1;
- foreach ($Links as $Val) {
- if ($SkipSpaces) {
- $SkipSpaces = 0;
- } else {
- $attachments .= ' | ';
- }
- $attachments .= '<a href="' . $Val['href'] . '">' . $Val['text'] . '</a>';
+ $SkipSpaces = 1;
+ foreach ($Links as $Val) {
+ if ($SkipSpaces) {
+ $SkipSpaces = 0;
+ } else {
+ $attachments .= ' | ';
}
- $attachments .= "</TD></TR>\n";
- unset($Links);
- }
-
- }
-
- return $attachments;
+ $attachments .= '<a href="' . $Val['href'] . '">' . $Val['text'] . '</a>';
+ }
+ unset($Links);
+ $attachments .= "</TD></TR>\n";
+ }
+ return $attachments;
}
/** this function decodes the body depending on the encoding type. **/
return $trusted;
}
-?>
\ No newline at end of file
+?>