From 7baf86a911ddc0ef8b2c3f9b9dbaa579f31ab4bc Mon Sep 17 00:00:00 2001 From: teepe Date: Tue, 13 Nov 2001 23:37:30 +0000 Subject: [PATCH] integrated attachment_common into the core git-svn-id: https://svn.code.sf.net/p/squirrelmail/code/trunk/squirrelmail@1748 7612ce4b-ef26-0410-bec9-ea0150e637f0 --- functions/attachment_common.php | 185 +++++++++++++++++++++++++++++ functions/mime.php | 1 + src/image.php | 52 +++++++++ src/load_prefs.php | 3 +- src/options.php | 1 + src/options_display.php | 7 ++ src/read_body.php | 19 +++ src/redirect.php | 35 ++++++ src/vcard.php | 198 ++++++++++++++++++++++++++++++++ 9 files changed, 500 insertions(+), 1 deletion(-) create mode 100644 functions/attachment_common.php create mode 100644 src/image.php create mode 100644 src/vcard.php diff --git a/functions/attachment_common.php b/functions/attachment_common.php new file mode 100644 index 00000000..46eeacd9 --- /dev/null +++ b/functions/attachment_common.php @@ -0,0 +1,185 @@ + 'image/x-bitmap', + 'gif' => 'image/gif', + 'htm' => 'text/html', + 'html' => 'text/html', + 'jpg' => 'image/jpeg', + 'jpeg' => 'image/jpeg', + 'php' => 'text/plain', + 'png' => 'image/png', + 'rtf' => 'text/richtext', + 'txt' => 'text/plain', + 'vcf' => 'text/x-vcard'); + + // Register browser-supported image types + if (isset($attachment_common_types)) { + // Don't run this before being logged in. That may happen + // when plugins include mime.php + foreach ($attachment_common_types as $val => $v) { + if ($val == 'image/gif') + register_attachment_common('image/gif', 'link_image'); + elseif (($val == 'image/jpeg' || $val == 'image/pjpeg') and + (!isset($jpeg_done))) { + $jpeg_done = 1; + register_attachment_common('image/jpeg', 'link_image'); + register_attachment_common('image/pjpeg', 'link_image'); + } + elseif ($val == 'image/png') + register_attachment_common('image/png', 'link_image'); + elseif ($val == 'image/x-xbitmap') + register_attachment_common('image/x-xbitmap', 'link_image'); + } + unset($jpeg_done); + } + + // Register text-type attachments + register_attachment_common('message/rfc822', 'link_text'); + register_attachment_common('text/plain', 'link_text'); + register_attachment_common('text/richtext', 'link_text'); + + // Register HTML + register_attachment_common('text/html', 'link_html'); + + // Register vcards + register_attachment_common('text/x-vcard', 'link_vcard'); + + // Register "unknown" attachments + register_attachment_common('application/octet-stream', 'octet_stream'); + + +/* Function which optimizes readability of the above code */ + +function register_attachment_common($type, $func) { + global $squirrelmail_plugin_hooks; + $squirrelmail_plugin_hooks['attachment ' . $type]['attachment_common'] = + 'attachment_common_' . $func; +} + + +function attachment_common_link_text(&$Args) +{ + // If there is a text attachment, we would like to create a 'view' button + // that links to the text attachment viewer. + // + // $Args[1] = the array of actions + // + // Use our plugin name for adding an action + // $Args[1]['attachment_common'] = array for href and text + // + // $Args[1]['attachment_common']['text'] = What is displayed + // $Args[1]['attachment_common']['href'] = Where it links to + // + // This sets the 'href' of this plugin for a new link. + $Args[1]['attachment_common']['href'] = '../src/download.php?startMessage=' . + $Args[2] . '&passed_id=' . $Args[3] . '&mailbox=' . $Args[4] . + '&passed_ent_id=' . $Args[5] . '&override_type0=text&override_type1=plain'; + + // If we got here from a search, we should preserve these variables + if ($Args[8] && $Args[9]) + $Args[1]['attachment_common']['href'] .= '&where=' . + urlencode($Args[8]) . '&what=' . urlencode($Args[9]); + + // The link that we created needs a name. "view" will be displayed for + // all text attachments handled by this plugin. + $Args[1]['attachment_common']['text'] = _("view"); + + // Each attachment has a filename on the left, which is a link. + // Where that link points to can be changed. Just in case the link above + // for viewing text attachments is not the same as the default link for + // this file, we'll change it. + // + // This is a lot better in the image links, since the defaultLink will just + // download the image, but the one that we set it to will format the page + // to have an image tag in the center (looking a lot like this text viewer) + $Args[6] = $Args[1]['attachment_common']['href']; +} + + +function attachment_common_link_html(&$Args) +{ + $Args[1]['attachment_common']['href'] = '../src/download.php?startMessage=' . + $Args[2] . '&passed_id=' . $Args[3] . '&mailbox=' . $Args[4] . + '&passed_ent_id=' . $Args[5] . '&override_type0=text&override_type1=html'; + + if ($Args[8] && $Args[9]) + $Args[1]['attachment_common']['href'] .= '&where=' . + urlencode($Args[8]) . '&what=' . urlencode($Args[9]); + + $Args[1]['attachment_common']['text'] = _("view"); + + $Args[6] = $Args[1]['attachment_common']['href']; +} + + +function attachment_common_link_image(&$Args) +{ + global $attachment_common_show_images, $attachment_common_show_images_list; + + $info['passed_id'] = $Args[3]; + $info['mailbox'] = $Args[4]; + $info['ent_id'] = $Args[5]; + + $attachment_common_show_images_list[] = $info; + + $Args[1]['attachment_common']['href'] = '../src/image.php?startMessage=' . + $Args[2] . '&passed_id=' . $Args[3] . '&mailbox=' . $Args[4] . + '&passed_ent_id=' . $Args[5]; + + if ($Args[8] && $Args[9]) + $Args[1]['attachment_common']['href'] .= '&where=' . + urlencode($Args[8]) . '&what=' . urlencode($Args[9]); + + $Args[1]['attachment_common']['text'] = _("view"); + + $Args[6] = $Args[1]['attachment_common']['href']; +} + + +function attachment_common_link_vcard(&$Args) +{ + $Args[1]['attachment_common']['href'] = '../src/vcard.php?startMessage=' . + $Args[2] . '&passed_id=' . $Args[3] . '&mailbox=' . $Args[4] . + '&passed_ent_id=' . $Args[5]; + + if (isset($where) && isset($what)) + $Args[1]['attachment_common']['href'] .= '&where=' . + urlencode($Args[8]) . '&what=' . urlencode($Args[9]); + + $Args[1]['attachment_common']['text'] = _("Business Card"); + + $Args[6] = $Args[1]['attachment_common']['href']; +} + + +function attachment_common_octet_stream(&$Args) +{ + global $FileExtensionToMimeType; + + do_hook('attachment_common-load_mime_types'); + + ereg('\\.([^\\.]+)$', $Args[7], $Regs); + + $Ext = strtolower($Regs[1]); + + if ($Ext == '' || ! isset($FileExtensionToMimeType[$Ext])) + return; + + $Ret = do_hook('attachment ' . $FileExtensionToMimeType[$Ext], + $Args[1], $Args[2], $Args[3], $Args[4], $Args[5], $Args[6], + $Args[7], $Args[8], $Args[9]); + + foreach ($Ret as $a => $b) { + $Args[$a] = $b; + } +} + +?> diff --git a/functions/mime.php b/functions/mime.php index cfb9e9d9..74dd9258 100644 --- a/functions/mime.php +++ b/functions/mime.php @@ -12,6 +12,7 @@ define('mime_php', true); require_once('../functions/imap.php'); + require_once('../functions/attachment_common.php'); /** Setting up the objects that have the structure for the message **/ diff --git a/src/image.php b/src/image.php new file mode 100644 index 00000000..8ae17e0a --- /dev/null +++ b/src/image.php @@ -0,0 +1,52 @@ +' . + '' . + "\n" . + '' . "\n" . + '
' . + '
' . + _("Viewing an image attachment") . " - "; + if (isset($where) && isset($what)) { + // from a search + echo '' . _("View message") . ''; + } else { + echo '' . _("View message") . ''; + } + + $DownloadLink = '../src/download.php?passed_id=' . $passed_id . + '&mailbox=' . urlencode($mailbox) . + '&passed_ent_id=' . $passed_ent_id . '&absolute_dl=true'; + + echo '
' . + _("Download this as a file") . + '
 ' . "\n" . + '
