+ // A recursive function that returns a list of attachments with links
+ // to where to download these attachments
+ function formatAttachments ($message, $ent_id, $mailbox, $id) {
+ global $where, $what;
+ global $startMessage, $color;
+ static $ShownHTML = 0;
+
+ $body = "";
+ if ($ShownHTML == 0)
+ {
+ $ShownHTML = 1;
+
+ $body .= "<TABLE WIDTH=100% CELLSPACING=0 CELLPADDING=2 BORDER=0 BGCOLOR=\"$color[0]\"><TR>\n";
+ $body .= "<TH ALIGN=\"left\" BGCOLOR=\"$color[9]\"><B>\n";
+ $body .= _('Attachments') . ':';
+ $body .= "</B></TH></TR><TR><TD>\n";
+
+ $body .= "<TABLE CELLSPACING=0 CELLPADDING=1 BORDER=0>\n";
+
+ $body .= formatAttachments ($message, $ent_id, $mailbox, $id);
+
+ $body .= "</TABLE></TD></TR></TABLE>";
+
+ return $body;
+ }
+
+ if ($message) {
+ if (!$message->entities) {
+ $type0 = strtolower($message->header->type0);
+ $type1 = strtolower($message->header->type1);
+
+ if ($message->header->entity_id != $ent_id) {
+ $filename = decodeHeader($message->header->filename);
+ if (trim($filename) == "") {
+ $display_filename = "untitled-".$message->header->entity_id;
+ } else {
+ $display_filename = $filename;
+ }
+
+ $urlMailbox = urlencode($mailbox);
+ $ent = urlencode($message->header->entity_id);
+
+ $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 = '';
+
+ $HookResults = do_hook("attachment $type0/$type1", $Links,
+ $startMessage, $id, $urlMailbox, $ent, $DefaultLink,
+ $display_filename, $where, $what);
+
+ $Links = $HookResults[1];
+ $DefaultLink = $HookResults[6];
+
+ $body .= '<TR><TD> </TD><TD>';
+ $body .= "<A HREF=\"$DefaultLink\">$display_filename</A> </TD>";
+ $body .= '<TD><SMALL><b>' . show_readable_size($message->header->size) .
+ '</b> </small></TD>';
+ $body .= "<TD><SMALL>[ $type0/$type1 ] </SMALL></TD>";
+ $body .= '<TD><SMALL>';
+ if ($message->header->description)
+ $body .= '<b>' . htmlspecialchars($message->header->description) . '</b>';
+ $body .= '</SMALL></TD><TD><SMALL> ';
+
+
+ $SkipSpaces = 1;
+ foreach ($Links as $Val)
+ {
+ if ($SkipSpaces)
+ {
+ $SkipSpaces = 0;
+ }
+ else
+ {
+ $body .= ' | ';
+ }
+ $body .= '<a href="' . $Val['href'] . '">' . $Val['text'] . '</a>';
+ }
+
+ unset($Links);
+
+ $body .= "</SMALL></TD></TR>\n";
+ }
+ return $body;
+ } else {
+ for ($i = 0; $i < count($message->entities); $i++) {
+ $body .= formatAttachments ($message->entities[$i], $ent_id, $mailbox, $id);
+ }
+ return $body;
+ }
+ }
+ }