From 2e25760a6a131103fb36d9cc262f984c2d745419 Mon Sep 17 00:00:00 2001 From: indiri69 Date: Fri, 16 Aug 2002 21:44:35 +0000 Subject: [PATCH] Removed a bunch of redundant code in formatAttachments. git-svn-id: https://svn.code.sf.net/p/squirrelmail/code/trunk/squirrelmail@3342 7612ce4b-ef26-0410-bec9-ea0150e637f0 --- functions/mime.php | 167 ++++++++++++++++----------------------------- 1 file changed, 60 insertions(+), 107 deletions(-) diff --git a/functions/mime.php b/functions/mime.php index 72dc3cde..c91ea398 100644 --- a/functions/mime.php +++ b/functions/mime.php @@ -380,143 +380,96 @@ function formatAttachments($message, $exclude_id, $mailbox, $id) { $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; - $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'] = + $name = ''; + $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]; + $ImageURL = ''; + if ($type0 =='message' && $type1 == 'rfc822') { + $default_page = '../src/read_body.php'; + $rfc822_header = $att->rfc822_header; + $filename = decodeHeader($rfc822_header->subject); - $attachments .= '' . - "$display_filename " . - '' . show_readable_size($header->size) . - '  ' . - "[ $type0/$type1 ] " . - ''; - $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 .= '' . $from_name . ''; - $attachments .= ' '; - - $SkipSpaces = 1; - foreach ($Links as $Val) { - if ($SkipSpaces) { - $SkipSpaces = 0; - } else { - $attachments .= '  |  '; - } - $attachments .= '' . $Val['text'] . ''; + $from_o = $rfc822_header->from; + if (is_object($from_o)) { + $from_name = $from_o->getAddress(false); + } else { + $from_name = _("Unknown sender"); } - unset($Links); - $attachments .= "\n"; + $from_name = decodeHeader(htmlspecialchars($from_name)); } else { + $default_page = '../src/download.php'; $filename = decodeHeader($header->getParameter('filename')); if (trim($filename) == '') { - $name = decodeHeader($header->getParameter('name')); + $name = decodeHeader($header->getParameter('name')); if (trim($name) == '') { if ( trim( $header->id ) == '' ) - $display_filename = 'untitled-[' . $ent . ']' ; + $filename = 'untitled-[' . $ent . ']' ; else - $display_filename = 'cid: ' . $header->id; + $filename = 'cid: ' . $header->id; } else { - $display_filename = $name; $filename = $name; } - } else { - $display_filename = $filename; - } - - $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); + if ($message->header->description) { + $from_name = htmlspecialchars(_($header->description)); } + } + + $display_filename = $filename; + $DefaultLink = $default_page . "?startMessage=$startMessage" + . "&passed_id=$id&mailbox=$urlMailbox" + . "&passed_ent_id=$ent"; + 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 .= '' . + $attachments .= '' . "$display_filename " . '' . show_readable_size($header->size) . '  ' . "[ $type0/$type1 ] " . ''; - if ($message->header->description) { - $attachments .= '' . htmlspecialchars(_($header->description)) . ''; - } - $attachments .= ' '; + $attachments .= '' . $from_name . ''; + $attachments .= ' '; - $SkipSpaces = 1; - foreach ($Links as $Val) { - if ($SkipSpaces) { - $SkipSpaces = 0; - } else { - $attachments .= '  |  '; - } - $attachments .= '' . $Val['text'] . ''; + $SkipSpaces = 1; + foreach ($Links as $Val) { + if ($SkipSpaces) { + $SkipSpaces = 0; + } else { + $attachments .= '  |  '; } - $attachments .= "\n"; - unset($Links); - } - - } - - return $attachments; + $attachments .= '' . $Val['text'] . ''; + } + unset($Links); + $attachments .= "\n"; + } + return $attachments; } /** this function decodes the body depending on the encoding type. **/ -- 2.25.1