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

Ahmed ashihab at alcahest.com
Mon Apr 14 02:24:26 PDT 2003


Cleaned up versions attached...hope this fits the bill

Ahmed...


Quoting Jan Schneider sent on Sun 13 Apr 2003 15:34:49 BST

> Quoting Ahmed <ashihab at alcahest.com>:
>
> > 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
>
> This looks fine, though I'd rather not notify about every single spam
> reported message but rather something like "%d messages have been
> reported
> as spam" at the end of the foreach loop.
>
> > 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
>
> Loos fine too, but you should default prefs.php.dist to the old
> behaviour,
> marking drafts as seen.
>
> > Appologies if the coding style is a little off-standard
>
> The only thing that looks odd according to our coding standards is the
> indention. If you fix that and the above mentioned nits, I'll commit your
> patches.
>
>
-------------- next part --------------
*** /var/www/horde.old/imp/compose.php	Sun Apr 13 14:31:22 2003
--- ../compose.php	Mon Apr 14 00:53:49 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('unseen_drafts')) {
!             $append_flags = '\\Draft';
!         } else {
!             $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)) {
-------------- next part --------------
*** prefs.php.dist.ori	Mon Apr 14 01:10:26 2003
--- prefs.php.dist	Mon Apr 14 01:13:35 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', 'unseen_drafts'));
  
  if (isset($GLOBALS['conf']['compose']['allow_receipts']) &&
      $GLOBALS['conf']['compose']['allow_receipts']) {
***************
*** 925,930 ****
--- 925,938 ----
      'shared' => false,
      'type' => 'checkbox',
      'desc' => _("Automatically Bcc yourself when composing a message?"));
+ 
+ // save drafts as seen or unseen
+ $_prefs['unseen_drafts'] = array(
+     'value' => 0,
+     'locked' => false,
+     'shared' => false,
+     'type' => 'checkbox',
+     'desc' => _("Save drafts as unseen."));
  
  // End Message Composition preferences
  
-------------- next part --------------
*** /var/www/horde.old/imp/mailbox.php	Fri Apr 11 10:00:30 2003
--- mailbox.php	Mon Apr 14 00:36:22 2003
***************
*** 104,109 ****
--- 104,179 ----
      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;
+     }
+     /* we know we have at least 1 message */
+     $msg_count = 0;
+ 
+     foreach ($indices as $msgnum) {
+         /* Fetch the raw message contents (headers and complete body). */
+         $imp_contents = &new IMP_Contents($msgnum);
+         $raw_msg = $imp_contents->fullMessageText();
+ 
+         $msg_count++;
+ 
+         /* 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);
+     	}
+ 
+     	/* 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);
+ 	}
+     }
+ 
+     /* report what we done */
+     if (!empty($conf['spam']['program'])) {
+         if ($msg_count > 1) {
+             $notification->push($msg_count . _(" Messages have been reported as spam."), 'horde.message');
+         } else {
+             $notification->push(_("Message has been reported as spam.") . $msg_count , 'horde.message');
+         }
+     }
+ 
+     if (!empty($conf['spam']['email'])) {
+         if ($msg_count > 1) {
+             $notification->push($msg_count . _(" Messages has been reported as spam to your system administrator."), 'horde.message');
+         } else {
+             $notification->push(_("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;


More information about the imp mailing list