From 57257333e3546449b8f5138ff152766bcf8329c3 Mon Sep 17 00:00:00 2001 From: philippe_mingo Date: Sat, 9 Feb 2002 17:10:22 +0000 Subject: [PATCH] MDN support. First approach. git-svn-id: https://svn.code.sf.net/p/squirrelmail/code/trunk/squirrelmail@2391 7612ce4b-ef26-0410-bec9-ea0150e637f0 --- src/compose.php | 25 +- src/load_prefs.php | 2 + src/options_display.php | 10 +- src/read_body.php | 513 +++++++++++++++++++++++++++++++--------- 4 files changed, 435 insertions(+), 115 deletions(-) diff --git a/src/compose.php b/src/compose.php index 749a542b..0d6a638f 100644 --- a/src/compose.php +++ b/src/compose.php @@ -36,7 +36,7 @@ if (!isset($mailbox) || $mailbox == '' || ($mailbox == 'None')) { if (isset($draft)) { include_once ('../src/draft_actions.php'); - if (!saveMessageAsDraft($send_to, $send_to_cc, $send_to_bcc, $subject, $body, $reply_id)) { + if (!saveMessageAsDraft($send_to, $send_to_cc, $send_to_bcc, $subject, $body, $reply_id, $MDN)) { showInputForm(); exit(); } else { @@ -100,13 +100,14 @@ if (isset($send)) { $body = $newBody; do_hook("compose_send"); - + + $MDN = False; // we are not sending a mdn response if (! isset($mailprio)) { $Result = sendMessage($send_to, $send_to_cc, $send_to_bcc, - $subject, $body, $reply_id); + $subject, $body, $reply_id, $MDN); } else { $Result = sendMessage($send_to, $send_to_cc, $send_to_bcc, - $subject, $body, $reply_id, $mailprio); + $subject, $body, $reply_id, $MDN, $mailprio); } if (! $Result) { showInputForm(); @@ -419,7 +420,7 @@ function showInputForm () { $use_javascript_addr_book, $send_to_bcc, $reply_id, $mailbox, $from_htmladdr_search, $location_of_buttons, $attachment_dir, $username, $data_dir, $identity, $draft_id, $delete_draft, - $mailprio; + $mailprio, $default_use_mdn, $mdn_user_support; $subject = decodeHeader($subject, false); $reply_subj = decodeHeader($reply_subj, false); @@ -439,6 +440,8 @@ function showInputForm () { echo "\n" . '
\n"; if (isset($draft_id)) { @@ -601,7 +604,7 @@ function showInputForm () { function showComposeButtonRow() { global $use_javascript_addr_book, $save_as_draft, - $default_use_priority, $mailprio; + $default_use_priority, $mailprio, $default_use_mdn; echo " \n \n"; if ($use_javascript_addr_book) { @@ -632,6 +635,14 @@ function showComposeButtonRow() "\n\t"; } + $mdn_user_support=getPref($data_dir, $username, 'mdn_user_support',$default_use_mdn); + if ($default_use_mdn) { + if ($mdn_user_support) { + echo _("Confirm reading:"). + ""; + } + } + do_hook('compose_button_row'); echo " \n"; @@ -688,6 +699,8 @@ function saveAttachedFiles() { } + + function ClearAttachments() { global $username, $attachments, $attachment_dir; diff --git a/src/load_prefs.php b/src/load_prefs.php index 6be0208f..acd61f77 100644 --- a/src/load_prefs.php +++ b/src/load_prefs.php @@ -193,6 +193,8 @@ $attachment_common_show_images = getPref($data_dir, $username, 'attachment_commo $pf_subtle_link = getPref($data_dir, $username, 'pf_subtle_link', SMPREF_ON); $pf_cleandisplay = getPref($data_dir, $username, 'pf_cleandisplay', SMPREF_OFF); +$mdn_user_support = getPref($data_dir, $username, 'mdn_user_support', SMPREF_ON); + $include_self_reply_all = getPref($data_dir, $username, 'include_self_reply_all', SMPREF_ON); diff --git a/src/options_display.php b/src/options_display.php index d5c30fdc..ec881463 100644 --- a/src/options_display.php +++ b/src/options_display.php @@ -18,7 +18,7 @@ define('SMOPT_GRP_MESSAGE', 2); /* Define the optpage load function for the display options page. */ function load_optpage_data_display() { - global $theme, $language, $languages, $js_autodetect_results; + global $theme, $language, $languages, $js_autodetect_results, $default_use_mdn; /* Build a simple array into which we will build options. */ $optgrps = array(); @@ -225,6 +225,14 @@ function load_optpage_data_display() { 'type' => SMOPT_TYPE_BOOLEAN, 'refresh' => SMOPT_REFRESH_NONE ); + if ($default_use_mdn) { + $optvals[SMOPT_GRP_MESSAGE][] = array( + 'name' => 'mdn_user_support', + 'caption' => _("Enable request/confirm reading"), + 'type' => SMOPT_TYPE_BOOLEAN, + 'refresh' => SMOPT_REFRESH_NONE + ); + } /* Assemble all this together and return it as our result. */ $result = array( diff --git a/src/read_body.php b/src/read_body.php index 866422d5..a277a207 100644 --- a/src/read_body.php +++ b/src/read_body.php @@ -17,6 +17,7 @@ require_once('../functions/imap.php'); require_once('../functions/mime.php'); require_once('../functions/date.php'); require_once('../functions/url_parser.php'); +require_once('../functions/smtp.php'); /** * Given an IMAP message id number, this will look it up in the cached @@ -58,8 +59,9 @@ function RemoveAddress(&$addr_list, $addr) { /** returns the index of the previous message from the array. */ function findPreviousMessage() { - global $msort, $currentArrayIndex, $sort, $msgs, $imapConnection; - global $mailbox, $data_dir, $username; + global $msort, $currentArrayIndex, $sort, $msgs, $imapConnection, + $mailbox, $data_dir, $username; + $result = -1; if ($sort == 6) { @@ -87,26 +89,26 @@ function findPreviousMessage() { * "printer friendly". */ function printer_friendly_link() { - global $passed_id, $mailbox, $ent_num, $color; - global $pf_subtle_link; - global $javascript_on; + global $passed_id, $mailbox, $ent_num, $color, + $pf_subtle_link, + $javascript_on; if (strlen(trim($mailbox)) < 1) { $mailbox = 'INBOX'; } - $params = '?passed_ent_id=' . $ent_num; - $params .= '&mailbox=' . urlencode($mailbox); - $params .= '&passed_id=' . $passed_id; + $params = '?passed_ent_id=' . $ent_num . + '&mailbox=' . urlencode($mailbox) . + '&passed_id=' . $passed_id; $print_text = _("View Printable Version"); if (!$pf_subtle_link) { /* The link is large, on the bottom of the header panel. */ - $result = ' ' . "\n" . - ' ' . "\n" . - '  ' . "\n" . - ' '."\n"; + $result = '' . + '' . + ' ' . + ''."\n"; } else { /* The link is subtle, below "view full header". */ $result = "
\n"; @@ -130,22 +132,162 @@ function printer_friendly_link() { if (!$pf_subtle_link) { /* The link is large, on the bottom of the header panel. */ - $result .= ' ' . "\n" . - ' ' . "\n"; + $result .= '' . "\n"; } return ($result); } -/*****************************/ -/*** Main of read_boby.php ***/ -/*****************************/ +function ServerMDNSupport( $read ) { + + $num = 0; + $resp = ''; + while ($num < count($read) ) { + $resp .= $read[$num]; + $num++; + } + $read[] = split(' * ', $resp); + $num = 0; + $ret = FALSE; + while ( !$ret && $num < count($read) ) { + if ( ereg('PERMANENTFLAGS', $read[$num] ) ) { + $ret = ( ereg('mdnsent',strtolower($read[$num]) ) || ereg("\\\*", $read[$num] ) ); + } + $num++; + } + return ( $ret ); +} + +function SendMDN ( $recipient , $sender) { + global $imapConnection, $mailbox, $username, $attachment_dir, $SERVER_NAME, + $version, $attachments, $identity, $data_dir, $passed_id; + + $message = sqimap_get_message($imapConnection, $passed_id, $mailbox); + $header = $message->header; + + $hashed_attachment_dir = getHashedDir($username, $attachment_dir); + + // part 1 (RFC2298) + + $senton = getLongDateString( $header->date ); + $to_array = $header->to; + $to = ''; + foreach ($to_array as $line) { + $to .= " $line "; + } + + $subject = $header->subject; + $now = getLongDateString( time() ); + $body = sprintf( _("This message sent on %s to %s with subject \"%s\" has been displayed on %s."), + $senton, $to, $subject, $now ) . + "\r\n" . + _("This is no guarantee that the message has been read or understood.") . "\r\n"; + + // part2 (RFC2298) + + $original_recipient = $to; + $original_message_id = $header->message_id; + + $part2 = "Reporting-UA : $SERVER_NAME ; SquirrelMail (version $version) \r\n"; + if ($original_recipient != '') { + $part2 .= "Original-Recipient : $original_recipient\r\n"; + } + $final_recipient = $sender; + $part2 .= "Final-Recipient: rfc822; $final_recipient\r\n" . + "Original-Message-ID : $original_message_id\r\n" . + "Disposition: manual-action/MDN-sent-manually; displayed\r\n"; + + + $localfilename = GenerateRandomString(32, 'FILE', 7); + $full_localfilename = "$hashed_attachment_dir/$localfilename"; + + $fp = fopen( $full_localfilename, 'w'); + fwrite ($fp, $part2); + fclose($fp); + + $newAttachment = array(); + $newAttachment['localfilename'] = $localfilename; + $newAttachment['type'] = "message/disposition-notification"; + + $attachments[] = $newAttachment; + $MDN_to = trim($recipient); + $reply_id = 0; + + return (SendMessage($MDN_to,'','',"Read: $subject", $body,$reply_id, True, 3) ); +} + + +function ToggleMDNflag ( $set ) { + + global $imapConnection, $passed_id; + + $myflag = '$MDNSent'; + if ($set) { + $read = sqimap_run_command ($imapConnection, "STORE $passed_id +FLAGS ($myflag)", true, + $response, $readmessage); + } else { + $read = sqimap_run_command ($imapConnection, "STORE $passed_id -FLAGS ($myflag)", true, + $response, $readmessage); + } +} + +function ClearAttachments() { + global $username, $attachments, $attachment_dir; + + $hashed_attachment_dir = getHashedDir($username, $attachment_dir); + + foreach ($attachments as $info) { + $attached_file = "$hashed_attachment_dir/$info[localfilename]"; + if (file_exists($attached_file)) { + unlink($attached_file); + } + } + + $attachments = array(); +} + + +/* + * Main of read_boby.php -------------------------------------------------- + */ + +/* + Urled vars + ---------- + $passed_id +*/ $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0); -sqimap_mailbox_select($imapConnection, $mailbox); +$read = sqimap_mailbox_select($imapConnection, $mailbox); + do_hook('html_top'); + +/* + * The following code sets necesarry stuff for the MDN thing + */ +if( $default_use_mdn && + ( $mdn_user_support = getPref($data_dir, $username, 'mdn_user_support', $default_use_mdn) ) ) { + + $supportMDN = ServerMDNSupport($read); + + $flags = sqimap_get_flags ($imapConnection, $passed_id); + $FirstTimeSee = TRUE; + $num=0; + while ($num < count($flags)) { + if ($flags[$num] == 'Seen') { + $FirstTimeSee = false; + } + $num++; + } + +} + displayPageHeader($color, $mailbox); + +/* + * The following code shows the header of the message and then exit + */ if (isset($view_hdr)) { $read = sqimap_run_command ($imapConnection, "FETCH $passed_id BODY[HEADER]", true, $a, $b); @@ -159,9 +301,9 @@ if (isset($view_hdr)) { } else { echo "&passed_id=$passed_id&startMessage=$startMessage&show_more=$show_more\">"; } - echo ''._("View message") . "\n" . - "\n" . - '
'; + echo _("View message") . "
\n" . + "\n" . + '
'; $cnum = 0; for ($i=1; $i < count($read); $i++) { @@ -197,8 +339,8 @@ if (isset($view_hdr)) { parseEmail($s); if (isset($f)) echo "$f$s"; } - echo "
\n"; - echo ''; + echo "\n" . + ''; sqimap_logout($imapConnection); exit; } @@ -290,7 +432,9 @@ $ent_num = findDisplayEntity($message); $echo_more = _("more"); $echo_less = _("less"); -if (!isset($show_more_cc)) $show_more_cc = false; +if (!isset($show_more_cc)) { + $show_more_cc = FALSE; +} /** FORMAT THE TO STRING **/ $i = 0; @@ -446,13 +590,13 @@ $subject = decodeHeader(htmlspecialchars($message->header->subject)); do_hook('read_body_top'); echo '
' . - '' . "\n" . - '
' . "\n" . - ' ' . "\n" . - ' ' . "\n" . - ' ' . - ' ' . + '' . '
' . "\n" . - ' ' . "\n" . - '' . + '
' . + '' . + '' . + '' . + '' . - ' ' . - '
' . + '' . + '' . "\n" . - ' ' . "\n" . - ' ' . "\n"; + '' . + '' . + ''; if ( !($where && $what) ) { @@ -505,40 +649,40 @@ if ( !($where && $what) ) { } } -echo ' ' . "\n" . - ' ' . - ' ' . - ' ' . + '' . + '' . + '" . _("Forward") . ' | ' . - ' " . _("Reply") . ' | ' . - ' " . _("Reply All") . '  ' . - ' ' . - '
' . - '
' . - ' ' . "\n" . - ' ' . "\n"; + '' . + '' . + '' . + '
' . + '
' . + '' . "\n" . + '' . "\n"; /** subject **/ -echo " \n" . - ' \n" . + '' . "\n" . - ' ' ."\n"; +echo '' . + ' '; /** from **/ -echo ' ' . "\n" . - ' ' . + '' . "\n" . - ' ' . "\n"; + '' . + ''; /** date **/ -echo ' ' . "\n" . - ' ' . "\n" . + '' . "\n" . - ' ' . "\n"; + "' . "\n" . + '' . "\n"; /** to **/ -echo " \n" . - " \n" . + "' . "\n" . - ' ' . "\n"; + '' . "\n" . + '' . "\n"; /** cc **/ if (isset($cc_string)) { - echo " \n" . - " ' . "\n" . - ' ' . "\n"; + echo '' . + "' . + '' . "\n"; } /** bcc **/ if (isset($bcc_string)) { - echo " \n" . - " ' . "\n" . - ' ' . "\n"; + echo ''. + "' . + '' . "\n"; } if ($default_use_priority) { if (isset($priority_string)) { - echo " \n" . - " " . "\n" . - " " . "\n"; + echo '' . + "' . + "" . "\n"; } } @@ -623,13 +767,13 @@ if ($show_xmailer_default) { $response, $readmessage); $mailer = substr($read[1], strpos($read[1], " ")); if (trim($mailer)) { - echo " \n" . - " " . "\n" . - " " . "\n"; + echo '' . + "' . + "" . "\n"; } } @@ -638,7 +782,160 @@ if (!$pf_subtle_link) { echo printer_friendly_link(true); } +if ($default_use_mdn) { + if ($mdn_user_support) { + + // debug gives you the capability to remove mdn-flags + $debug = FALSE; + + $read = sqimap_run_command ($imapConnection, "FETCH $passed_id BODY.PEEK[HEADER.FIELDS (Disposition-Notification-To)]", true, + $response, $readmessage); + $MDN_to = substr($read[1], strpos($read[1], ' ')); + $MDN_flag_present = false; + + $read = sqimap_run_command ($imapConnection, "FETCH $passed_id FLAGS", true, + $response, $readmessage); + $str = strtolower($read[0]); + if (ereg('mdnsent', $str ) ) { + $MDN_flag_present = true; + } + if (trim($MDN_to) && + (!isset( $sendreceipt ) || $sendreceipt == '' ) ) { + + if ( $MDN_flag_present && $supportMDN) { + $sendreceipt="removeMDN"; + $url = "\"read_body.php?mailbox=$mailbox&passed_id=$passed_id&startMessage=$startMessage&show_more=$show_more&sendreceipt=$sendreceipt\""; + $sendreceipt=""; + if ($debug ) { + echo '' . + "' . + '' . "\n"; + } else { + echo '' . + "' . + '' . "\n"; + } + + } // when deleted or draft flag is set don't offer to send a MDN response + else if ( ereg('Draft',$read[0] || ereg('Deleted',$read[0])) ) { + echo '' . + "' . + '' . "\n"; + } + // if no MDNsupport don't use the annoying popup messages + else if ( !$FirstTimeSee ) { + $sendreceipt = 'send'; + $url = "\"read_body.php?mailbox=$mailbox&passed_id=$passed_id&startMessage=$startMessage&show_more=$show_more&sendreceipt=$sendreceipt\""; + echo '' . + "' . + '' . "\n"; + $sendreceipt=''; + } + else { + $sendreceipt = 'send'; + $url = "\"read_body.php?mailbox=$mailbox&passed_id=$passed_id&startMessage=$startMessage&show_more=$show_more&sendreceipt=$sendreceipt\""; + if ($javascript_on) { + echo "' . "\n"; + } + echo '' . + "' . + '' . "\n"; + $sendreceipt = ''; + } + } + + if ( !isset( $sendreceipt ) ) { + } else if ( $sendreceipt == 'send' ) { + if ( !$MDN_flag_present) { + if (isset($identity) ) { + $final_recipient = getPref($data_dir, $username, 'email_address' . '0'); + } else $final_recipient = getPref($data_dir, $username, 'email_address'); + + $final_recipient = trim($final_recipient); + if ($final_recipient == '' ) { + $final_recipient = getPref($data_dir, $username, 'email_address'); + } + + if ( SendMDN( $MDN_to, $final_recipient ) > 0 && $supportMDN == true ) { + ToggleMDNflag ( true); + } + } + $sendreceipt = 'removeMDN'; + $url = "\"read_body.php?mailbox=$mailbox&passed_id=$passed_id&startMessage=$startMessage&show_more=$show_more&sendreceipt=$sendreceipt\""; + $sendreceipt=""; + + if ($debug && $supportMDN) { + echo " \n" . + " ' . "\n" . + ' ' . "\n"; + } else { + echo " \n" . + " ' . "\n" . + ' ' . "\n"; + } + } + elseif ($sendreceipt == 'removeMDN' ) { + ToggleMDNflag ( false ); + + $sendreceipt = 'send'; + $url = "\"read_body.php?mailbox=$mailbox&passed_id=$passed_id&startMessage=$startMessage&show_more=$show_more&sendreceipt=$sendreceipt\""; + echo ''. + "' . + '' . "\n"; + $sendreceipt = ''; + + } + } +} + do_hook('read_body_header'); + echo '
\n" . +echo "\n" . _("Subject:") . - " \n" . - " $subject \n" . - " \n" . + "$subject \n" . + "'. '
' . "\n" . +echo '
' . _("From:") . - ' ' . "\n" . - " $from_name \n" . - '
' . + "$from_name \n" . + '
' . "\n" . +echo '
' . "\n" . _("Date:") . - " \n" . - " $dateString \n" . - '
\n" . + "$dateString \n" . + '
\n" . +echo "
\n" . _("To:") . - ' ' . "\n" . - " $to_string \n" . - '
' . "\n" . + "$to_string \n" . + '
\n" . - ' Cc:' . "\n" . - " \n" . - " $cc_string \n" . - '
" . + 'Cc:' . + "" . + "$cc_string " . + '
\n" . - ' Bcc:' . "\n" . - " \n" . - " $bcc_string \n" . - '
" . + 'Bcc:' . + "" . + "$bcc_string " . + '
\n" . - " "._("Priority").": \n". - " \n" . - " $priority_string \n" . - "
" . + _("Priority") . ': '. + "" . + "$priority_string " . + '
\n" . - " "._("Mailer").": \n". - " \n" . - " $mailer \n" . - "
" . + _("Mailer") . ': '. + "" . + "$mailer " . + '
" . + _("Read receipt") . ': ' . + "" . + '' . + _("send") . + " [" . _("Remove MDN flag") . '] ' . + '
" . + _("Read receipt") . ': ' . + "" . + ''._("send").''. + '
" . + _("Read receipt") . ': '. + "" . + '' . _("requested") . "" . + '
" . + _("Read receipt") . ': ' . + "" . + '' . _("requested") . + "   [" . _("Send read receipt now") . "]" . + '
" . + _("Read receipt") . ': ' . + "" . + '' . _("requested") . "  " . '[' . + _("Send read receipt now") . '] ' ." \n" . + '
\n" . + " "._("Read receipt").": \n". + " \n" . + ' '._("send").''." " . '[' . _("Remove MDN flag") . '] ' . "\n" . + '
\n" . + " "._("Read receipt").": \n". + " \n" . + ' '._("send").''. "\n" . + '
" . + _("Read receipt") . ': ' . + "" . + '' . _("requested") . + "   [" . _("Send read receipt now") . "]" . + '
' . '
'; @@ -659,18 +956,18 @@ if (($attachment_common_show_images) && foreach ($attachment_common_show_images_list as $img) { $imgurl = '../src/download.php' . - '?' . + '?' . 'passed_id=' . urlencode($img['passed_id']) . '&mailbox=' . urlencode($mailbox) . '&passed_ent_id=' . urlencode($img['ent_id']) . '&absolute_dl=true'; echo "\n" . - " \n" . - " \n" . - " \n" . + '' . + '\n" . + "\n" . "
\n" . - " \n" . - "
' . + "\n" . + "
\n"; } -- 2.25.1