diff options
author | Hugues Hiegel <hugues@hiegel.fr> | 2013-09-12 11:35:26 +0200 |
---|---|---|
committer | Hugues Hiegel <root@paranoid> | 2013-11-08 17:40:16 +0100 |
commit | 31de4bc5ebf9556817554ae9630ca06e92fd7218 (patch) | |
tree | f98afd42b6f4f818b3f4c489b2e6a7b3912dbb93 /plugins/markasjunk2 | |
parent | ef14bd0d8d58ae0f57aa1969e31a5373aa441dba (diff) |
Updates / Plugins
Diffstat (limited to 'plugins/markasjunk2')
41 files changed, 1598 insertions, 0 deletions
diff --git a/plugins/markasjunk2/config.inc.php.dist b/plugins/markasjunk2/config.inc.php.dist new file mode 100644 index 000000000..7cfcfd5ea --- /dev/null +++ b/plugins/markasjunk2/config.inc.php.dist @@ -0,0 +1,152 @@ +<?php + +/** + * MarkAsJunk2 configuration file + */ + +// Learning driver +// Use an external process such as sa-learn to learn from spam/ham messages. Default: null. +// Please see the README for more information +$rcmail_config['markasjunk2_learning_driver'] = null; + +// Ham mailbox +// Mailbox messages should be moved to when they are marked as ham. null = INBOX +// set to FALSE to disable message moving +$rcmail_config['markasjunk2_ham_mbox'] = null; + +// Spam mailbox +// Mailbox messages should be moved to when they are marked as spam. +// null = the mailbox assigned as the spam folder in Roundcube settings +// set to FALSE to disable message moving +$rcmail_config['markasjunk2_spam_mbox'] = null; + +// Mark messages as read when reporting them as spam +$rcmail_config['markasjunk2_read_spam'] = true; + +// Mark messages as unread when reporting them as ham +$rcmail_config['markasjunk2_unread_ham'] = false; + +// Add flag to messages marked as spam (flag will be removed when marking as ham) +// If you do not want to use message flags set this to null +$rcmail_config['markasjunk2_spam_flag'] = 'Junk'; + +// Add flag to messages marked as ham (flag will be removed when marking as spam) +// If you do not want to use message flags set this to null +$rcmail_config['markasjunk2_ham_flag'] = null; + +// Write output from spam/ham commands to the log for debug +$rcmail_config['markasjunk2_debug'] = false; + +// Show icon on mailbox toolbar +// The mark as spam/ham icon can either be displayed on the toolbar or as part of the mark messages menu +$rcmail_config['markasjunk2_mb_toolbar'] = true; + +// Show icon on compose toolbar +// The mark as spam/ham icon can either be displayed on the toolbar or as part of the mark messages menu +$rcmail_config['markasjunk2_cp_toolbar'] = true; + +// Learn any message moved to the spam mailbox as spam (not just when the button is pressed) +$rcmail_config['markasjunk2_move_spam'] = false; + +// Learn any message moved from the spam mailbox to the ham mailbox as ham (not just when the button is pressed) +$rcmail_config['markasjunk2_move_ham'] = false; + +// cmd_learn Driver options +// ------------------------ +// The command used to learn that a message is spam +// The command can contain the following macros that will be expanded as follows: +// %u is replaced with the username (from the session info) +// %l is replaced with the local part of the username (if the username is an email address) +// %d is replaced with the domain part of the username (if the username is an email address or default mail domain if not) +// %i is replaced with the email address from the user's default identity +// %xds is replaced with the X-DSPAM-Signature header +// %f is replaced with the path to the message file +// If you do not want run the command set this to null +$rcmail_config['markasjunk2_spam_cmd'] = null; + +// The command used to learn that a message is ham +// The command can contain the following macros that will be expanded as follows: +// %u is replaced with the username (from the session info) +// %l is replaced with the local part of the username (if the username is an email address) +// %d is replaced with the domain part of the username (if the username is an email address or default mail domain if not) +// %i is replaced with the email address from the user's default identity +// %xds is replaced with the X-DSPAM-Signature header +// %f is replaced with the path to the message file +// If you do not want run the command set this to null +$rcmail_config['markasjunk2_ham_cmd'] = null; + +// dir_learn Driver options +// ------------------------ +// The full path of the directory used to store spam (must be writable by webserver) +$rcmail_config['markasjunk2_spam_dir'] = null; + +// The full path of the directory used to store ham (must be writable by webserver) +$rcmail_config['markasjunk2_ham_dir'] = null; + +// The filename prefix +// The filename can contain the following macros that will be expanded as follows: +// %u is replaced with the username (from the session info) +// %l is replaced with the local part of the username (if the username is an email address) +// %d is replaced with the domain part of the username (if the username is an email address or default mail domain if not) +// %t is replaced with the type of message (spam/ham) +$rcmail_config['markasjunk2_filename'] = null; + +// email_learn Driver options +// -------------------------- +// The email address that spam messages will be sent to +// The address can contain the following macros that will be expanded as follows: +// %u is replaced with the username (from the session info) +// %l is replaced with the local part of the username (if the username is an email address) +// %d is replaced with the domain part of the username (if the username is an email address or default mail domain if not) +// %i is replaced with the email address from the user's default identity +// If you do not want to send an email set this to null +$rcmail_config['markasjunk2_email_spam'] = null; + +// The email address that ham messages will be sent to +// The address can contain the following macros that will be expanded as follows: +// %u is replaced with the username (from the session info) +// %l is replaced with the local part of the username (if the username is an email address) +// %d is replaced with the domain part of the username (if the username is an email address or default mail domain if not) +// %i is replaced with the email address from the user's default identity +// If you do not want to send an email set this to null +$rcmail_config['markasjunk2_email_ham'] = null; + +// Should the spam/ham message be sent as an attachment +$rcmail_config['markasjunk2_email_attach'] = true; + +// The email subject (when sending as attachment) +// The subject can contain the following macros that will be expanded as follows: +// %u is replaced with the username (from the session info) +// %l is replaced with the local part of the username (if the username is an email address) +// %d is replaced with the domain part of the username (if the username is an email address or default mail domain if not) +// %t is replaced with the type of message (spam/ham) +$rcmail_config['markasjunk2_email_subject'] = 'learn this message as %t'; + +// sa_blacklist Driver options +// --------------------------- +// Path to SAUserPrefs config file +$rcmail_config['markasjunk2_sauserprefs_config'] = '../sauserprefs/config.inc.php'; + +// edit_headers Driver options +// --------------------------- +// Patterns to match and replace headers for spam messages +// Replacement method uses preg_replace - http://www.php.net/manual/function.preg-replace.php +// WARNING: Be sure to match the entire header line, including the name of the header, also use ^ and $ and the 'm' flag +// see the README for an example +// TEST CAREFULLY BEFORE USE ON REAL MESSAGES +$rcmail_config['markasjunk2_spam_patterns'] = array( + 'patterns' => array(), + 'replacements' => array() + ); + +// Patterns to match and replace headers for spam messages +// Replacement method uses preg_replace - http://www.php.net/manual/function.preg-replace.php +// WARNING: Be sure to match the entire header line, including the name of the header, also use ^ and $ and the 'm' flag +// see the README for an example +// TEST CAREFULLY BEFORE USE ON REAL MESSAGES +$rcmail_config['markasjunk2_ham_patterns'] = array( + 'patterns' => array(), + 'replacements' => array() + ); + +?>
\ No newline at end of file diff --git a/plugins/markasjunk2/drivers/cmd_learn.php b/plugins/markasjunk2/drivers/cmd_learn.php new file mode 100644 index 000000000..f27adc1d1 --- /dev/null +++ b/plugins/markasjunk2/drivers/cmd_learn.php @@ -0,0 +1,74 @@ +<?php + +/** + * Command line learn driver + * @version 2.0 + * @author Philip Weir + * Patched by Julien Vehent to support DSPAM + * Enhanced support for DSPAM by Stevan Bajic <stevan@bajic.ch> + */ + +class markasjunk2_cmd_learn +{ + public function spam($uids) + { + $this->_do_salearn($uids, true); + } + + public function ham($uids) + { + $this->_do_salearn($uids, false); + } + + private function _do_salearn($uids, $spam) + { + $rcmail = rcube::get_instance(); + $temp_dir = realpath($rcmail->config->get('temp_dir')); + + if ($spam) + $command = $rcmail->config->get('markasjunk2_spam_cmd'); + else + $command = $rcmail->config->get('markasjunk2_ham_cmd'); + + if (!$command) + return; + + $command = str_replace('%u', $_SESSION['username'], $command); + $command = str_replace('%l', $rcmail->user->get_username('local'), $command); + $command = str_replace('%d', $rcmail->user->get_username('domain'), $command); + if (preg_match('/%i/', $command)) { + $identity_arr = $rcmail->user->get_identity(); + $command = str_replace('%i', $identity_arr['email'], $command); + } + + foreach (explode(",", $uids) as $uid) { + // get DSPAM signature from header (if %xds macro is used) + if (preg_match('/%xds/', $command)) { + if (preg_match('/^X\-DSPAM\-Signature:\s+((\d+,)?([a-f\d]+))\s*$/im', $rcmail->storage->get_raw_headers($uid), $dspam_signature)) + $tmp_command = str_replace('%xds', $dspam_signature[1], $command); + else + continue; // no DSPAM signature found in headers -> continue with next uid/message + } + + if (preg_match('/%f/', $command)) { + $tmpfname = tempnam($temp_dir, 'rcmSALearn'); + file_put_contents($tmpfname, $rcmail->storage->get_raw_body($uid)); + $tmp_command = str_replace('%f', $tmpfname, $command); + } + + exec($tmp_command, $output); + + if ($rcmail->config->get('markasjunk2_debug')) { + rcube::write_log('markasjunk2', $tmp_command); + rcube::write_log('markasjunk2', $output); + } + + if (preg_match('/%f/', $command)) + unlink($tmpfname); + + $output = ''; + } + } +} + +?>
\ No newline at end of file diff --git a/plugins/markasjunk2/drivers/dir_learn.php b/plugins/markasjunk2/drivers/dir_learn.php new file mode 100644 index 000000000..88dc7e4eb --- /dev/null +++ b/plugins/markasjunk2/drivers/dir_learn.php @@ -0,0 +1,49 @@ +<?php + +/** + * Copy spam/ham messages to a direcotry for learning later + * @version 2.0 + * @author Philip Weir + */ + +class markasjunk2_dir_learn +{ + public function spam($uids) + { + $this->_do_messagemove($uids, true); + } + + public function ham($uids) + { + $this->_do_messagemove($uids, false); + } + + private function _do_messagemove($uids, $spam) + { + $rcmail = rcube::get_instance(); + + if ($spam) + $dest_dir = unslashify($rcmail->config->get('markasjunk2_spam_dir')); + else + $dest_dir = unslashify($rcmail->config->get('markasjunk2_ham_dir')); + + if (!$dest_dir) + return; + + $filename = $rcmail->config->get('markasjunk2_filename'); + $filename = str_replace('%u', $_SESSION['username'], $filename); + $filename = str_replace('%t', ($spam) ? 'spam' : 'ham', $filename); + $filename = str_replace('%l', $rcmail->user->get_username('local'), $filename); + $filename = str_replace('%d', $rcmail->user->get_username('domain'), $filename); + + foreach (explode(",", $uids) as $uid) { + $tmpfname = tempnam($dest_dir, $filename); + file_put_contents($tmpfname, $rcmail->storage->get_raw_body($uid)); + + if ($rcmail->config->get('markasjunk2_debug')) + rcube::write_log('markasjunk2', $tmpfname); + } + } +} + +?>
\ No newline at end of file diff --git a/plugins/markasjunk2/drivers/edit_headers.php b/plugins/markasjunk2/drivers/edit_headers.php new file mode 100644 index 000000000..9ee71ff79 --- /dev/null +++ b/plugins/markasjunk2/drivers/edit_headers.php @@ -0,0 +1,53 @@ +<?php + +/** + * Edit headers + * @version 1.0 + * @author Philip Weir + */ + +class markasjunk2_edit_headers +{ + public function spam(&$uids) + { + $this->_edit_headers($uids, true); + } + + public function ham(&$uids) + { + $this->_edit_headers($uids, false); + } + + private function _edit_headers(&$uids, $spam) + { + $rcmail = rcube::get_instance(); + $args = $spam ? $rcmail->config->get('markasjunk2_spam_patterns') : $rcmail->config->get('markasjunk2_ham_patterns'); + + if (sizeof($args['patterns']) == 0) + return; + + $mbox = rcube_utils::get_input_value('_mbox', rcube_utils::INPUT_POST); + + $new_uids = array(); + foreach (explode(",", $uids) as $uid) { + $raw_message = $rcmail->storage->get_raw_body($uid); + $raw_headers = $rcmail->storage->get_raw_headers($uid); + + $updated_headers = preg_replace($args['patterns'], $args['replacements'], $raw_headers); + $raw_message = str_replace($raw_headers, $updated_headers, $raw_message); + + $saved = $rcmail->storage->save_message($mbox, $raw_message); + + if ($saved !== false) { + $rcmail->output->command('rcmail_markasjunk2_move', null, $uid); + array_push($new_uids, $saved); + } + + } + + if (sizeof($new_uids) > 0) + $uids = implode(',', $new_uids); + } +} + +?>
\ No newline at end of file diff --git a/plugins/markasjunk2/drivers/email_learn.php b/plugins/markasjunk2/drivers/email_learn.php new file mode 100644 index 000000000..b7f9f87ea --- /dev/null +++ b/plugins/markasjunk2/drivers/email_learn.php @@ -0,0 +1,191 @@ +<?php + +/** + * Email learn driver + * @version 2.0 + * @author Philip Weir + */ + +class markasjunk2_email_learn +{ + public function spam($uids) + { + $this->_do_emaillearn($uids, true); + } + + public function ham($uids) + { + $this->_do_emaillearn($uids, false); + } + + private function _do_emaillearn($uids, $spam) + { + $rcmail = rcube::get_instance(); + $identity_arr = $rcmail->user->get_identity(); + $from = $identity_arr['email']; + + if ($spam) + $mailto = $rcmail->config->get('markasjunk2_email_spam'); + else + $mailto = $rcmail->config->get('markasjunk2_email_ham'); + + $mailto = str_replace('%u', $_SESSION['username'], $mailto); + $mailto = str_replace('%l', $rcmail->user->get_username('local'), $mailto); + $mailto = str_replace('%d', $rcmail->user->get_username('domain'), $mailto); + $mailto = str_replace('%i', $from, $mailto); + + if (!$mailto) + return; + + $message_charset = $rcmail->output->get_charset(); + // chose transfer encoding + $charset_7bit = array('ASCII', 'ISO-2022-JP', 'ISO-8859-1', 'ISO-8859-2', 'ISO-8859-15'); + $transfer_encoding = in_array(strtoupper($message_charset), $charset_7bit) ? '7bit' : '8bit'; + + $temp_dir = realpath($rcmail->config->get('temp_dir')); + + $subject = $rcmail->config->get('markasjunk2_email_subject'); + $subject = str_replace('%u', $_SESSION['username'], $subject); + $subject = str_replace('%t', ($spam) ? 'spam' : 'ham', $subject); + $subject = str_replace('%l', $rcmail->user->get_username('local'), $subject); + $subject = str_replace('%d', $rcmail->user->get_username('domain'), $subject); + + // compose headers array + $headers = array(); + $headers['Date'] = date('r'); + $headers['From'] = format_email_recipient($identity_arr['email'], $identity_arr['name']); + $headers['To'] = $mailto; + $headers['Subject'] = $subject; + + foreach (explode(",", $uids) as $uid) { + $MESSAGE = new rcube_message($uid); + + // set message charset as default + if (!empty($MESSAGE->headers->charset)) + $rcmail->storage->set_charset($MESSAGE->headers->charset); + + $MAIL_MIME = new Mail_mime($rcmail->config->header_delimiter()); + + if ($rcmail->config->get('markasjunk2_email_attach', false)) { + $tmpPath = tempnam($temp_dir, 'rcmMarkASJunk2'); + + // send mail as attachment + $MAIL_MIME->setTXTBody(($spam ? 'Spam' : 'Ham'). ' report from ' . $rcmail->config->get('product_name'), false, true); + + $raw_message = $rcmail->storage->get_raw_body($uid); + $subject = $MESSAGE->get_header('subject'); + + if (isset($subject) && $subject !="") + $disp_name = $subject . ".eml"; + else + $disp_name = "message_rfc822.eml"; + + if (file_put_contents($tmpPath, $raw_message)) { + $MAIL_MIME->addAttachment($tmpPath, "message/rfc822", $disp_name, true, + $transfer_encoding, 'attachment', '', '', '', + $rcmail->config->get('mime_param_folding') ? 'quoted-printable' : NULL, + $rcmail->config->get('mime_param_folding') == 2 ? 'quoted-printable' : NULL, + '', RCUBE_CHARSET + ); + } + + // encoding settings for mail composing + $MAIL_MIME->setParam('text_encoding', $transfer_encoding); + $MAIL_MIME->setParam('html_encoding', 'quoted-printable'); + $MAIL_MIME->setParam('head_encoding', 'quoted-printable'); + $MAIL_MIME->setParam('head_charset', $message_charset); + $MAIL_MIME->setParam('html_charset', $message_charset); + $MAIL_MIME->setParam('text_charset', $message_charset); + + // pass headers to message object + $MAIL_MIME->headers($headers); + } + else { + $headers['Resent-From'] = $headers['From']; + $headers['Resent-Date'] = $headers['Date']; + $headers['Date'] = $MESSAGE->headers->date; + $headers['From'] = $MESSAGE->headers->from; + $headers['Subject'] = $MESSAGE->headers->subject; + $MAIL_MIME->headers($headers); + + if ($MESSAGE->has_html_part()) { + $body = $MESSAGE->first_html_part(); + $MAIL_MIME->setHTMLBody($body); + } + + $body = $MESSAGE->first_text_part(); + $MAIL_MIME->setTXTBody($body, false, true); + + foreach ($MESSAGE->attachments as $attachment) { + $MAIL_MIME->addAttachment( + $MESSAGE->get_part_content($attachment->mime_id), + $attachment->mimetype, + $attachment->filename, + false, + $attachment->encoding, + $attachment->disposition, + '', $attachment->charset + ); + } + + foreach ($MESSAGE->mime_parts as $attachment) { + if (!empty($attachment->content_id)) { + // covert CID to Mail_MIME format + $attachment->content_id = str_replace('<', '', $attachment->content_id); + $attachment->content_id = str_replace('>', '', $attachment->content_id); + + if (empty($attachment->filename)) + $attachment->filename = $attachment->content_id; + + $message_body = $MAIL_MIME->getHTMLBody(); + $dispurl = 'cid:' . $attachment->content_id; + $message_body = str_replace($dispurl, $attachment->filename, $message_body); + $MAIL_MIME->setHTMLBody($message_body); + + $MAIL_MIME->addHTMLImage( + $MESSAGE->get_part_content($attachment->mime_id), + $attachment->mimetype, + $attachment->filename, + false + ); + } + } + + // encoding settings for mail composing + $MAIL_MIME->setParam('head_encoding', $MESSAGE->headers->encoding); + $MAIL_MIME->setParam('head_charset', $MESSAGE->headers->charset); + + foreach ($MESSAGE->mime_parts as $mime_id => $part) { + $mimetype = strtolower($part->ctype_primary . '/' . $part->ctype_secondary); + + if ($mimetype == 'text/html') { + $MAIL_MIME->setParam('text_encoding', $part->encoding); + $MAIL_MIME->setParam('html_charset', $part->charset); + } + else if ($mimetype == 'text/plain') { + $MAIL_MIME->setParam('html_encoding', $part->encoding); + $MAIL_MIME->setParam('text_charset', $part->charset); + } + } + } + + $rcmail->rcmail_deliver_message($MAIL_MIME, $from, $mailto, $smtp_error, $body_file); + + // clean up + if (file_exists($tmpPath)) + unlink($tmpPath); + + if ($rcmail->config->get('markasjunk2_debug')) { + if ($spam) + rcube::write_log('markasjunk2', $uid . ' SPAM ' . $mailto . ' (' . $subject . ')'); + else + rcube::write_log('markasjunk2', $uid . ' HAM ' . $mailto . ' (' . $subject . ')'); + + if ($smtp_error['vars']) + rcube::write_log('markasjunk2', $smtp_error['vars']); + } + } + } +} + +?>
\ No newline at end of file diff --git a/plugins/markasjunk2/drivers/sa_blacklist.php b/plugins/markasjunk2/drivers/sa_blacklist.php new file mode 100644 index 000000000..dd2ce6bc7 --- /dev/null +++ b/plugins/markasjunk2/drivers/sa_blacklist.php @@ -0,0 +1,103 @@ +<?php + +/** + * SpamAssassin Blacklist driver + * @version 2.0 + * @requires SAUserPrefs plugin + * @author Philip Weir + */ + +class markasjunk2_sa_blacklist +{ + public function spam($uids) + { + $this->_do_list($uids, true); + } + + public function ham($uids) + { + $this->_do_list($uids, false); + } + + private function _do_list($uids, $spam) + { + $rcmail = rcube::get_instance(); + if (is_file($rcmail->config->get('markasjunk2_sauserprefs_config')) && !$rcmail->config->load_from_file($rcmail->config->get('markasjunk2_sauserprefs_config'))) { + rcube::raise_error(array('code' => 527, 'type' => 'php', + 'file' => __FILE__, 'line' => __LINE__, + 'message' => "Failed to load config from " . $rcmail->config->get('markasjunk2_sauserprefs_config')), true, false); + return false; + } + + $db = rcube_db::factory($rcmail->config->get('sauserprefs_db_dsnw'), $rcmail->config->get('sauserprefs_db_dsnr'), $rcmail->config->get('sauserprefs_db_persistent')); + $db->db_connect('w'); + + // check DB connections and exit on failure + if ($err_str = $db->is_error()) { + rcube::raise_error(array( + 'code' => 603, + 'type' => 'db', + 'message' => $err_str), FALSE, TRUE); + } + + foreach (explode(",", $uids) as $uid) { + $message = new rcube_message($uid); + $email = $message->sender['mailto']; + + if ($spam) { + // delete any whitelisting for this address + $db->query( + "DELETE FROM ". $rcmail->config->get('sauserprefs_sql_table_name') ." WHERE ". $rcmail->config->get('sauserprefs_sql_username_field') ." = ? AND ". $rcmail->config->get('sauserprefs_sql_preference_field') ." = ? AND ". $rcmail->config->get('sauserprefs_sql_value_field') ." = ?;", + $_SESSION['username'], + 'whitelist_from', + $email); + + // check address is not already blacklisted + $sql_result = $db->query( + "SELECT value FROM ". $rcmail->config->get('sauserprefs_sql_table_name') ." WHERE ". $rcmail->config->get('sauserprefs_sql_username_field') ." = ? AND ". $rcmail->config->get('sauserprefs_sql_preference_field') ." = ? AND ". $rcmail->config->get('sauserprefs_sql_value_field') ." = ?;", + $_SESSION['username'], + 'blacklist_from', + $email); + + if (!$db->fetch_array($sql_result)) { + $db->query( + "INSERT INTO ". $rcmail->config->get('sauserprefs_sql_table_name') ." (". $rcmail->config->get('sauserprefs_sql_username_field') .", ". $rcmail->config->get('sauserprefs_sql_preference_field') .", ". $rcmail->config->get('sauserprefs_sql_value_field') .") VALUES (?, ?, ?);", + $_SESSION['username'], + 'blacklist_from', + $email); + + if ($rcmail->config->get('markasjunk2_debug')) + rcube::write_log('markasjunk2', $_SESSION['username'] . ' blacklist ' . $email); + } + } + else { + // delete any blacklisting for this address + $db->query( + "DELETE FROM ". $rcmail->config->get('sauserprefs_sql_table_name') ." WHERE ". $rcmail->config->get('sauserprefs_sql_username_field') ." = ? AND ". $rcmail->config->get('sauserprefs_sql_preference_field') ." = ? AND ". $rcmail->config->get('sauserprefs_sql_value_field') ." = ?;", + $_SESSION['username'], + 'blacklist_from', + $email); + + // check address is not already whitelisted + $sql_result = $db->query( + "SELECT value FROM ". $rcmail->config->get('sauserprefs_sql_table_name') ." WHERE ". $rcmail->config->get('sauserprefs_sql_username_field') ." = ? AND ". $rcmail->config->get('sauserprefs_sql_preference_field') ." = ? AND ". $rcmail->config->get('sauserprefs_sql_value_field') ." = ?;", + $_SESSION['username'], + 'whitelist_from', + $email); + + if (!$db->fetch_array($sql_result)) { + $db->query( + "INSERT INTO ". $rcmail->config->get('sauserprefs_sql_table_name') ." (". $rcmail->config->get('sauserprefs_sql_username_field') .", ". $rcmail->config->get('sauserprefs_sql_preference_field') .", ". $rcmail->config->get('sauserprefs_sql_value_field') .") VALUES (?, ?, ?);", + $_SESSION['username'], + 'whitelist_from', + $email); + + if ($rcmail->config->get('markasjunk2_debug')) + rcube::write_log('markasjunk2', $_SESSION['username'] . ' whitelist ' . $email); + } + } + } + } +} + +?>
\ No newline at end of file diff --git a/plugins/markasjunk2/drivers/sa_detach.php b/plugins/markasjunk2/drivers/sa_detach.php new file mode 100644 index 000000000..947b4b8a7 --- /dev/null +++ b/plugins/markasjunk2/drivers/sa_detach.php @@ -0,0 +1,47 @@ +<?php + +/** + * SpamAssassin detach ham driver + * @version 2.0 + * @author Philip Weir + */ + +class markasjunk2_sa_detach +{ + public function spam($uids) + { + // do nothing + } + + public function ham(&$uids) + { + $rcmail = rcube::get_instance(); + $storage = $rcmail->storage; + $mbox = rcube_utils::get_input_value('_mbox', rcube_utils::INPUT_POST); + + $new_uids = array(); + foreach (explode(",", $uids) as $uid) { + $saved = false; + $message = new rcube_message($uid); + + if (sizeof($message->attachments) > 0) { + foreach ($message->attachments as $part) { + if ($part->ctype_primary == 'message' && $part->ctype_secondary == 'rfc822') { + $orig_message_raw = $storage->get_message_part($message->uid, $part->mime_id, $part); + $saved = $storage->save_message($mbox, $orig_message_raw); + + if ($saved !== false) { + $rcmail->output->command('rcmail_markasjunk2_move', null, $uid); + array_push($new_uids, $saved); + } + } + } + } + } + + if (sizeof($new_uids) > 0) + $uids = implode(',', $new_uids); + } +} + +?>
\ No newline at end of file diff --git a/plugins/markasjunk2/localization/ca_ES.inc b/plugins/markasjunk2/localization/ca_ES.inc new file mode 100644 index 000000000..2268cf76a --- /dev/null +++ b/plugins/markasjunk2/localization/ca_ES.inc @@ -0,0 +1,14 @@ +<?php +/* Author: Daniel López */ + +$labels = array(); +$labels['buttonjunk'] = 'Marca com a Spam'; +$labels['markasjunk'] = 'És Spam'; +$labels['buttonnotjunk'] = 'Aquest missatge no és Spam'; +$labels['markasnotjunk'] = 'No és Spam'; + +$messages = array(); +$messages['reportedasjunk'] = 'Reportat conrrectament com spam.'; +$messages['reportedasnotjunk'] = 'Missatge mogut a la safata d\'Entrada'; + +?>
\ No newline at end of file diff --git a/plugins/markasjunk2/localization/cs_CZ.inc b/plugins/markasjunk2/localization/cs_CZ.inc new file mode 100644 index 000000000..e9564a855 --- /dev/null +++ b/plugins/markasjunk2/localization/cs_CZ.inc @@ -0,0 +1,14 @@ +<?php +/* Author: Martin Frajdl */ + +$labels = array(); +$labels['buttonjunk'] = 'Oznacit jako spam'; +$labels['markasjunk'] = 'Jako spam'; +$labels['buttonnotjunk'] = 'Tato zpráva není spam'; +$labels['markasnotjunk'] = 'Nemí spam'; + +$messages = array(); +$messages['reportedasjunk'] = 'Úspešne hlášeny jako spam'; +$messages['reportedasnotjunk'] = 'Úspešne hlášeny jako spam'; + +?>
\ No newline at end of file diff --git a/plugins/markasjunk2/localization/de_CH.inc b/plugins/markasjunk2/localization/de_CH.inc new file mode 100644 index 000000000..71492b481 --- /dev/null +++ b/plugins/markasjunk2/localization/de_CH.inc @@ -0,0 +1,15 @@ +<?php +/* Author: Rrainer Rhalbmann */ + +$labels = array(); +$labels['buttonjunk'] = 'als Spam markieren'; +$labels['markasjunk'] = 'als Spam'; +$labels['buttonnotjunk'] = 'Diese Nachricht ist kein Spam'; +$labels['markasnotjunk'] = 'kein Spam'; +$labels['notjunk'] = 'kein Spam'; + +$messages = array(); +$messages['reportedasjunk'] = 'Erfolgreich als Spam gekennzeichnet'; +$messages['reportedasnotjunk'] = 'Nachricht in Posteingang verschoben'; + +?>
\ No newline at end of file diff --git a/plugins/markasjunk2/localization/de_DE.inc b/plugins/markasjunk2/localization/de_DE.inc new file mode 100644 index 000000000..71492b481 --- /dev/null +++ b/plugins/markasjunk2/localization/de_DE.inc @@ -0,0 +1,15 @@ +<?php +/* Author: Rrainer Rhalbmann */ + +$labels = array(); +$labels['buttonjunk'] = 'als Spam markieren'; +$labels['markasjunk'] = 'als Spam'; +$labels['buttonnotjunk'] = 'Diese Nachricht ist kein Spam'; +$labels['markasnotjunk'] = 'kein Spam'; +$labels['notjunk'] = 'kein Spam'; + +$messages = array(); +$messages['reportedasjunk'] = 'Erfolgreich als Spam gekennzeichnet'; +$messages['reportedasnotjunk'] = 'Nachricht in Posteingang verschoben'; + +?>
\ No newline at end of file diff --git a/plugins/markasjunk2/localization/en_GB.inc b/plugins/markasjunk2/localization/en_GB.inc new file mode 100644 index 000000000..e63548094 --- /dev/null +++ b/plugins/markasjunk2/localization/en_GB.inc @@ -0,0 +1,15 @@ +<?php +/* Author: Philip Weir */ + +$labels = array(); +$labels['buttonjunk'] = 'Mark as spam'; +$labels['markasjunk'] = 'As spam'; +$labels['buttonnotjunk'] = 'This message is not spam'; +$labels['markasnotjunk'] = 'As not spam'; +$labels['notjunk'] = 'Not spam'; + +$messages = array(); +$messages['reportedasjunk'] = 'Successfully reported as spam'; +$messages['reportedasnotjunk'] = 'Successfully reported as not spam'; + +?>
\ No newline at end of file diff --git a/plugins/markasjunk2/localization/en_US.inc b/plugins/markasjunk2/localization/en_US.inc new file mode 100644 index 000000000..b67fbedfb --- /dev/null +++ b/plugins/markasjunk2/localization/en_US.inc @@ -0,0 +1,15 @@ +<?php +/* Author: Philip Weir */ + +$labels = array(); +$labels['buttonjunk'] = 'Mark as junk'; +$labels['markasjunk'] = 'As junk'; +$labels['buttonnotjunk'] = 'This message is not junk'; +$labels['markasnotjunk'] = 'As not junk'; +$labels['notjunk'] = 'Not junk'; + +$messages = array(); +$messages['reportedasjunk'] = 'Successfully reported as junk'; +$messages['reportedasnotjunk'] = 'Successfully reported as not junk'; + +?>
\ No newline at end of file diff --git a/plugins/markasjunk2/localization/es_AR.inc b/plugins/markasjunk2/localization/es_AR.inc new file mode 100644 index 000000000..2095b0721 --- /dev/null +++ b/plugins/markasjunk2/localization/es_AR.inc @@ -0,0 +1,14 @@ +<?php +/* Author: Guillermo Asernitzky */ + +$labels = array(); +$labels['buttonjunk'] = 'Marcar como Spam'; +$labels['markasjunk'] = 'Como Spam'; +$labels['buttonnotjunk'] = 'Este mensaje no es Spam'; +$labels['markasnotjunk'] = 'No es Spam'; + +$messages = array(); +$messages['reportedasjunk'] = 'Reportado como Spam'; +$messages['reportedasnotjunk'] = 'Mensaje movido a la bandeja de entrada'; + +?>
\ No newline at end of file diff --git a/plugins/markasjunk2/localization/es_ES.inc b/plugins/markasjunk2/localization/es_ES.inc new file mode 100644 index 000000000..58388f227 --- /dev/null +++ b/plugins/markasjunk2/localization/es_ES.inc @@ -0,0 +1,14 @@ +<?php +/* Author: David Garabana Barro */ + +$labels = array(); +$labels['buttonjunk'] = 'Marcar como spam'; +$labels['markasjunk'] = 'Es spam'; +$labels['buttonnotjunk'] = 'Este mensaje no es spam'; +$labels['markasnotjunk'] = 'No es spam'; + +$messages = array(); +$messages['reportedasjunk'] = 'Reportado correctamente como spam.'; +$messages['reportedasnotjunk'] = 'Movido a la bandeja de entrada.'; + +?>
\ No newline at end of file diff --git a/plugins/markasjunk2/localization/fa_IR.inc b/plugins/markasjunk2/localization/fa_IR.inc new file mode 100644 index 000000000..1fd7b82ae --- /dev/null +++ b/plugins/markasjunk2/localization/fa_IR.inc @@ -0,0 +1,14 @@ +<?php +/* Author: KiarasH Mozafari */ + +$labels = array(); +$labels['buttonjunk'] = 'بنجل کن'; +$labels['markasjunk'] = 'بنجل'; +$labels['buttonnotjunk'] = 'این نامه بنجل نیست'; +$labels['markasnotjunk'] = 'بنجل نیست'; + +$messages = array(); +$messages['reportedasjunk'] = 'این نامه با موفقیت به صورت بنجل گزارش داده شد'; +$messages['reportedasnotjunk'] = 'نامه به صندق منتقل شد'; + +?>
\ No newline at end of file diff --git a/plugins/markasjunk2/localization/fr_FR.inc b/plugins/markasjunk2/localization/fr_FR.inc new file mode 100644 index 000000000..843f01242 --- /dev/null +++ b/plugins/markasjunk2/localization/fr_FR.inc @@ -0,0 +1,14 @@ +<?php +/* Author: */ + +$labels = array(); +$labels['buttonjunk'] = 'Marquer comme spam'; +$labels['markasjunk'] = 'Comme spam'; +$labels['buttonnotjunk'] = 'Ceci n\'est pas un spam'; +$labels['markasnotjunk'] = 'Comme acceptable'; + +$messages = array(); +$messages['reportedasjunk'] = 'Message classé en spam'; +$messages['reportedasnotjunk'] = 'Message déplacé dans Inbox'; + +?>
\ No newline at end of file diff --git a/plugins/markasjunk2/localization/gl_ES.inc b/plugins/markasjunk2/localization/gl_ES.inc new file mode 100644 index 000000000..b2b65e5d6 --- /dev/null +++ b/plugins/markasjunk2/localization/gl_ES.inc @@ -0,0 +1,14 @@ +<?php +/* Author: David Garabana Barro */ + +$labels = array(); +$labels['buttonjunk'] = 'Marcar coma correo lixo'; +$labels['markasjunk'] = 'É correo lixo'; +$labels['buttonnotjunk'] = 'Esta mensaxe non é correo lixo'; +$labels['markasnotjunk'] = 'Non é correo lixo'; + +$messages = array(); +$messages['reportedasjunk'] = 'Marcouse correctamente coma correo lixo '; +$messages['reportedasnotjunk'] = 'A mensaxe moveuse a caixa de entrada'; + +?>
\ No newline at end of file diff --git a/plugins/markasjunk2/localization/hu_HU.inc b/plugins/markasjunk2/localization/hu_HU.inc new file mode 100644 index 000000000..9f8ef1bbe --- /dev/null +++ b/plugins/markasjunk2/localization/hu_HU.inc @@ -0,0 +1,14 @@ +<?php +/* Author: Attila Sipos */ + +$labels = array(); +$labels['buttonjunk'] = 'Megkelölés levélszemétként'; +$labels['markasjunk'] = 'Levélszemétként'; +$labels['buttonnotjunk'] = 'Ez az üzenet nem levélszemét'; +$labels['markasnotjunk'] = 'Nem levélszemét'; + +$messages = array(); +$messages['reportedasjunk'] = 'Sikeresen jelentve, mint levélszemét'; +$messages['reportedasnotjunk'] = 'Az üzenet visszakerült a Érkezett levelekbe'; + +?>
\ No newline at end of file diff --git a/plugins/markasjunk2/localization/it_IT.inc b/plugins/markasjunk2/localization/it_IT.inc new file mode 100644 index 000000000..c7760d05e --- /dev/null +++ b/plugins/markasjunk2/localization/it_IT.inc @@ -0,0 +1,15 @@ +<?php +/* Author: Alessio Cecchi */ + +$labels = array(); +$labels['buttonjunk'] = 'Segnala come Spam'; +$labels['markasjunk'] = 'Spam'; +$labels['buttonnotjunk'] = 'Questo messaggiono non è Spam'; +$labels['markasnotjunk'] = 'Non Spam'; +$labels['notjunk'] = 'Non Spam'; + +$messages = array(); +$messages['reportedasjunk'] = 'Segnalato con successo come Spam'; +$messages['reportedasnotjunk'] = 'Messaggio spostato in Posta in arrivo'; + +?>
\ No newline at end of file diff --git a/plugins/markasjunk2/localization/lv_LV.inc b/plugins/markasjunk2/localization/lv_LV.inc new file mode 100644 index 000000000..738de15b1 --- /dev/null +++ b/plugins/markasjunk2/localization/lv_LV.inc @@ -0,0 +1,15 @@ +<?php +/* Author: Mārtiņš Dzērve */ + +$labels = array(); +$labels['buttonjunk'] = 'Atzīmēt mēstules'; +$labels['markasjunk'] = 'Kā mēstuli'; +$labels['buttonnotjunk'] = 'Atzīmēt ne-mēstules'; +$labels['markasnotjunk'] = 'Kā ne-mēstule'; +$labels['notjunk'] = 'Ne-mēstules'; + +$messages = array(); +$messages['reportedasjunk'] = 'Veiksmīgi ziņots par mēstuli'; +$messages['reportedasnotjunk'] = 'Veiksmīgi ziņots par ne-mēstuli'; + +?>
\ No newline at end of file diff --git a/plugins/markasjunk2/localization/nl_NL.inc b/plugins/markasjunk2/localization/nl_NL.inc new file mode 100644 index 000000000..4eb572901 --- /dev/null +++ b/plugins/markasjunk2/localization/nl_NL.inc @@ -0,0 +1,14 @@ +<?php +/* Author: Hans Spaans */ + +$labels = array(); +$labels['buttonjunk'] = 'Markeer als spam'; +$labels['markasjunk'] = 'Is spam'; +$labels['buttonnotjunk'] = 'Dit bericht is geen spam'; +$labels['markasnotjunk'] = 'Geen spam'; + +$messages = array(); +$messages['reportedasjunk'] = 'Bericht gemarkeerd als spam'; +$messages['reportedasnotjunk'] = 'Bericht verplaatst naar Inbox'; + +?>
\ No newline at end of file diff --git a/plugins/markasjunk2/localization/pl_PL.inc b/plugins/markasjunk2/localization/pl_PL.inc new file mode 100644 index 000000000..7cbe359c7 --- /dev/null +++ b/plugins/markasjunk2/localization/pl_PL.inc @@ -0,0 +1,15 @@ +<?php +/* Author: Bartosz Mierzwiak */ + +$labels = array(); +$labels['buttonjunk'] = 'Oznacz jako Spam'; +$labels['markasjunk'] = 'Jako Spam'; +$labels['buttonnotjunk'] = 'Ta wiadomość nie jest Spamem'; +$labels['markasnotjunk'] = 'Jako nie Spam'; +$labels['notjunk'] = 'Nie Spam'; + +$messages = array(); +$messages['reportedasjunk'] = 'Pomyślnie oznaczono jako Spam'; +$messages['reportedasnotjunk'] = 'Wiadomość przeniesiona do Odebranych'; + +?>
\ No newline at end of file diff --git a/plugins/markasjunk2/localization/pt_BR.inc b/plugins/markasjunk2/localization/pt_BR.inc new file mode 100644 index 000000000..cf62fc6c9 --- /dev/null +++ b/plugins/markasjunk2/localization/pt_BR.inc @@ -0,0 +1,14 @@ +<?php +/* Author: Arthur Furlan */ + +$labels = array(); +$labels['buttonjunk'] = 'Marcar como Spam'; +$labels['markasjunk'] = 'Spam'; +$labels['buttonnotjunk'] = 'Esta mensagem não é Spam'; +$labels['markasnotjunk'] = 'Não Spam'; + +$messages = array(); +$messages['reportedasjunk'] = 'Mensagem marcada como Spam com sucesso'; +$messages['reportedasnotjunk'] = 'Mensagem movida para a Caixa da Entrada'; + +?>
\ No newline at end of file diff --git a/plugins/markasjunk2/localization/ro_RO.inc b/plugins/markasjunk2/localization/ro_RO.inc new file mode 100644 index 000000000..13567a8b2 --- /dev/null +++ b/plugins/markasjunk2/localization/ro_RO.inc @@ -0,0 +1,14 @@ +<?php +/* Author: Ovidiu Bica */ + +$labels = array(); +$labels['buttonjunk'] = 'Marcheaza ca spam'; +$labels['markasjunk'] = 'Este Spam'; +$labels['buttonnotjunk'] = 'Acest mesaj nu este spam'; +$labels['markasnotjunk'] = 'Nu este spam'; + +$messages = array(); +$messages['reportedasjunk'] = 'Raportat cu succes ca Spam'; +$messages['reportedasnotjunk'] = 'Mesajul a fost mutat in Inbox'; + +?>
\ No newline at end of file diff --git a/plugins/markasjunk2/localization/ru_RU.inc b/plugins/markasjunk2/localization/ru_RU.inc new file mode 100644 index 000000000..e91f6a454 --- /dev/null +++ b/plugins/markasjunk2/localization/ru_RU.inc @@ -0,0 +1,15 @@ +<?php +/* Author: Peter Zotov */ + +$labels = array(); +$labels['buttonjunk'] = 'Пометить как спам'; +$labels['markasjunk'] = 'Как спам'; +$labels['buttonnotjunk'] = 'Это сообщение не спам'; +$labels['markasnotjunk'] = 'Не спам'; +$labels['notjunk'] = 'Не спам'; + +$messages = array(); +$messages['reportedasjunk'] = 'Помечено как спам'; +$messages['reportedasnotjunk'] = 'Сообщение перемещено во Входящие'; + +?>
\ No newline at end of file diff --git a/plugins/markasjunk2/localization/tr_TR.inc b/plugins/markasjunk2/localization/tr_TR.inc new file mode 100644 index 000000000..7da3f0a40 --- /dev/null +++ b/plugins/markasjunk2/localization/tr_TR.inc @@ -0,0 +1,14 @@ +<?php +/* Author: Mustafa Icer */ + +$labels = array(); +$labels['buttonjunk'] = 'Spam olarak işaretle'; +$labels['markasjunk'] = 'Spam olarak'; +$labels['buttonnotjunk'] = 'Bu mesaj Spam değildir'; +$labels['markasnotjunk'] = 'Spam değildir'; + +$messages = array(); +$messages['reportedasjunk'] = 'Başarıyla spam olarak bildirildi'; +$messages['reportedasnotjunk'] = 'Mesaj, gelen klasörüne taşındı'; + +?>
\ No newline at end of file diff --git a/plugins/markasjunk2/localization/zh_TW.inc b/plugins/markasjunk2/localization/zh_TW.inc new file mode 100644 index 000000000..9d9d4a541 --- /dev/null +++ b/plugins/markasjunk2/localization/zh_TW.inc @@ -0,0 +1,14 @@ +<?php +/* Author: Denny Lin */ + +$labels = array(); +$labels['buttonjunk'] = '標為垃圾郵件'; +$labels['markasjunk'] = '標為垃圾郵件'; +$labels['buttonnotjunk'] = '非垃圾郵件'; +$labels['markasnotjunk'] = '非垃圾郵件'; + +$messages = array(); +$messages['reportedasjunk'] = '已標為垃圾郵件'; +$messages['reportedasnotjunk'] = '已移至收件匣'; + +?>
\ No newline at end of file diff --git a/plugins/markasjunk2/markasjunk2.js b/plugins/markasjunk2/markasjunk2.js new file mode 100644 index 000000000..5dc141f6a --- /dev/null +++ b/plugins/markasjunk2/markasjunk2.js @@ -0,0 +1,199 @@ +/** + * MarkAsJunk2 plugin script + */ + +function rcmail_markasjunk2(prop) { + if (!rcmail.env.uid && (!rcmail.message_list || !rcmail.message_list.get_selection().length)) + return; + + if (!prop || prop == 'markasjunk2') + prop = 'junk'; + + var prev_sel = null; + + // also select childs of (collapsed) threads + if (rcmail.message_list) { + if (rcmail.env.uid) { + if (rcmail.message_list.rows[rcmail.env.uid].has_children && !rcmail.message_list.rows[rcmail.env.uid].expanded) { + if (!rcmail.message_list.in_selection(rcmail.env.uid)) { + prev_sel = rcmail.message_list.get_selection(); + rcmail.message_list.select_row(rcmail.env.uid); + } + + rcmail.message_list.select_childs(rcmail.env.uid); + rcmail.env.uid = null; + } + else if (rcmail.message_list.get_single_selection() == rcmail.env.uid) { + rcmail.env.uid = null; + } + } + else { + selection = rcmail.message_list.get_selection(); + for (var i in selection) { + if (rcmail.message_list.rows[selection[i]].has_children && !rcmail.message_list.rows[selection[i]].expanded) + rcmail.message_list.select_childs(selection[i]); + } + } + } + + var uids = rcmail.env.uid ? rcmail.env.uid : rcmail.message_list.get_selection().join(','); + + var lock = rcmail.set_busy(true, 'loading'); + rcmail.http_post('plugin.markasjunk2.' + prop, '_uid='+uids+'&_mbox='+urlencode(rcmail.env.mailbox), lock); + + if (prev_sel) { + rcmail.message_list.clear_selection(); + + for (var i in prev_sel) + rcmail.message_list.select_row(prev_sel[i], CONTROL_KEY); + } +} + +function rcmail_markasjunk2_notjunk(prop) { + rcmail_markasjunk2('not_junk'); +} + +rcube_webmail.prototype.rcmail_markasjunk2_move = function(mbox, uid) { + var prev_uid = rcmail.env.uid; + var prev_sel = null; + var a_uids = uid.split(","); + + if (rcmail.message_list && a_uids.length == 1 && !rcmail.message_list.rows[a_uids[0]]) { + rcmail.env.uid = a_uids[0]; + } + else if (rcmail.message_list && a_uids.length == 1 && !rcmail.message_list.in_selection(a_uids[0]) && !rcmail.env.threading) { + rcmail.env.uid = a_uids[0]; + rcmail.message_list.remove_row(rcmail.env.uid, false); + } + else if (rcmail.message_list && (!rcmail.message_list.in_selection(a_uids[0]) || a_uids.length != rcmail.message_list.selection.length)) { + prev_sel = rcmail.message_list.get_selection(); + rcmail.message_list.clear_selection(); + + for (var i in a_uids) + rcmail.message_list.select_row(a_uids[i], CONTROL_KEY); + } + + if (mbox) + rcmail.move_messages(mbox); + else + rcmail.delete_messages(); + + rcmail.env.uid = prev_uid; + + if (prev_sel) { + rcmail.message_list.clear_selection(); + + for (var i in prev_sel) { + if (prev_sel[i] != uid) + rcmail.message_list.select_row(prev_sel[i], CONTROL_KEY); + } + } +} + +function rcmail_markasjunk2_init() { + if (window.rcm_contextmenu_register_command) { + rcm_contextmenu_register_command('markasjunk2', 'rcmail_markasjunk2', rcmail.gettext('markasjunk2.markasjunk'), 'reply', null, true, null, null, 'markmessage markasjunk2'); + rcm_contextmenu_register_command('markasnotjunk2', 'rcmail_markasjunk2_notjunk', rcmail.gettext('markasjunk2.markasnotjunk'), 'reply', null, true, null, null, 'markmessage markasnotjunk2'); + $('#rcmContextMenu li.unflagged').removeClass('separator_below'); + $('#rcmContextMenu li.reply').addClass('separator_above'); + } +} + +function rcmail_markasjunk2_update() { + var spamobj = $('#' + rcmail.buttons['plugin.markasjunk2.junk'][0].id); + var hamobj = $('#' + rcmail.buttons['plugin.markasjunk2.not_junk'][0].id); + + if (spamobj.parent('li').length > 0) { + spamobj = spamobj.parent(); + hamobj = hamobj.parent(); + } + + if (!rcmail.env.markasjunk2_override && rcmail.env.markasjunk2_spam_mailbox && rcmail.env.mailbox != rcmail.env.markasjunk2_spam_mailbox) { + $('#rcmContextMenu li.markasjunk2').show(); + $('#rcmContextMenu li.markasnotjunk2').hide(); + spamobj.show(); + hamobj.hide(); + } + else if (!rcmail.env.markasjunk2_override) { + $('#rcmContextMenu li.markasjunk2').hide(); + $('#rcmContextMenu li.markasnotjunk2').show(); + spamobj.hide(); + hamobj.show(); + } +} + +function rcmail_markasjunk2_status(command) { + switch (command) { + case 'beforedelete': + if (!rcmail.env.flag_for_deletion && rcmail.env.trash_mailbox && + rcmail.env.mailbox != rcmail.env.trash_mailbox && + (rcmail.message_list && !rcmail.message_list.shiftkey)) + rcmail.enable_command('plugin.markasjunk2.junk', 'plugin.markasjunk2.not_junk', false); + + break; + case 'beforemove': + case 'beforemoveto': + rcmail.enable_command('plugin.markasjunk2.junk', 'plugin.markasjunk2.not_junk', false); + break; + case 'aftermove': + case 'aftermoveto': + if (rcmail.env.action == 'show') + rcmail.enable_command('plugin.markasjunk2.junk', 'plugin.markasjunk2.not_junk', true); + + break; + case 'afterpurge': + case 'afterexpunge': + if (!rcmail.env.messagecount && rcmail.task == 'mail') + rcmail.enable_command('plugin.markasjunk2.junk', 'plugin.markasjunk2.not_junk', false); + + break; + } +} + +$(document).ready(function() { + if (window.rcmail) { + rcmail.addEventListener('init', function(evt) { + // register command (directly enable in message view mode) + rcmail.register_command('plugin.markasjunk2.junk', rcmail_markasjunk2, rcmail.env.uid); + rcmail.register_command('plugin.markasjunk2.not_junk', rcmail_markasjunk2_notjunk, rcmail.env.uid); + + if (rcmail.message_list) { + rcmail.message_list.addEventListener('select', function(list) { + rcmail.enable_command('plugin.markasjunk2.junk', list.get_selection().length > 0); + rcmail.enable_command('plugin.markasjunk2.not_junk', list.get_selection().length > 0); + }); + } + }); + + rcmail.add_onload('rcmail_markasjunk2_init()'); + rcmail.addEventListener('listupdate', function(props) { rcmail_markasjunk2_update(); } ); + + rcmail.addEventListener('beforemoveto', function(mbox) { + if (mbox && typeof mbox === 'object') + mbox = mbox.id; + + // check if destination mbox equals junk box (and we're not already in the junk box) + if (rcmail.env.markasjunk2_move_spam && mbox && mbox == rcmail.env.markasjunk2_spam_mailbox && mbox != rcmail.env.mailbox) { + rcmail_markasjunk2(); + return false; + + } + // or if destination mbox equals ham box and we are in the junk box + else if (rcmail.env.markasjunk2_move_ham && mbox && mbox == rcmail.env.markasjunk2_ham_mailbox && rcmail.env.mailbox == rcmail.env.markasjunk2_spam_mailbox) { + rcmail_markasjunk2_notjunk(); + return false; + } + + return; + } ); + + // update button activation after external events + rcmail.addEventListener('beforedelete', function(props) { rcmail_markasjunk2_status('beforedelete'); } ); + rcmail.addEventListener('beforemove', function(props) { rcmail_markasjunk2_status('beforemove'); } ); + rcmail.addEventListener('beforemoveto', function(props) { rcmail_markasjunk2_status('beforemoveto'); } ); + rcmail.addEventListener('aftermove', function(props) { rcmail_markasjunk2_status('aftermove'); } ); + rcmail.addEventListener('aftermoveto', function(props) { rcmail_markasjunk2_status('aftermoveto'); } ); + rcmail.addEventListener('afterpurge', function(props) { rcmail_markasjunk2_status('afterpurge'); } ); + rcmail.addEventListener('afterexpunge', function(props) { rcmail_markasjunk2_status('afterexpunge'); } ); + } +});
\ No newline at end of file diff --git a/plugins/markasjunk2/markasjunk2.php b/plugins/markasjunk2/markasjunk2.php new file mode 100644 index 000000000..313798685 --- /dev/null +++ b/plugins/markasjunk2/markasjunk2.php @@ -0,0 +1,211 @@ +<?php + +/** + * MarkAsJunk2 + * + * Sample plugin that adds a new button to the mailbox toolbar + * to mark the selected messages as Junk and move them to the Junk folder + * or to move messages in the Junk folder to the inbox - moving only the + * attachment if it is a Spamassassin spam report email + * + * @version @package_version@ + * @author Philip Weir + * Based on the Markasjunk plugin by Thomas Bruederli + */ +class markasjunk2 extends rcube_plugin +{ + public $task = 'mail'; + private $spam_mbox = null; + private $ham_mbox = null; + private $spam_flag = 'JUNK'; + private $ham_flag = 'NOTJUNK'; + private $toolbar = true; + + function init() + { + $this->register_action('plugin.markasjunk2.junk', array($this, 'mark_junk')); + $this->register_action('plugin.markasjunk2.not_junk', array($this, 'mark_notjunk')); + + $rcmail = rcube::get_instance(); + $this->load_config(); + $this->ham_mbox = $rcmail->config->get('markasjunk2_ham_mbox', 'INBOX'); + $this->spam_mbox = $rcmail->config->get('markasjunk2_spam_mbox', $rcmail->config->get('junk_mbox', null)); + $this->toolbar = $rcmail->action == 'show' ? $rcmail->config->get('markasjunk2_cp_toolbar', true) : $rcmail->config->get('markasjunk2_mb_toolbar', true); + + if ($rcmail->action == '' || $rcmail->action == 'show') { + $this->include_script('markasjunk2.js'); + $this->add_texts('localization', true); + $this->include_stylesheet($this->local_skin_path() .'/markasjunk2.css'); + if ($rcmail->output->browser->ie && $rcmail->output->browser->ver == 6) + $this->include_stylesheet($this->local_skin_path() . '/ie6hacks.css'); + + $mb_override = ($this->spam_mbox) ? false : true; + $display_junk = $display_not_junk = ''; + if ($_SESSION['mbox'] == $this->spam_mbox) + $display_junk = 'display: none;'; + elseif (!$mb_override) + $display_not_junk = 'display: none;'; + + if ($this->toolbar) { + $this->add_button(array('command' => 'plugin.markasjunk2.junk', 'type' => 'link', 'class' => 'button buttonPas markasjunk2 disabled', 'classact' => 'button markasjunk2', 'classsel' => 'button markasjunk2Sel', 'title' => 'markasjunk2.buttonjunk', 'label' => 'junk', 'style' => $display_junk), 'toolbar'); + $this->add_button(array('command' => 'plugin.markasjunk2.not_junk', 'type' => 'link', 'class' => 'button buttonPas markasnotjunk2 disabled', 'classact' => 'button markasnotjunk2', 'classsel' => 'button markasnotjunk2Sel', 'title' => 'markasjunk2.buttonnotjunk', 'label' => 'markasjunk2.notjunk', 'style' => $display_not_junk), 'toolbar'); + } + else { + $markjunk = $this->api->output->button(array('command' => 'plugin.markasjunk2.junk', 'label' => 'markasjunk2.markasjunk', 'id' => 'markasjunk2', 'class' => 'icon markasjunk2', 'classact' => 'icon markasjunk2 active', 'innerclass' => 'icon markasjunk2')); + $marknotjunk = $this->api->output->button(array('command' => 'plugin.markasjunk2.not_junk', 'label' => 'markasjunk2.markasnotjunk', 'id' => 'markasnotjunk2', 'class' => 'icon markasnotjunk2', 'classact' => 'icon markasnotjunk2 active', 'innerclass' => 'icon markasnotjunk2')); + $this->api->add_content(html::tag('li', array('style' => $display_junk), $markjunk), 'markmenu'); + $this->api->add_content(html::tag('li', array('style' => $display_not_junk), $marknotjunk), 'markmenu'); + } + + $this->api->output->set_env('markasjunk2_override', $mb_override); + $this->api->output->set_env('markasjunk2_ham_mailbox', $this->ham_mbox); + $this->api->output->set_env('markasjunk2_spam_mailbox', $this->spam_mbox); + + $this->api->output->set_env('markasjunk2_move_spam', $rcmail->config->get('markasjunk2_move_spam', false)); + $this->api->output->set_env('markasjunk2_move_ham', $rcmail->config->get('markasjunk2_move_ham', false)); + } + } + + function mark_junk() + { + $this->add_texts('localization'); + $this->_set_flags(); + + $uids = rcube_utils::get_input_value('_uid', rcube_utils::INPUT_POST); + $mbox = rcube_utils::get_input_value('_mbox', rcube_utils::INPUT_POST); + + if ($this->_spam($uids, $mbox, $this->spam_mbox)) + $this->api->output->command('display_message', $this->gettext('reportedasjunk'), 'confirmation'); + + $this->api->output->send(); + } + + function mark_notjunk() + { + $this->add_texts('localization'); + $this->_set_flags(); + + $uids = rcube_utils::get_input_value('_uid', rcube_utils::INPUT_POST); + $mbox = rcube_utils::get_input_value('_mbox', rcube_utils::INPUT_POST); + + if ($this->_ham($uids, $mbox, $this->ham_mbox)) + $this->api->output->command('display_message', $this->gettext('reportedasnotjunk'), 'confirmation'); + + $this->api->output->send(); + } + + private function _spam($uids, $mbox_name = NULL, $dest_mbox = NULL) + { + $rcmail = rcube::get_instance(); + $storage = $rcmail->storage; + + if ($rcmail->config->get('markasjunk2_learning_driver', false)) { + $result = $this->_call_driver($uids, true); + + if (!$result) + return false; + } + + if ($rcmail->config->get('markasjunk2_read_spam', false)) + $storage->set_flag($uids, 'SEEN', $mbox_name); + + if ($rcmail->config->get('markasjunk2_spam_flag', false)) + $storage->set_flag($uids, $this->spam_flag, $mbox_name); + + if ($rcmail->config->get('markasjunk2_ham_flag', false)) + $storage->unset_flag($uids, $this->ham_flag, $mbox_name); + + if ($dest_mbox && $mbox_name != $dest_mbox) + $this->api->output->command('rcmail_markasjunk2_move', $dest_mbox, $uids); + else + $this->api->output->command('command', 'list', $mbox_name); + + return true; + } + + private function _ham($uids, $mbox_name = NULL, $dest_mbox = NULL) + { + $rcmail = rcube::get_instance(); + $storage = $rcmail->storage; + + if ($rcmail->config->get('markasjunk2_learning_driver', false)) { + $result = $this->_call_driver($uids, false); + + if (!$result) + return false; + } + + if ($rcmail->config->get('markasjunk2_unread_ham', false)) + $storage->unset_flag($uids, 'SEEN', $mbox_name); + + if ($rcmail->config->get('markasjunk2_spam_flag', false)) + $storage->unset_flag($uids, $this->spam_flag, $mbox_name); + + if ($rcmail->config->get('markasjunk2_ham_flag', false)) + $storage->set_flag($uids, $this->ham_flag, $mbox_name); + + if ($dest_mbox && $mbox_name != $dest_mbox) + $this->api->output->command('rcmail_markasjunk2_move', $dest_mbox, $uids); + else + $this->api->output->command('command', 'list', $mbox_name); + + return true; + } + + private function _call_driver(&$uids, $spam) + { + $driver = $this->home.'/drivers/'. rcube::get_instance()->config->get('markasjunk2_learning_driver', 'cmd_learn') .'.php'; + $class = 'markasjunk2_' . rcube::get_instance()->config->get('markasjunk2_learning_driver', 'cmd_learn'); + + if (!is_readable($driver)) { + rcube::raise_error(array( + 'code' => 600, + 'type' => 'php', + 'file' => __FILE__, + 'line' => __LINE__, + 'message' => "MarkasJunk2 plugin: Unable to open driver file $driver" + ), true, false); + } + + include_once $driver; + + if (!class_exists($class, false) || !method_exists($class, 'spam') || !method_exists($class, 'ham')) { + rcube::raise_error(array( + 'code' => 600, + 'type' => 'php', + 'file' => __FILE__, + 'line' => __LINE__, + 'message' => "MarkasJunk2 plugin: Broken driver: $driver" + ), true, false); + } + + $object = new $class; + if ($spam) + $object->spam($uids); + else + $object->ham($uids); + + return $object->is_error ? false : true; + } + + private function _set_flags() + { + $rcmail = rcube::get_instance(); + + if ($rcmail->config->get('markasjunk2_spam_flag', false)) { + if ($flag = array_search($rcmail->config->get('markasjunk2_spam_flag'), $rcmail->storage->conn->flags)) + $this->spam_flag = $flag; + else + $rcmail->storage->conn->flags[$this->spam_flag] = $rcmail->config->get('markasjunk2_spam_flag'); + } + + if ($rcmail->config->get('markasjunk2_ham_flag', false)) { + if ($flag = array_search($rcmail->config->get('markasjunk2_ham_flag'), $rcmail->storage->conn->flags)) + $this->ham_flag = $flag; + else + $rcmail->storage->conn->flags[$this->ham_flag] = $rcmail->config->get('markasjunk2_ham_flag'); + } + } +} + +?>
\ No newline at end of file diff --git a/plugins/markasjunk2/package.xml b/plugins/markasjunk2/package.xml new file mode 100644 index 000000000..3b16ed13a --- /dev/null +++ b/plugins/markasjunk2/package.xml @@ -0,0 +1,92 @@ +<?xml version="1.0" encoding="UTF-8"?> +<package xmlns="http://pear.php.net/dtd/package-2.0" xmlns:tasks="http://pear.php.net/dtd/tasks-1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" packagerversion="1.9.0" version="2.0" xsi:schemaLocation="http://pear.php.net/dtd/tasks-1.0 + http://pear.php.net/dtd/tasks-1.0.xsd + http://pear.php.net/dtd/package-2.0 + http://pear.php.net/dtd/package-2.0.xsd"> + <name>markasjunk2</name> + <uri>http://github.com/JohnDoh/Roundcube-Plugin-Mark-as-Junk-2/</uri> + <summary>Learn messages as Junk/Not Junk</summary> + <description>Adds a new button to the mailbox toolbar to mark the selected messages as Junk/Not Junk, optionally detaching original messages from spam reports if the message is not junk and learning junk/not junk using various methods (sa-learn, etc.).</description> + <lead> + <name>Philip Weir</name> + <user>JohnDoh</user> + <email>roundcube@tehinterweb.co.uk</email> + <active>yes</active> + </lead> + <date>2013-02-24</date> + <time>10:16:53</time> + <version> + <release>1.6</release> + <api>1.6</api> + </version> + <stability> + <release>stable</release> + <api>stable</api> + </stability> + <license uri="http://www.gnu.org/licenses/gpl.html">GNU GPLv3+</license> + <notes>-</notes> + <contents> + <dir baseinstalldir="/" name="/"> + <file name="markasjunk2.php" role="php"> + <tasks:replace from="@name@" to="name" type="package-info"/> + <tasks:replace from="@package_version@" to="version" type="package-info"/> + </file> + <file name="markasjunk2.js" role="data"> + <tasks:replace from="@name@" to="name" type="package-info"/> + <tasks:replace from="@package_version@" to="version" type="package-info"/> + </file> + <file name="config.inc.php.dist" role="data"/> + <file name="CHANGELOG" role="data"/> + <file name="README.md" role="data"/> + <file name="drivers/cmd_learn.php" role="php"/> + <file name="drivers/dir_learn.php" role="php"/> + <file name="drivers/edit_headers.php" role="php"/> + <file name="drivers/email_learn.php" role="php"/> + <file name="drivers/sa_blacklist.php" role="php"/> + <file name="drivers/sa_detach.php" role="php"/> + <file name="localization/ca_ES.inc" role="data"/> + <file name="localization/cs_CZ.inc" role="data"/> + <file name="localization/de_CH.inc" role="data"/> + <file name="localization/de_DE.inc" role="data"/> + <file name="localization/en_GB.inc" role="data"/> + <file name="localization/en_US.inc" role="data"/> + <file name="localization/es_AR.inc" role="data"/> + <file name="localization/es_ES.inc" role="data"/> + <file name="localization/fa_IR.inc" role="data"/> + <file name="localization/fr_FR.inc" role="data"/> + <file name="localization/gl_ES.inc" role="data"/> + <file name="localization/hu_HU.inc" role="data"/> + <file name="localization/it_IT.inc" role="data"/> + <file name="localization/lv_LV.inc" role="data"/> + <file name="localization/nl_NL.inc" role="data"/> + <file name="localization/pl_PL.inc" role="data"/> + <file name="localization/pt_BR.inc" role="data"/> + <file name="localization/ro_RO.inc" role="data"/> + <file name="localization/ru_RU.inc" role="data"/> + <file name="localization/tr_TR.inc" role="data"/> + <file name="localization/zh_TW.inc" role="data"/> + <file name="skins/classic/ie6hacks.css" role="data"/> + <file name="skins/classic/mail_toolbar.gif" role="data"/> + <file name="skins/classic/mail_toolbar.png" role="data"/> + <file name="skins/classic/markasjunk2.css" role="data"/> + <file name="skins/classic/messageactions.gif" role="data"/> + <file name="skins/classic/messageactions.png" role="data"/> + <file name="skins/larry/ie6hacks.css" role="data"/> + <file name="skins/larry/mail_toolbar.png" role="data"/> + <file name="skins/larry/markasjunk2.css" role="data"/> + <file name="skins/larry/messageactions.png" role="data"/> + </dir> + <!-- / --> + </contents> + <dependencies> + <required> + <php> + <min>5.2.1</min> + </php> + <pearinstaller> + <min>1.7.0</min> + </pearinstaller> + </required> + </dependencies> + <phprelease/> +</package> diff --git a/plugins/markasjunk2/skins/classic/ie6hacks.css b/plugins/markasjunk2/skins/classic/ie6hacks.css new file mode 100644 index 000000000..3b61721e3 --- /dev/null +++ b/plugins/markasjunk2/skins/classic/ie6hacks.css @@ -0,0 +1,19 @@ +/** + * MarkAsJunk2 plugin styles (IE6 hacks) + */ + +#messagetoolbar a.markasjunk2, +#messagetoolbar a.markasjunk2Sel, +#messagetoolbar a.markasnotjunk2, +#messagetoolbar a.markasnotjunk2Sel +{ + background-image: url(mail_toolbar.gif); +} + +#rcmContextMenu .markasjunk2 a, +#rcmContextMenu .markasnotjunk2 a, +#markmessagemenu a.markasjunk2, +#markmessagemenu a.markasnotjunk2 +{ + background-image: url(messageactions.gif); +}
\ No newline at end of file diff --git a/plugins/markasjunk2/skins/classic/mail_toolbar.gif b/plugins/markasjunk2/skins/classic/mail_toolbar.gif Binary files differnew file mode 100644 index 000000000..d1cdff0f2 --- /dev/null +++ b/plugins/markasjunk2/skins/classic/mail_toolbar.gif diff --git a/plugins/markasjunk2/skins/classic/mail_toolbar.png b/plugins/markasjunk2/skins/classic/mail_toolbar.png Binary files differnew file mode 100644 index 000000000..aad0e9ebc --- /dev/null +++ b/plugins/markasjunk2/skins/classic/mail_toolbar.png diff --git a/plugins/markasjunk2/skins/classic/markasjunk2.css b/plugins/markasjunk2/skins/classic/markasjunk2.css new file mode 100644 index 000000000..311a45083 --- /dev/null +++ b/plugins/markasjunk2/skins/classic/markasjunk2.css @@ -0,0 +1,52 @@ +/** + * MarkAsJunk2 plugin styles + */ + +#messagetoolbar a.markasjunk2, +#messagetoolbar a.markasjunk2Sel, +#messagetoolbar a.markasnotjunk2, +#messagetoolbar a.markasnotjunk2Sel +{ + text-indent: -5000px; + background-image: url(mail_toolbar.png); +} + +#messagetoolbar a.markasjunk2 +{ + background-position: -32px 0; +} + +#messagetoolbar a.markasjunk2Sel +{ + background-position: -32px -32px; +} + +#messagetoolbar a.markasnotjunk2 +{ + background-position: 0 0; +} + +#messagetoolbar a.markasnotjunk2Sel +{ + background-position: 0 -32px; +} + +#rcmContextMenu .markasjunk2 a, +#rcmContextMenu .markasnotjunk2 a, +#markmessagemenu a.markasjunk2, +#markmessagemenu a.markasnotjunk2 +{ + background-image: url(messageactions.png); +} + +#rcmContextMenu .markasjunk2 a, +#markmessagemenu a.markasjunk2 +{ + background-position: 7px -17px; +} + +#rcmContextMenu .markasnotjunk2 a, +#markmessagemenu a.markasnotjunk2 +{ + background-position: 7px 0; +}
\ No newline at end of file diff --git a/plugins/markasjunk2/skins/classic/messageactions.gif b/plugins/markasjunk2/skins/classic/messageactions.gif Binary files differnew file mode 100644 index 000000000..255ae3606 --- /dev/null +++ b/plugins/markasjunk2/skins/classic/messageactions.gif diff --git a/plugins/markasjunk2/skins/classic/messageactions.png b/plugins/markasjunk2/skins/classic/messageactions.png Binary files differnew file mode 100644 index 000000000..11a7f7f51 --- /dev/null +++ b/plugins/markasjunk2/skins/classic/messageactions.png diff --git a/plugins/markasjunk2/skins/larry/ie6hacks.css b/plugins/markasjunk2/skins/larry/ie6hacks.css new file mode 100644 index 000000000..cd33694ae --- /dev/null +++ b/plugins/markasjunk2/skins/larry/ie6hacks.css @@ -0,0 +1,3 @@ +/** + * MarkAsJunk2 plugin styles (IE6 hacks) + */ diff --git a/plugins/markasjunk2/skins/larry/mail_toolbar.png b/plugins/markasjunk2/skins/larry/mail_toolbar.png Binary files differnew file mode 100644 index 000000000..3d5981482 --- /dev/null +++ b/plugins/markasjunk2/skins/larry/mail_toolbar.png diff --git a/plugins/markasjunk2/skins/larry/markasjunk2.css b/plugins/markasjunk2/skins/larry/markasjunk2.css new file mode 100644 index 000000000..90362ed2a --- /dev/null +++ b/plugins/markasjunk2/skins/larry/markasjunk2.css @@ -0,0 +1,51 @@ +/** + * MarkAsJunk2 plugin styles + */ + +#messagetoolbar a.markasjunk2, +#messagetoolbar a.markasjunk2Sel, +#messagetoolbar a.markasnotjunk2, +#messagetoolbar a.markasnotjunk2Sel +{ + background-image: url(mail_toolbar.png); +} + +#messagetoolbar a.markasjunk2, +#messagetoolbar a.markasjunk2Sel +{ + background-position: center -14px; +} + +#messagetoolbar a.markasnotjunk2, +#messagetoolbar a.markasnotjunk2Sel +{ + background-position: center -61px; +} + +#rcmContextMenu .markasjunk2 a span, +#rcmContextMenu .markasnotjunk2 a span, +#markmessagemenu a.markasjunk2 span, +#markmessagemenu a.markasnotjunk2 span +{ + background-image: url(messageactions.png); +} + +#markmessagemenu a.markasjunk2 span +{ + background-position: 1px -17px; +} + +#markmessagemenu a.markasnotjunk2 span +{ + background-position: 1px 5px; +} + +#rcmContextMenu .markasjunk2 a span +{ + background-position: 7px -14px; +} + +#rcmContextMenu .markasnotjunk2 a span +{ + background-position: 7px 7px; +}
\ No newline at end of file diff --git a/plugins/markasjunk2/skins/larry/messageactions.png b/plugins/markasjunk2/skins/larry/messageactions.png Binary files differnew file mode 100644 index 000000000..15f5d56ac --- /dev/null +++ b/plugins/markasjunk2/skins/larry/messageactions.png |