[imp] "Report as spam" link on mailbox listing

Ahmed ashihab at alcahest.com
Sun Apr 13 15:39:15 PDT 2003


Thanks Jan,

I've attached the following patches which seems to work locally for us, they
are against latest HEAD.

mailbox.php.patch -> /horde/imp/mailbox.php
actions.inc.patch -> /horde/imp/templates/mailbox.inc

somewhat unrelated patches for adding drafts as either seen or not (under
user control from prefs, default to imp "seen" convention). Has been
working locally for months.

compose.php.patch -> /horde/imp/compose.php
pref.php.dist.patch -> /horde/imp/config/prefs.php.dist

Appologies if the coding style is a little off-standard

Ahmed...


Quoting Jan Schneider sent on Sun 13 Apr 2003 11:55:41 BST
>
> Compare how the blacklist action is handled in mailbox.php and
> message.php.
> Something similar should be applied for a spamreport action in
> mailbox.php.
-------------- next part --------------
*** /var/www/horde.old/imp/mailbox.php	Fri Apr 11 10:00:30 2003
--- mailbox.php	Sun Apr 13 14:03:26 2003
***************
*** 104,109 ****
--- 104,161 ----
      IMP_Filter::whitelistMessage($indices);
      break;
  
+ case SPAM_REPORT:
+     require_once IMP_BASE . '/lib/Contents.php';
+ 
+     /* Abort immediately if spam reporting has not been enabled. */
+     if (!$conf['spam']['reporting']) {
+         break;
+     }
+ 
+     foreach ($indices as $msgnum) {
+     	/* Fetch the raw message contents (headers and complete body). */
+     	$imp_contents = &new IMP_Contents($msgnum);
+     	$raw_msg = $imp_contents->fullMessageText();
+ 
+     	/* If a spam reporting program has been provided, use it. */
+     	if (!empty($conf['spam']['program'])) {
+         	/* Use a pipe to write the message contents. This should be secure. */
+        		$pipe = popen($conf['spam']['program'], 'w');
+         	fwrite($pipe, $raw_msg);
+         	pclose($pipe);
+ 
+         	$notification->push(_("This message has been reported as spam."), 'horde.message');
+     	}
+ 
+     	/* If a spam reporting email address has been provided, use it. */
+     	if (!empty($conf['spam']['email'])) {
+         	require_once HORDE_BASE . '/lib/MIME/Message.php';
+         	require_once HORDE_BASE . '/lib/MIME/Part.php';
+         	require_once IMP_BASE . '/lib/Compose.php';
+ 
+         	/* Initialize the user's identities */
+         	$user_identity = &Identity::singleton(array('imp', 'imp'));
+ 
+         	/* Build the MIME structure. */
+         	$mime = &new MIME_Message();
+         	$mime->setType('multipart/digest');
+         	$mime->addPart(new MIME_Part('message/rfc822', $raw_msg));
+ 
+         	$spam_headers = &new IMP_Headers();
+         	$spam_headers->addMessageIdHeader();
+         	$spam_headers->addHeader('Date', date('r'));
+         	$spam_headers->addHeader('To', $conf['spam']['email']);
+         	$spam_headers->addHeader('From', $user_identity->getFromLine());
+         	$spam_headers->addHeader('Subject', _("Spam Report from") . ' ' . $imp['user']);
+         	$spam_headers->addMIMEHeaders($mime);
+ 
+         	/* Send the message. */
+         	IMP_Compose::sendMessage($conf['spam']['email'], $spam_headers, $mime);
+         	$notification->push(_("This message has been reported as spam to your system administrator."), 'horde.message');
+ 	}
+     }
+     break;
+ 
  case MESSAGE_MISSING:
      $notification->push(_("There was an error viewing the requested message."), 'horde.error');
      break;
-------------- next part --------------
*** actions.inc	Sun Apr 13 14:19:17 2003
--- /var/www/horde/imp/templates/mailbox/actions.inc	Sun Apr 13 14:23:28 2003
***************
*** 19,24 ****
--- 19,27 ----
  <?php endif; ?>
  <?php endif; ?>
      | <?php echo Horde::widget('', _("Forward"), 'widget', '', 'Submit(' . FWD_DIGEST . '); return false;', _("Forward")) ?>
+ <?php if (isset($conf['spam']['reporting'])): ?>
+  | <?php echo Horde::widget('', _("Report as Spam"), 'widget', '', 'Submit(' . SPAM_REPORT . '); return false;', _("Report as Spam")); ?>
+ <?php endif; ?>
      </td>
      <td align="right">
  <?php if ($showdelete): ?>
-------------- next part --------------
*** compose.php	Sun Apr 13 14:31:22 2003
--- /var/www/horde/imp/compose.php	Sun Apr  6 19:54:24 2003
***************
*** 855,861 ****
          $body = preg_replace("|([^\r])\n|", "\\1\r\n", $body);
          $body = str_replace("\n\n", "\n\r\n", $body);
  
!         $append_flags = '\\Draft \\Seen';
          if ($imp_folder->exists($imp['stream'], $drafts_folder) ||
              $imp_folder->create($imp['stream'], $drafts_folder, $prefs->getValue('subscribe'))) {
              if (!@imap_append($imp['stream'], IMP::serverString() . $drafts_folder, $body, $append_flags)) {
--- 855,865 ----
          $body = preg_replace("|([^\r])\n|", "\\1\r\n", $body);
          $body = str_replace("\n\n", "\n\r\n", $body);
  
!         if ($prefs->getValue('seen_drafts')) {
!                  $append_flags = '\\Draft \\Seen';
!          } else {
!                  $append_flags = '\\Draft';
!          }
          if ($imp_folder->exists($imp['stream'], $drafts_folder) ||
              $imp_folder->create($imp['stream'], $drafts_folder, $prefs->getValue('subscribe'))) {
              if (!@imap_append($imp['stream'], IMP::serverString() . $drafts_folder, $body, $append_flags)) {
-------------- next part --------------
*** prefs.php.dist.ori	Sun Apr 13 14:27:25 2003
--- prefs.php.dist	Sun Apr 13 14:29:25 2003
***************
*** 113,119 ****
                         'attrib_text', 'compose_popup', 'compose_html',
                         'compose_confirm', 'folderselect', 'reply_headers',
                         'close_draft', 'set_priority', 'sending_charset',
!                        'encryptselect', 'self_bcc'));
  
  if (isset($GLOBALS['conf']['compose']['allow_receipts']) &&
      $GLOBALS['conf']['compose']['allow_receipts']) {
--- 113,119 ----
                         'attrib_text', 'compose_popup', 'compose_html',
                         'compose_confirm', 'folderselect', 'reply_headers',
                         'close_draft', 'set_priority', 'sending_charset',
!                        'encryptselect', 'self_bcc', 'seen_drafts'));
  
  if (isset($GLOBALS['conf']['compose']['allow_receipts']) &&
      $GLOBALS['conf']['compose']['allow_receipts']) {
***************
*** 881,886 ****
--- 881,894 ----
      'locked' => false,
      'shared' => false,
      'type' => 'implicit');
+ 
+ // save drafts as seen or unseen
+ $_prefs['seen_drafts'] = array(
+     'value' => 0,
+     'locked' => false,
+     'shared' => false,
+     'type' => 'checkbox',
+     'desc' => _("Save Drafts as seen."));
  
  // closing window after saving a draft?
  $_prefs['close_draft'] = array(


More information about the imp mailing list