' . "\n" . + + '' . "\n" . + '
' . + '' . + + '
' . "\n"; + '' . "\n"; + +?> diff --git a/src/load_prefs.php b/src/load_prefs.php index 377338e6..90745ab1 100644 --- a/src/load_prefs.php +++ b/src/load_prefs.php @@ -188,12 +188,13 @@ $location_of_bar = getPref($data_dir, $username, 'location_of_bar', SMPREF_LOC_LEFT); $location_of_buttons = getPref($data_dir, $username, 'location_of_buttons', SMPREF_LOC_BETWEEN); - global $collapse_folders, $show_html_default, $show_xmailer_default; + global $collapse_folders, $show_html_default, $show_xmailer_default, $attachment_common_show_images; $collapse_folders = getPref($data_dir, $username, 'collapse_folders', SMPREF_ON); /* show_html_default is a int value. */ $show_html_default = intval(getPref($data_dir, $username, 'show_html_default', SMPREF_ON)); $show_xmailer_default = intval(getPref($data_dir, $username, 'show_xmailer_default', SMPREF_OFF ) ); + $attachment_common_show_images = intval(getPref($data_dir, $username, 'attachment_common_show_images', SMPREF_OFF ) ); global $include_self_reply_all; $include_self_reply_all = getPref($data_dir, $username, 'include_self_reply_all', SMPREF_ON); diff --git a/src/options.php b/src/options.php index bcdb43ad..a7b9a08f 100644 --- a/src/options.php +++ b/src/options.php @@ -80,6 +80,7 @@ setPref($data_dir, $username, 'page_selector', $new_page_selector); setPref($data_dir, $username, 'page_selector_max', $new_page_selector_max); setPref($data_dir, $username, 'show_xmailer_default', $new_show_xmailer_default); + setPref($data_dir, $username, 'attachment_common_show_images', $new_attachment_common_show_images); $js_autodetect_results = (isset($new_js_autodetect_results) ? $new_js_autodetect_results : SMPREF_JS_OFF); if ($new_javascript_setting == SMPREF_JS_AUTODETECT) { diff --git a/src/options_display.php b/src/options_display.php index 07899f07..edaaf3c4 100644 --- a/src/options_display.php +++ b/src/options_display.php @@ -188,6 +188,13 @@ 'refresh' => SMOPT_REFRESH_NONE ); + $optvals[SMOPT_GRP_MESSAGE][] = array( + 'name' => 'attachment_common_show_images', + 'caption' => _("Enable display of images with email, below attachment box"), + 'type' => SMOPT_TYPE_BOOLEAN, + 'refresh' => SMOPT_REFRESH_NONE + ); + /* Build and output the option groups. */ $option_groups = createOptionGroups($optgrps, $optvals); printOptionGroups($option_groups); diff --git a/src/read_body.php b/src/read_body.php index 8b5ad466..a0e89636 100644 --- a/src/read_body.php +++ b/src/read_body.php @@ -520,6 +520,25 @@ "  " . '' . "\n"; + /* show attached images inline -- if pref'fed so */ + + if (($attachment_common_show_images) and + is_array($attachment_common_show_images_list)) { + foreach ($attachment_common_show_images_list as $img) { + echo "\n" . + " \n" . + " \n" . + " \n" . + "
\n" . + ' ' . "\n" . + "
\n"; + } + } + do_hook('read_body_bottom'); do_hook('html_bottom'); sqimap_logout($imapConnection); diff --git a/src/redirect.php b/src/redirect.php index 42f23ccf..cb89d5ae 100644 --- a/src/redirect.php +++ b/src/redirect.php @@ -97,6 +97,20 @@ session_register ('user_is_logged_in'); session_register ('just_logged_in'); + /* parse the accepted content-types of the client */ + $attachment_common_types = array(); + $attachment_common_types_parsed = array(); + session_register('attachment_common_types'); + session_register('attachment_common_types_parsed'); + + if (isset($HTTP_SERVER_VARS['HTTP_ACCEPT']) && + !isset($attachment_common_types_parsed[$HTTP_SERVER_VARS['HTTP_ACCEPT']])) + attachment_common_parse($HTTP_SERVER_VARS['HTTP_ACCEPT'], $debug); + if (isset($HTTP_ACCEPT) && + !isset($attachment_common_types_parsed[$HTTP_ACCEPT])) + attachment_common_parse($HTTP_ACCEPT, $debug); + + /* Complete autodetection of Javascript. */ checkForPrefs($data_dir, $username); $javascript_setting = getPref($data_dir, $username, 'javascript_setting', SMPREF_JS_AUTODETECT); @@ -121,4 +135,25 @@ /* Send them off to the appropriate page. */ header("Location: $redirect_url"); + + +function attachment_common_parse($str, $debug) +{ + global $attachment_common_types, $attachment_common_types_parsed; + + $attachment_common_types_parsed[$str] = true; + $types = explode(', ', $str); + + foreach ($types as $val) + { + // Ignore the ";q=1.0" stuff + if (strpos($val, ';') !== false) + $val = substr($val, 0, strpos($val, ';')); + + if (! isset($attachment_common_types[$val])) { + $attachment_common_types[$val] = true; + } + } +} + ?> diff --git a/src/vcard.php b/src/vcard.php new file mode 100644 index 00000000..af3695ae --- /dev/null +++ b/src/vcard.php @@ -0,0 +1,198 @@ +' . "\n" . + ''; + + $message = sqimap_get_message($imapConnection, $passed_id, $mailbox); + + $entity_vcard = getEntity($message,$passed_ent_id); + + $vcard = mime_fetch_body ($imapConnection, $passed_id, $passed_ent_id); + $vcard = decodeBody($vcard, $entity_vcard->header->encoding); + $vcard = explode ("\n",$vcard); + foreach ($vcard as $l) + { + $k = substr($l, 0, strpos($l, ':')); + $v = substr($l, strpos($l, ':') + 1); + $attributes = explode(';', $k); + $k = strtolower(array_shift($attributes)); + foreach ($attributes as $attr) + { + if ($attr == 'quoted-printable') + $v = quoted_printable_decode($v); + else + $k .= ';' . $attr; + } + + $v = ereg_replace(';', "\n", $v); + $vcard_nice[$k] = $v; + } + + if ($vcard_nice['version'] == '2.1') + { + // get firstname and lastname for sm addressbook + $vcard_nice["firstname"] = substr($vcard_nice["n"], + strpos($vcard_nice["n"], "\n") + 1, strlen($vcard_nice["n"])); + $vcard_nice["lastname"] = substr($vcard_nice["n"], 0, + strpos($vcard_nice["n"], "\n")); + } + else + { + echo '\n"; + } + + foreach ($vcard_nice as $k => $v) + { + $v = htmlspecialchars($v); + $v = trim($v); + $vcard_safe[$k] = trim(nl2br($v)); + } + + $ShowValues = array( + 'fn' => _("Name"), + 'title' => _("Title"), + 'email;internet' => _("Email"), + 'url' => _("Web Page"), + 'org' => _("Organization / Department"), + 'adr' => _("Address"), + 'tel;work' => _("Work Phone"), + 'tel;home' => _("Home Phone"), + 'tel;cell' => _("Cellular Phone"), + 'tel;fax' => _("Fax"), + 'note' => _("Note")); + + echo '
' . + '
' . + _("Viewing a Business Card") . " - "; + if (isset($where) && isset($what)) { + // from a search + echo '' . _("View message") . ''; + } else { + echo '' . _("View message") . ''; + } + echo '
vCard Version ' . $vcard_nice['version'] . + ' is not supported. Some information might not be converted ' . + "correctly.

' . + '' . "\n"; + + if (isset($vcard_safe['email;internet'])) { + $vcard_safe['email;internet'] = '' . $vcard_safe['email;internet'] . + ''; + } + if (isset($vcard_safe['url'])) { + $vcard_safe['url'] = '' . + $vcard_safe['url'] . ''; + } + + foreach ($ShowValues as $k => $v) + { + if (isset($vcard_safe[$k]) && $vcard_safe[$k]) + { + echo "\n"; + } + } + + echo '
$v:" . $vcard_safe[$k] . + "
' . + '
' . + '
' . + '' . + '' . + '' . + '' . + '
' . + '
' . + _("Add to Addressbook") . + '
' . + '
' . + '' . + '' . + '' . + '' . + '' . + '
Nickname:
Note Field Contains:' . + '' . + '
' . + '' . + '' . + '' . + '' . + '
' . + '
' . + '
' . + '' . + _("Download this as a file") . '' . + '
' . + + '' . + '
' . + '
' . + ''; -- 2.25.1