From be72fb3597c21ca3aaa058adf41bb72d53d197c7 Mon Sep 17 00:00:00 2001 From: Aleksander Machniak Date: Fri, 28 Dec 2012 12:40:57 +0100 Subject: Unified attachments filenames handling for message parts without a filename --- program/lib/Roundcube/rcube_message.php | 21 --------------------- program/localization/en_US/labels.inc | 1 + program/steps/mail/compose.inc | 11 +---------- program/steps/mail/func.inc | 30 +++++++++++++++++++++++++----- program/steps/mail/get.inc | 21 ++------------------- program/steps/mail/show.inc | 5 +---- 6 files changed, 30 insertions(+), 59 deletions(-) diff --git a/program/lib/Roundcube/rcube_message.php b/program/lib/Roundcube/rcube_message.php index 9fea8382a..d450bb439 100644 --- a/program/lib/Roundcube/rcube_message.php +++ b/program/lib/Roundcube/rcube_message.php @@ -106,7 +106,6 @@ class rcube_message if (!empty($this->headers->structure)) { $this->get_mime_numbers($this->headers->structure); $this->parse_structure($this->headers->structure); - $this->parse_attachments(); } else { $this->body = $this->storage->get_body($uid); @@ -650,26 +649,6 @@ class rcube_message } - /** - * Parse attachment parts - */ - private function parse_attachments() - { - // Attachment must have a name - foreach ($this->attachments as $attachment) { - if (!$attachment->filename) { - $ext = rcube_mime::get_mime_extensions($attachment->mimetype); - $ext = array_shift($ext); - - $attachment->filename = 'Part_' . $attachment->mime_id; - if ($ext) { - $attachment->filename .= '.' . $ext; - } - } - } - } - - /** * Fill aflat array with references to all parts, indexed by part numbers * diff --git a/program/localization/en_US/labels.inc b/program/localization/en_US/labels.inc index 730e6af09..fa8f33d6d 100644 --- a/program/localization/en_US/labels.inc +++ b/program/localization/en_US/labels.inc @@ -377,6 +377,7 @@ $labels['edititem'] = 'Edit item'; $labels['preferhtml'] = 'Display HTML'; $labels['defaultcharset'] = 'Default Character Set'; $labels['htmlmessage'] = 'HTML Message'; +$labels['messagepart'] = 'Part'; $labels['dateformat'] = 'Date format'; $labels['timeformat'] = 'Time format'; $labels['prettydate'] = 'Pretty dates'; diff --git a/program/steps/mail/compose.inc b/program/steps/mail/compose.inc index 379e920e5..74c6d5f29 100644 --- a/program/steps/mail/compose.inc +++ b/program/steps/mail/compose.inc @@ -1154,16 +1154,7 @@ function rcmail_save_attachment(&$message, $pid) } $mimetype = $part->ctype_primary . '/' . $part->ctype_secondary; - $filename = $part->filename; - if (!strlen($filename)) { - if ($mimetype == 'text/html') { - $filename = rcube_label('htmlmessage'); - } - else { - $filename = 'Part_'.$pid; - } - $filename .= '.' . $part->ctype_secondary; - } + $filename = rcmail_attachment_name($part); $attachment = array( 'group' => $COMPOSE['id'], diff --git a/program/steps/mail/func.inc b/program/steps/mail/func.inc index 814adb64d..bedd3e8ea 100644 --- a/program/steps/mail/func.inc +++ b/program/steps/mail/func.inc @@ -1598,10 +1598,7 @@ function rcmail_message_part_controls($attrib) $part = $MESSAGE->mime_parts[$part]; $table = new html_table(array('cols' => 3)); - $filename = $part->filename; - if (empty($filename) && $attach_prop->mimetype == 'text/html') { - $filename = rcube_label('htmlmessage'); - } + $filename = rcmail_attachment_name($part); if (!empty($filename)) { $table->add('title', Q(rcube_label('filename'))); @@ -1616,7 +1613,6 @@ function rcmail_message_part_controls($attrib) } - function rcmail_message_part_frame($attrib) { global $MESSAGE; @@ -1841,6 +1837,30 @@ function rcmail_fix_mimetype($name) return $name; } +// return attachment filename, handle empty filename case +function rcmail_attachment_name($attachment) +{ + $filename = $attachment->filename; + + if ($filename === null || $filename === '') { + if ($attachment->mimetype == 'text/html') { + $filename = rcube_label('htmlmessage'); + } + else { + $ext = rcube_mime::get_mime_extensions($attachment->mimetype); + $ext = array_shift($ext); + $filename = rcube_label('messagepart') . ' ' . $attachment->mime_id; + if ($ext) { + $filename .= '.' . $ext; + } + } + } + + $filename = preg_replace('[\r\n]', '', $filename); + + return $filename; +} + function rcmail_search_filter($attrib) { global $OUTPUT, $CONFIG; diff --git a/program/steps/mail/get.inc b/program/steps/mail/get.inc index 803716d61..37f728ebf 100644 --- a/program/steps/mail/get.inc +++ b/program/steps/mail/get.inc @@ -47,13 +47,7 @@ check_storage_status(); // show part page if (!empty($_GET['_frame'])) { if (($part_id = get_input_value('_part', RCUBE_INPUT_GPC)) && ($part = $MESSAGE->mime_parts[$part_id])) { - $filename = $part->filename; - if (empty($filename) && $part->mimetype == 'text/html') { - $filename = rcube_label('htmlmessage'); - } - if (!empty($filename)) { - $OUTPUT->set_pagetitle($filename); - } + $OUTPUT->set_pagetitle(rcmail_attachment_name($part)); } $OUTPUT->send('messagepart'); @@ -236,18 +230,7 @@ else if (strlen($pid = get_input_value('_part', RCUBE_INPUT_GET))) { // don't kill the connection if download takes more than 30 sec. @set_time_limit(0); - if ($part->filename) { - $filename = $part->filename; - } - else if ($part->mimetype == 'text/html') { - $filename = rcube_label('htmlmessage'); - } - else { - $ext = '.' . ($mimetype == 'text/plain' ? 'txt' : $ctype_secondary); - $filename = ($MESSAGE->subject ? $MESSAGE->subject : 'roundcube') . $ext; - } - - $filename = preg_replace('[\r\n]', '', $filename); + $filename = rcmail_attachment_name($part); if ($browser->ie && $browser->ver < 7) $filename = rawurlencode(abbreviate_string($filename, 55)); diff --git a/program/steps/mail/show.inc b/program/steps/mail/show.inc index 82594f3e4..22f4ff4c2 100644 --- a/program/steps/mail/show.inc +++ b/program/steps/mail/show.inc @@ -150,10 +150,7 @@ function rcmail_message_attachments($attrib) if (sizeof($MESSAGE->attachments)) { foreach ($MESSAGE->attachments as $attach_prop) { - $filename = $attach_prop->filename; - if (empty($filename) && $attach_prop->mimetype == 'text/html') { - $filename = rcube_label('htmlmessage'); - } + $filename = rcmail_attachment_name($attach_prop); if ($PRINT_MODE) { $size = $RCMAIL->message_part_size($attach_prop); -- cgit v1.2.3 From 830fd2ecbb67c395617e1cc38f343d12af0a2861 Mon Sep 17 00:00:00 2001 From: Aleksander Machniak Date: Fri, 28 Dec 2012 15:33:48 +0100 Subject: Display PGP/MIME signature attachments as "Digital Signature" (#1488570) --- CHANGELOG | 1 + program/localization/en_US/labels.inc | 1 + program/steps/mail/func.inc | 9 ++++++++- program/steps/mail/show.inc | 2 +- 4 files changed, 11 insertions(+), 2 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 5f010acb3..687fd8929 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,6 +1,7 @@ CHANGELOG Roundcube Webmail =========================== +- Display PGP/MIME signature attachments as "Digital Signature" (#1488570) - Workaround UW-IMAP bug where hierarchy separator is added to the shared folder name (#1488879) - Fix version comparisons with -stable suffix (#1488876) - Add unsupported alternative parts to attachments list (#1488870) diff --git a/program/localization/en_US/labels.inc b/program/localization/en_US/labels.inc index fa8f33d6d..b5fcee496 100644 --- a/program/localization/en_US/labels.inc +++ b/program/localization/en_US/labels.inc @@ -378,6 +378,7 @@ $labels['preferhtml'] = 'Display HTML'; $labels['defaultcharset'] = 'Default Character Set'; $labels['htmlmessage'] = 'HTML Message'; $labels['messagepart'] = 'Part'; +$labels['digitalsig'] = 'Digital Signature'; $labels['dateformat'] = 'Date format'; $labels['timeformat'] = 'Time format'; $labels['prettydate'] = 'Pretty dates'; diff --git a/program/steps/mail/func.inc b/program/steps/mail/func.inc index bedd3e8ea..44a1557c3 100644 --- a/program/steps/mail/func.inc +++ b/program/steps/mail/func.inc @@ -1838,7 +1838,7 @@ function rcmail_fix_mimetype($name) } // return attachment filename, handle empty filename case -function rcmail_attachment_name($attachment) +function rcmail_attachment_name($attachment, $display = false) { $filename = $attachment->filename; @@ -1858,6 +1858,13 @@ function rcmail_attachment_name($attachment) $filename = preg_replace('[\r\n]', '', $filename); + // Display smart names for some known mimetypes + if ($display) { + if (preg_match('/application\/(pgp|pkcs7)-signature/i', $attachment->mimetype)) { + $filename = rcube_label('digitalsig'); + } + } + return $filename; } diff --git a/program/steps/mail/show.inc b/program/steps/mail/show.inc index 22f4ff4c2..64e628880 100644 --- a/program/steps/mail/show.inc +++ b/program/steps/mail/show.inc @@ -150,7 +150,7 @@ function rcmail_message_attachments($attrib) if (sizeof($MESSAGE->attachments)) { foreach ($MESSAGE->attachments as $attach_prop) { - $filename = rcmail_attachment_name($attach_prop); + $filename = rcmail_attachment_name($attach_prop, true); if ($PRINT_MODE) { $size = $RCMAIL->message_part_size($attach_prop); -- cgit v1.2.3