summaryrefslogtreecommitdiff
path: root/program/steps/mail
diff options
context:
space:
mode:
authorthomascube <thomas@roundcube.net>2007-03-19 22:36:24 +0000
committerthomascube <thomas@roundcube.net>2007-03-19 22:36:24 +0000
commit5cc4b13a0c6d32d74d0cba17feeb6c5fbceaf25f (patch)
treea4d6f4f7ea5d0a0360b7b0ead746f6b3c3b556a7 /program/steps/mail
parent86958f70d2970704e9ec6935d65e294c077143ea (diff)
Correctly parse message/rfc822; fixed html2text conversion; code cleanup
Diffstat (limited to 'program/steps/mail')
-rw-r--r--program/steps/mail/compose.inc17
-rw-r--r--program/steps/mail/func.inc45
-rw-r--r--program/steps/mail/get.inc8
3 files changed, 28 insertions, 42 deletions
diff --git a/program/steps/mail/compose.inc b/program/steps/mail/compose.inc
index 1c2639d9b..a794e9814 100644
--- a/program/steps/mail/compose.inc
+++ b/program/steps/mail/compose.inc
@@ -401,8 +401,8 @@ function rcmail_compose_body($attrib)
$body = rcmail_first_text_part($MESSAGE);
$isHtml = false;
}
- if (strlen($body))
- $body = rcmail_create_forward_body($body, $isHtml);
+
+ $body = rcmail_create_forward_body($body, $isHtml);
}
else if ($compose_mode == RCUBE_COMPOSE_DRAFT)
{
@@ -564,10 +564,9 @@ function rcmail_create_forward_body($body, $bodyIsHtml)
}
// add attachments
- if (!isset($_SESSION['compose']['forward_attachments']) &&
- is_array($MESSAGE['parts']) && sizeof($MESSAGE['parts'])>1)
+ if (!isset($_SESSION['compose']['forward_attachments']) && is_array($MESSAGE['parts']))
rcmail_write_compose_attachments($MESSAGE);
-
+
return $prefix.$body;
}
@@ -598,7 +597,7 @@ function rcmail_write_compose_attachments(&$message)
{
if ($part->ctype_primary != 'message' && $part->ctype_primary != 'text' &&
($part->disposition=='attachment' || $part->disposition=='inline' || $part->headers['content-id'] ||
- (empty($part->disposition) && ($part->d_parameters['filename'] || $part->ctype_parameters['name']))))
+ (empty($part->disposition) && $part->filename)))
{
$tmp_path = tempnam($temp_dir, 'rcmAttmnt');
if ($fp = fopen($tmp_path, 'w'))
@@ -606,13 +605,9 @@ function rcmail_write_compose_attachments(&$message)
fwrite($fp, $IMAP->get_message_part($message['UID'], $pid, $part->encoding));
fclose($fp);
- $filename = !empty($part->d_parameters['filename']) ? $part->d_parameters['filename'] :
- (!empty($part->ctype_parameters['name']) ? $part->ctype_parameters['name'] :
- (!empty($part->headers['content-description']) ? $part->headers['content-description'] : 'file'));
-
$_SESSION['compose']['attachments'][] = array(
- 'name' => rcube_imap::decode_mime_string($filename),
'mimetype' => $part->ctype_primary . '/' . $part->ctype_secondary,
+ 'name' => $part->filename,
'path' => $tmp_path
);
}
diff --git a/program/steps/mail/func.inc b/program/steps/mail/func.inc
index be9558fe1..e5e4db837 100644
--- a/program/steps/mail/func.inc
+++ b/program/steps/mail/func.inc
@@ -727,6 +727,14 @@ function rcmail_print_body($part, $safe=FALSE, $plain=FALSE)
$body = is_array($part->replaces) ? strtr($part->body, $part->replaces) : $part->body;
+ // convert html to text/plain
+ if ($part->ctype_secondary=='html' && $plain)
+ {
+ $txt = new html2text($body, false, true);
+ $body = $txt->get_text();
+ $part->ctype_secondary = 'plain';
+ }
+
// text/html
if ($part->ctype_secondary=='html')
{
@@ -975,7 +983,7 @@ function rcmail_parse_message(&$structure, $arg=array(), $recursive=FALSE)
// part is file/attachment
else if ($mail_part->disposition=='attachment' || $mail_part->disposition=='inline' || $mail_part->headers['content-id'] ||
- (empty($mail_part->disposition) && ($mail_part->d_parameters['filename'] || $mail_part->ctype_parameters['name'])))
+ (empty($mail_part->disposition) && $mail_part->filename))
{
// skip apple resource forks
if ($message_ctype_secondary=='appledouble' && $secondary_type=='applefile')
@@ -984,18 +992,12 @@ function rcmail_parse_message(&$structure, $arg=array(), $recursive=FALSE)
// part belongs to a related message
if ($message_ctype_secondary=='related' && $mail_part->headers['content-id'])
{
- $mail_part->filename = rcube_imap::decode_mime_string($mail_part->d_parameters['filename']);
$mail_part->content_id = preg_replace(array('/^</', '/>$/'), '', $mail_part->headers['content-id']);
$sa_inline_objects[] = $mail_part;
}
// is regular attachment
- else if (($fname = $mail_part->d_parameters['filename']) ||
- ($fname = $mail_part->ctype_parameters['name']) ||
- ($fname = $mail_part->headers['content-description']))
- {
- $mail_part->filename = rcube_imap::decode_mime_string($fname);
+ else if ($mail_part->filename)
$a_attachments[] = $mail_part;
- }
}
}
@@ -1018,16 +1020,8 @@ function rcmail_parse_message(&$structure, $arg=array(), $recursive=FALSE)
}
// message is single part non-text
- else
- {
- if (($fname = $structure->d_parameters['filename']) ||
- ($fname = $structure->ctype_parameters['name']) ||
- ($fname = $structure->headers['content-description']))
- {
- $structure->filename = rcube_imap::decode_mime_string($fname);
- $a_attachments[] = $structure;
- }
- }
+ else if ($structure->filename)
+ $a_attachments[] = $structure;
return array($a_return_parts, $a_attachments);
}
@@ -1136,11 +1130,11 @@ function rcmail_message_body($attrib)
if (!isset($part->body))
$part->body = $IMAP->get_message_part($MESSAGE['UID'], $part->mime_id, $part);
- $body = rcmail_print_body($part, $safe_mode);
+ $body = rcmail_print_body($part, $safe_mode, !$CONFIG['prefer_html']);
$out .= '<div class="message-part">';
if ($part->ctype_secondary != 'plain')
- $out .= rcmail_mod_html_body($body, $attrib['id']);
+ $out .= rcmail_sanitize_html($body, $attrib['id']);
else
$out .= $body;
@@ -1180,7 +1174,7 @@ function rcmail_message_body($attrib)
// modify a HTML message that it can be displayed inside a HTML page
-function rcmail_mod_html_body($body, $container_id)
+function rcmail_sanitize_html($body, $container_id)
{
// remove any null-byte characters before parsing
$body = preg_replace('/\x00/', '', $body);
@@ -1452,22 +1446,19 @@ function rcmail_message_part_controls()
$attrib_str = create_attrib_string($attrib, array('id', 'class', 'style', 'cellspacing', 'cellpadding', 'border', 'summary'));
$out = '<table '. $attrib_str . ">\n";
- $filename = $part->d_parameters['filename'] ? $part->d_parameters['filename'] : $part->ctype_parameters['name'];
- $filesize = $part->size;
-
if ($filename)
{
$out .= sprintf('<tr><td class="title">%s</td><td>%s</td><td>[<a href="./?%s">%s</a>]</tr>'."\n",
Q(rcube_label('filename')),
- Q(rcube_imap::decode_mime_string($filename)),
+ Q($part->filename),
str_replace('_frame=', '_download=', $_SERVER['QUERY_STRING']),
Q(rcube_label('download')));
}
- if ($filesize)
+ if ($part->size)
$out .= sprintf('<tr><td class="title">%s</td><td>%s</td></tr>'."\n",
Q(rcube_label('filesize')),
- show_bytes($filesize));
+ show_bytes($part->size));
$out .= "\n</table>";
diff --git a/program/steps/mail/get.inc b/program/steps/mail/get.inc
index 521f47735..11688f125 100644
--- a/program/steps/mail/get.inc
+++ b/program/steps/mail/get.inc
@@ -59,16 +59,12 @@ else if ($pid = get_input_value('_part', RCUBE_INPUT_GET))
{
$ctype_primary = strtolower($part->ctype_primary);
$ctype_secondary = strtolower($part->ctype_secondary);
-
$mimetype = sprintf('%s/%s', $ctype_primary, $ctype_secondary);
- $filename = $part->d_parameters['filename'] ? $part->d_parameters['filename'] : $part->ctype_parameters['name'];
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: private", false);
header("Content-Transfer-Encoding: binary");
- header(sprintf('Content-Disposition: attachment; filename="%s";',
- $filename ? rcube_imap::decode_mime_string($filename) : "roundcube.$ctype_secondary"));
// send download headers
if ($_GET['_download'])
@@ -110,6 +106,10 @@ else if ($pid = get_input_value('_part', RCUBE_INPUT_GET))
}
else
{
+ header(sprintf('Content-Disposition: %s; filename="%s";',
+ $part->disposition ? $part->disposition : 'attachment',
+ $part->filename ? $part->filename : "roundcube.$ctype_secondary"));
+
// turn off output buffering and print part content
$IMAP->get_message_part($MESSAGE['UID'], $part->mime_id, $part->encoding, true);
}