spam_buttons/0000755000000000000000000000000011201130721012256 5ustar rootrootspam_buttons/functions.php0000644000000000000000000001230311127347303015013 0ustar rootroot, * Licensed under the GNU GPL. For full terms see the file COPYING. * * @package plugins * @subpackage spam_buttons * */ /** * Initialize this plugin (load config values) * * @return boolean FALSE if no configuration file could be loaded, TRUE otherwise * */ function spam_buttons_init() { return load_config('spam_buttons', array('config.php', '../../config/config_spam_buttons.php'), TRUE); } /** * Retrieve All Message Headers * * When called more than once in the same page request against the same * message, a cached set of headers is returned for efficiency. * * @param int $passed_id UID of the desired message * @param string $passed_ent_id Entity ID of the desired message attachment * * @return array An array of all message headers * */ function sb_get_message_headers($passed_id, $passed_ent_id) { static $parsed_headers = array(); $index = $passed_id . '.' . $passed_ent_id; if (isset($parsed_headers[$index])) return $parsed_headers[$index]; global $imapConnection, $username, $key, $uid_support, $mbx_response, $imapServerAddress, $imapPort, $mailbox; if (check_sm_version(1, 5, 2)) { $key = FALSE; $uid_support = TRUE; } if (!is_resource($imapConnection)) $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0); if (empty($mbx_response)) $mbx_response = sqimap_mailbox_select($imapConnection, $mailbox); if (empty($passed_ent_id)) $headers = sqimap_run_command($imapConnection, "FETCH $passed_id BODY.PEEK[HEADER]", true, $response, $message, $uid_support); else $headers = sqimap_run_command($imapConnection, "FETCH $passed_id BODY.PEEK[$passed_ent_id.HEADER]", true, $response, $message, $uid_support); $parsed_headers[$index] = sb_parse_headers($headers); return $parsed_headers[$index]; } /** * Parse raw headers retrieved from IMAP server into internal array format * * @param string $headers The raw headers straight from an IMAP FETCH query * * @return array An array of the given message headers * */ function sb_parse_headers($headers) { $parsed_headers = array(); // based on src/view_header.php... // $first = $second = array(); $cnum = 0; for ($i=1; $i < count($headers); $i++) { $line = $headers[$i]; switch (true) { case (eregi("^>", $line)): $second[$i] = $line; $first[$i] = ' '; $cnum++; break; case (eregi("^[ |\t]", $line)): $second[$i] = $line; $first[$i] = ''; break; case (eregi("^([^:]+):(.+)", $line, $regs)): $first[$i] = $regs[1] . ':'; $second[$i] = $regs[2]; $cnum++; break; default: $second[$i] = trim($line); $first[$i] = ''; break; } } for ($i=0; $i < count($second); $i = $j) { $f = (isset($first[$i]) ? $first[$i] : ''); $s = (isset($second[$i]) ? $second[$i] : ''); $j = $i + 1; while (($first[$j] == '') && ($j < count($first))) { $s .= ' ' . $second[$j]; $j++; } if ($f) $parsed_headers[] = array($f,$s); } return $parsed_headers; } /** * Retrieve A Single Message Header * * When called more than once in the same page request against the same * message, a cached header value is returned for efficiency. * * @param int $passed_id UID of the desired message * @param string $passed_ent_id Entity ID of the desired message attachment * @param string $header_name The name of the desired header * * @return array An array containing the header name and its value, * or an empty array if the header was not found * */ function sb_get_message_header($passed_id, $passed_ent_id, $header_name) { static $parsed_header = array(); $index = $passed_id . '.' . $passed_ent_id . '.' . $header_name; if (isset($parsed_header[$index])) return $parsed_header[$index]; global $imapConnection, $username, $key, $uid_support, $mbx_response, $imapServerAddress, $imapPort, $mailbox; if (check_sm_version(1, 5, 2)) { $key = FALSE; $uid_support = TRUE; } if (!is_resource($imapConnection)) $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0); if (empty($mbx_response)) $mbx_response = sqimap_mailbox_select($imapConnection, $mailbox); if (empty($passed_ent_id)) $header = sqimap_run_command($imapConnection, "FETCH $passed_id BODY.PEEK[HEADER.FIELDS ($header_name)]", true, $response, $message, $uid_support); else $header = sqimap_run_command($imapConnection, "FETCH $passed_id BODY.PEEK[$passed_ent_id.HEADER.FIELDS ($header_name)]", true, $response, $message, $uid_support); $parsed_header[$index] = sb_parse_headers($header); if (!empty($parsed_header[$index][0])) $parsed_header[$index] = $parsed_header[$index][0]; else $parsed_header[$index] = array(); return $parsed_header[$index]; } spam_buttons/docs/0000755000000000000000000000000011201130424013206 5ustar rootrootspam_buttons/docs/index.php0000644000000000000000000000074011203034234015033 0ustar rootrootspam_buttons/docs/INSTALL0000644000000000000000000000601411050150457014252 0ustar rootrootInstalling The Spam Buttons Plugin ================================== 1) Start with untaring the file into the plugins directory. Here is a example for the 1.0 version of the Spam Buttons plugin. $ cd plugins $ tar -zxvf spam_buttons-1.0-1.4.0.tar.gz 2) Decide if you want to store the plugin configuration file in the plugin directory or in the main SquirrelMail config directory. A) To store the configuration file in the plugin directory, change into the spam_buttons directory, copy config_example.php to config.php and edit config.php, making adjustments as you deem necessary. $ cd spam_buttons $ cp config_example.php config.php $ vi config.php B) To store the configuration file in the main SquirrelMail config directory, change into the spam_buttons directory, copy config_example.php to ../../config/config_spam_buttons.php and edit ../../config/config_spam_buttons.php, making adjustments as you deem necessary. $ cd spam_buttons $ cp config_example.php ../../config/config_spam_buttons.php $ vi ../../config/config_spam_buttons.php 3) If you are running SquirrelMail 1.4.11 or above, or if you have already run the patch included with the Reply Buttons or Bounce plugins, skip to step five. 4) Patch SquirrelMail 1.4.x to enable button display on the message list page. The patch should be run from the spam_buttons directory. Make sure to use the patch that corresponds closest to your SquirrelMail version. $ patch -p0 < patches/spam_buttons-squirrelmail-1.4.10.diff Note for Windows users: you can get native patch functionality by installing this very useful package: http://unxutils.sourceforge.net/ 5) Then go to your config directory and run conf.pl. Choose option 8 and move the plugin from the "Available Plugins" category to the "Installed Plugins" category. Save and exit. $ cd ../../config/ $ ./conf.pl 6) Also, please verify that you have the "Compatibility" plugin installed (but not necessarily activated). 7) Translations are not included in this package. To get a translation, download the language pack needed from: http://www.squirrelmail.org/download.php Upgrading Spam Buttons ====================== 1) Start with untaring the file into the plugins directory. Here is a example for the 1.0 version of the Spam Buttons plugin. $ cd plugins $ tar -zxvf spam_buttons-1.0-1.4.0.tar.gz 2) Change into the spam_buttons directory and check your config.php file against the new version to see if there are any new settings that you must add to your config.php file. $ diff -u config.php config_example.php If you store your configuration file in the main SquirrelMail config directory, adjust this command as follows: $ diff -u ../../config/config_spam_buttons.php config_example.php Or simply replace your config.php file with the provided example and reconfigure the plugin from scratch (see step 2 under the installation procedure above). spam_buttons/docs/.htaccess0000644000000000000000000000001611203033726015012 0ustar rootrootDeny from All spam_buttons/docs/COPYING0000644000000000000000000003543310212643236014264 0ustar rootroot GNU GENERAL PUBLIC LICENSE Version 2, June 1991 Copyright (C) 1989, 1991 Free Software Foundation, Inc. 675 Mass Ave, Cambridge, MA 02139, USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This General Public License applies to most of the Free Software Foundation's software and to any other program whose authors commit to using it. (Some other Free Software Foundation software is covered by the GNU Library General Public License instead.) You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. Finally, any free program is threatened constantly by software patents. We wish to avoid the danger that redistributors of a free program will individually obtain patent licenses, in effect making the program proprietary. To prevent this, we have made it clear that any patent must be licensed for everyone's free use or not licensed at all. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any derivative work under copyright law: that is to say, a work containing the Program or a portion of it, either verbatim or with modifications and/or translated into another language. (Hereinafter, translation is included without limitation in the term "modification".) Each licensee is addressed as "you". Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running the Program is not restricted, and the output from the Program is covered only if its contents constitute a work based on the Program (independent of having been made by running the Program). Whether that is true depends on what the Program does. 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and give any other recipients of the Program a copy of this License along with the Program. You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. 2. You may modify your copy or copies of the Program or any portion of it, thus forming a work based on the Program, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: a) You must cause the modified files to carry prominent notices stating that you changed the files and the date of any change. b) You must cause any work that you distribute or publish, that in whole or in part contains or is derived from the Program or any part thereof, to be licensed as a whole at no charge to all third parties under the terms of this License. c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the most ordinary way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this License. (Exception: if the Program itself is interactive but does not normally print such an announcement, your work based on the Program is not required to print an announcement.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Program, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Program, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Program. In addition, mere aggregation of another work not based on the Program with the Program (or with a work based on the Program) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may copy and distribute the Program (or a work based on it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you also do one of the following: a) Accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, b) Accompany it with a written offer, valid for at least three years, to give any third party, for a charge no more than your cost of physically performing source distribution, a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, c) Accompany it with the information you received as to the offer to distribute corresponding source code. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form with such an offer, in accord with Subsection b above.) The source code for a work means the preferred form of the work for making modifications to it. For an executable work, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the executable. However, as a special exception, the source code distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. If distribution of executable or object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place counts as distribution of the source code, even though third parties are not compelled to copy the source along with the object code. 4. You may not copy, modify, sublicense, or distribute the Program except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense or distribute the Program is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 5. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Program or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Program (or any work based on the Program), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Program or works based on it. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties to this License. 7. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Program at all. For example, if a patent license would not permit royalty-free redistribution of the Program by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Program. If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply and the section as a whole is intended to apply in other circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system, which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 8. If the distribution and/or use of the Program is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Program under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 9. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of this License, you may choose any version ever published by the Free Software Foundation. 10. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS spam_buttons/docs/README0000644000000000000000000003570711201130424014102 0ustar rootrootSpam Buttons plugin for SquirrelMail ==================================== Ver 2.3.1, 2009/07/01 Copyright (c) 2005-2009 Paul Lesniewski Description =========== This plugin will place "Spam" and/or "Not Spam" buttons on the mailbox message list page as well as on a single message view page. The action associated with the buttons (as well as the button text) can be configured to suit most any spam reporting system. Reporting by email, reporting by executing a command on the server, reporting by moving (or copying) the message to a designated folder and reporting by calling a custom-defined PHP function are all supported. Any number of custom buttons may also be added, where the associated action is completely customizable (for instance, adding the message sender to a whitelist or blacklist). One implementation of a mechanism for accepting spam reports sent as message attachments using Postfix can be found here: http://gtmp.org/publications/sa-postfix-en http://gtmp.org/doku.php/publications/sa-wrapper A copy of these pages are also saved herein - see: contrib/sa-postfix-en.html contrib/sa-wrapper.html Also found in the contrib directory is a patch submitted by Dmitry Banchshikov that adds an "Are you sure" JavaScript popup that appears when a user clicks on a spam or not spam button. The patch only works when using SquirrelMail 1.4.x, however. See contrib/confirm_action.diff License ======= This plugin is released under the GNU General Public License (see COPYING for details). Donations ========= If you or your company make regular use of this software, please consider supporting Open Source development by donating to the authors or inquire about hiring them to consult on other projects. Donation/ wish list links for the author(s) are as follows: Paul Lesniewski: http://squirrelmail.org/wiki/DonatePaulLesniewski Requirements ============ * SquirrelMail version 1.4.0 or above (although please note that report-by-email options may create problems in very early versions of SquirrelMail 1.4.x) * Compatibility plugin version 2.0.12 or above * Working preconfigured spam filtering system - this plugin is ONLY a front-end for YOUR spam filtering system! Configuration ============= Be sure to configure the plugin to use reporting by email, by moving to a folder OR reporting by shell command, but NOT more than one! Note that when configuring defaults for your users, where a "Spam" button should be shown in all folders except the actual spam folder (where a "Not Spam" button should be shown instead), you can define a value for $sb_suppress_spam_button_folder and $sb_show_not_spam_button_folder, both being the name of the spam folder. If you are uncertain how to specify folder names for any of the report-by-move or move-after-report or other settings that require exact IMAP style folder naming, you can look in the main SquirrelMail configuration file and as a guide, folders are usually named such as by putting together $default_folder_prefix and $trash_folder. The other way to find correct folder names is to visit the SquirrelMail Folders or Folder Options page in your browser, then view the HTML page source and see how the folders are named in the value attributes of the folder select drop-down widgets. Please see the plugin's configuration file for more details about the various plugin configuration settings. Troubleshooting =============== * If you have problems getting reporting to work, please first verify that you have correctly installed and configured your anti-spam system to correctly accept spam reports using the mechanism you configured in this plugin. This plugin IS NOT RESPONSIBLE for providing the actual reporting functionality in your mail server. You MUST first have a *fully functioning* spam reporting system on your mail server BEFORE you attempt to use this plugin. * Make sure the plugin is configured correctly by browsing to http://your-squirrelmail-location/src/configtest.php * If you experience errors (see your web server error log) that begin with "Fatal error: Call to undefined function load_config() in....", you are missing the Compatibility plugin. See the Requirements section above. * In order to help debug any problems, please use the $sb_debug flag in the configuration file and include any output it generates (along with the configuration settings you are using) in any help requests. * If you do not find that the user-configurable options for deleting or moving messages after report are showing up on Options->Display Preferences, please ensure that your reporting method is NOT report-by-move-to-folder. * When using the report-by-move-to-folder functionality, the spam buttons/links will not show when viewing message attachments, since attachments cannot be moved. Likewise, delete-after-report and move-after-report will be ignored when reporting message attachments. * When the user or administrator has enabled BOTH delete-after- report and move-after-report, move-after-report will take precedence, and delete-after-report will be ignored. * Reporting message attachments may not work reliably unless using SquirrelMail 1.4.11+ or 1.5.2+. * It has been reported that when using Sendmail to send messages in the main SquirrelMail configuration ($useSendmail) along with the report-by-email method (bounce only), reported messages do not appear to reach their destination. The problem may lie with how Sendmail treats what looks like a duplicated message. If you experience this issue, it is recommended that you choose a different reporting method. * When using SpamAssassin and you want to make sure the spam/ham counts are correctly increasing when a report is submitted, run sa-learn on the command line with the --dump option and it will show you the total spam and ham for the specified user. Those totals will change when you click the spam/ham buttons (unless your plugin configuration is incorrect). For example: sa-learn --username=jose@example.org --dump | head * If you are using the report-by-shell-commmand method, you can see more debugging output from the command by adding 2> /tmp/spam_buttons.log to the end of your shell command (note that you may also need to increase the verbosity of the command, usually by using the -D option with the SpamAssassin family of commands). * If changes to the configuration file don't seem to be showing in the user interface, first check that you have not overridden the configuration settings with user preference settings that are shown on the Options->Display Preferences page. Otherwise, ensure that there are not two Spam Buttons configuration files, one in the spam_buttons directory and one in the main SquirrelMail config directory (named "config_spam_buttons.php"). The one in the main SquirrelMail config directory will always override the one in the spam_buttons directory. Help Requests ============= Before looking for help elsewhere, please try to help yourself: * Read the Troubleshooting section herein. * Look to see if others have already asked about the same issue. There are tips and links for the best places to do this in the SquirrelMail mailing list posting guidelines: http://squirrelmail.org/wiki/MailingListPostingGuidelines You should also try Google or some other search engine. * If you cannot find any information about your issue, please first mail your help request to the squirrelmail-plugins mailing list. Information about it can be found here: http://lists.sourceforge.net/mailman/listinfo/squirrelmail-plugins You MUST read the mailing list posting guidelines (see above) and include as much information about your issue (and your system) as possible. Including configtest output, any debug output, the plugin configuration settings you've made and anything else you can think of to make it easier to diagnose your problem will get you the most useful responses. Inquiries that do not comply with the posting guidelines are liable to be ignored. * If you don't get any replies on the mailing list, you are welcome to send a help request to the authors' personal address(es), but please be patient with the mailing list. TODO ==== * Allow more than one reporting type at once? This is not too hard to implement when using report-by-email, report-by-shell- command and/or report-by-custom-function, but NOT when using report-by-move-to-folder because it might redirect the browser when it is done reporting, etc. Also, would need to figure out what to do with the $note return value - just use the *last* one? If implemented, need to relax configtest check. * Re-mark previously unread messages as unread after reporting * It is possible that use with UW (or dovecot?) will cause "connection dropped" IMAP errors when reporting from the message view screen -- IMAP server reports "* BYE Lost mailbox lock" which is probably due to other IMAP commands within this plugin that "corrupt" the IMAP connection state as far as UW is concerned... (only if report by email? have to do with putting mail in the sent folder?) -- this needs more research and may be related only to old versions of SM * Implement "dont_wait" functionality (see functions.php, search for "dont_wait")? Fork a new process and don't block the user experience waiting for slow spam reporting process to do its work. Questions come up: should this feature be considered incompatible with the "reselect" or "report/delete" or "report/move" functionalities? Those (as well as innocent user actions) might introduce race conditions. Update: one idea is to first make a copy of the target message(s) into, say, the attachment dir, from whence the child process can then, free of concerns of a race condition, do the learn task and then delete the message. This is similar to how the report-by-shell code already does it, saving off a temporary copy of the message in the attachment dir, so much of the needed code is already written. * If more than one message is being reported and the method is report- by-shell-command, it can be faster, at least for some applications, to have the target messages in a certain directory and just run the command once on the dir (not the files inside it). This is specific to that reporting type, so not a high priority at this time. * Offer an option that allows admins to indicate that multiple message reports should be done in one fell swoop: for report-by-shell-command, dump all messages to a single file and report it once... for report-by- email, all messages are attached to the same spam report (although for bounce functionality, I don't think there is any way to accomodate this. Change Log ========== v2.3.1 2009/07/01 Paul Lesniewski * Fixed regression in version 2.3 that resulted in the loss of correct pagination information when using buttons on the message list screen v2.3 2009/05/18 Paul Lesniewski * Updated for compatibility with SquirrelMail 1.4.18 v2.2.1 2009/01/31 Paul Lesniewski * Added check for patch in configtest for SquirrelMail versions that require it * Added some documentation about error that occurs when Compatibility plugin is missing * Correctly handle plural forms of success message for custom reporting mechanism with ngettext * Minor fix to accomodate Dovecot issue with UIDs that can be bigger than normal integer values v2.2 2008/06/04 Paul Lesniewski * Added ability to add any number of extra custom buttons/links, such as whitelist or blacklist, etc. See configuration file for details * Added new report method: custom PHP callback - sample implementation is included, but is ultimately your reponsibility * Fixed possible PHP notices caused by unmigrated prefs (v2.0->v2.1+) * Fine-tuned some internal logic for when buttons are shown or not * Slightly better, more efficient header inspection * Fix bug in report-by-email-attachment functionality for 1.4.14+ and 1.5.2+ * Added ability to decide if spam reports sent as email attachments should be stored in user's sent folder or not * Added ability to store configuration file in main SquirrelMail config directory (must be named "config_spam_buttons.php") v2.1 2008/01/01 Paul Lesniewski * Fixed issue where buttons would not appear upon initial login * Added button "inclusion" options (in contrast to the other button "suppression" options) * Both "inclusion" and "suppression" options can contain lists of more than one folder * Fix for report-by-email-attachment functionality so it remains compatible with 1.4.14+ and 1.5.2+ * Translators note some new strings have been added * Fixed report-by-move functionality in 1.5.0+ * Completed some internal code reorganization * Added ability to move to previous/next message from message view after report-by-move or delete/move after report (instead of returning to message list page) * Made move-after-report functionality work correctly when report-by-copy is enabled (Thanks to Herman van Rink) * Added auto-creation of non-existing folders (Thanks to Herman van Rink) * Added patch for 1.5.1, although 1.5.1 is still not officially supported - please upgrade to 1.5.2! v2.0 2007/09/05 Paul Lesniewski * Added tag-and-delete functionality (user or admin-configurable) * Added tag-and-move functionality (user or admin-configurable) * Added report-by-move-to-folder functionality * All move functionalities can be changed to copy instead * Added email address, username and domain substitutions for the report-by-email method * Suppress spam/ham buttons when in certain (configurable) folders * Suppress spam/ham buttons depending on if a message was tagged as spam by an anti-spam scanner (scans message headers) * Updated to comply with newest SquirrelMail plugin requirements * Added compatibility with SquirrelMail 1.5.2 * May no longer be compatible with SquirrelMail 1.5.0 or 1.5.1 (untested); please upgrade if you are using SquirrelMail development code v1.0.1 2005/03/11 Paul Lesniewski * Fixed some cut n paste typos * Fixed internationalization issues * Fixed support for IMAP servers without UID support * Help people who enter "false" instead of false when overriding $useSendmail v1.0 08/03/2005 Paul Lesniewski * Initial release spam_buttons/index.php0000644000000000000000000000077511127347307014130 0ustar rootroot, * Licensed under the GNU GPL. For full terms see the file COPYING. * * @package plugins * @subpackage spam_buttons * */ // retrieve the template vars // extract($t); ?> spam_buttons/templates/default/redirect_preview_pane.tpl0000644000000000000000000000245111127347504023010 0ustar rootroot, * Licensed under the GNU GPL. For full terms see the file COPYING. * * @package plugins * @subpackage spam_buttons * */ // retrieve the template vars // extract($t); // add message list refresh request if needed // if ($request_refresh_message_list) { if (strpos($redirect_location, '?') === FALSE) $redirect_location .= '?pp_rr_force=1'; else $redirect_location .= '&pp_rr_force=1'; } ?> spam_buttons/templates/default/read_menubar_buttons.tpl0000644000000000000000000000404011127347513022641 0ustar rootroot, * Licensed under the GNU GPL. For full terms see the file COPYING. * * @package plugins * @subpackage spam_buttons * */ // retrieve the template vars // extract($t); // if no buttons to be displayed, no output // if (empty($buttons)) return; ?>   | 
$button) { echo ' '; } ?>
spam_buttons/templates/default/redirect_standard.tpl0000644000000000000000000000124211127347525022124 0ustar rootroot, * Licensed under the GNU GPL. For full terms see the file COPYING. * * @package plugins * @subpackage spam_buttons * */ // retrieve the template vars // extract($t); ?> spam_buttons/version0000644000000000000000000000002311201130721013661 0ustar rootrootSpam Buttons 2.3.1 spam_buttons/options.php0000644000000000000000000006316611202760260014506 0ustar rootroot, * Licensed under the GNU GPL. For full terms see the file COPYING. * * @package plugins * @subpackage spam_buttons * */ /** * Display user configuration options on display preferences page * */ function spam_buttons_display_options_do() { include_once(SM_PATH . 'plugins/spam_buttons/functions.php'); global $data_dir, $username, $sb_reselect_messages, $javascript_on, $sb_reselect_messages_allow_override, $optpage_data, $sb_delete_after_report, $sb_delete_after_report_allow_override, $sb_move_after_report_spam, $sb_move_after_report_spam_allow_override, $sb_move_after_report_not_spam, $sb_move_after_report_not_spam_allow_override, $sb_report_spam_by_move_to_folder, $sb_report_not_spam_by_move_to_folder, $sb_copy_after_report_spam_allow_override, $sb_copy_after_report_spam, $sb_copy_after_report_not_spam_allow_override, $sb_copy_after_report_not_spam, $sb_suppress_spam_button_folder, $sb_suppress_not_spam_button_folder, $sb_suppress_spam_button_folder_allow_override, $sb_suppress_not_spam_button_folder_allow_override, $sb_show_spam_button_folder, $sb_report_not_spam_by_copy_to_folder, $sb_show_not_spam_button_folder, $sb_report_spam_by_copy_to_folder, $sb_show_spam_button_folder_allow_override, $sb_show_not_spam_button_folder_allow_override, $sb_move_to_other_message_after_report, $sb_move_to_other_message_after_report_allow_override; spam_buttons_init(); sq_change_text_domain('spam_buttons'); $my_optpage_values = array(); if ($sb_reselect_messages_allow_override && check_sm_version(1, 4, 11) && (empty($sb_report_spam_by_move_to_folder) || empty($sb_report_not_spam_by_move_to_folder))) { $sb_reselect_messages = getPref($data_dir, $username, 'sb_reselect_messages', $sb_reselect_messages); $my_optpage_values[] = array( 'name' => 'sb_reselect_messages', 'caption' => _("Reselect Messages After Reporting"), 'type' => SMOPT_TYPE_BOOLEAN, 'initial_value' => $sb_reselect_messages, 'refresh' => SMOPT_REFRESH_NONE, ); } if ($sb_delete_after_report_allow_override && empty($sb_report_spam_by_move_to_folder)) { $sb_delete_after_report = getPref($data_dir, $username, 'sb_delete_after_report', $sb_delete_after_report); $my_optpage_values[] = array( 'name' => 'sb_delete_after_report', 'caption' => _("Delete Spam After Reporting"), 'type' => SMOPT_TYPE_BOOLEAN, 'initial_value' => $sb_delete_after_report, 'refresh' => SMOPT_REFRESH_NONE, ); } $boxes = array(); if ($sb_move_after_report_spam_allow_override && (empty($sb_report_spam_by_move_to_folder) || $sb_report_spam_by_copy_to_folder)) { // Get folder list // global $username, $key, $imapServerAddress, $imapPort, $data_dir; if (check_sm_version(1, 5, 2)) { $key = FALSE; include_once(SM_PATH . 'functions/imap_general.php'); } $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0); $boxes = sqimap_mailbox_list($imapConnection); array_unshift($boxes, array('unformatted-disp' => _("[Do not move]"), 'formatted' => _("[Do not move]"), 'unformatted-dm' => 0, 'unformatted' => 0, 'raw' => '', 'id' => 0, 'flags' => array())); sqimap_logout($imapConnection); $sb_move_after_report_spam = getPref($data_dir, $username, 'sb_move_after_report_spam', $sb_move_after_report_spam); if ($sb_copy_after_report_spam && !$sb_copy_after_report_spam_allow_override) $opt_caption = _("Copy Spam After Reporting To"); else $opt_caption = _("Move Spam After Reporting To"); $my_optpage_values[] = array( 'name' => 'sb_move_after_report_spam', 'caption' => $opt_caption, 'type' => SMOPT_TYPE_FLDRLIST, 'posvals' => array('ignore' => $boxes), 'initial_value' => $sb_move_after_report_spam, 'refresh' => SMOPT_REFRESH_NONE, ); // add "copy instead of move" selection if needed // if ($sb_copy_after_report_spam_allow_override) { $sb_copy_after_report_spam = getPref($data_dir, $username, 'sb_copy_after_report_spam', $sb_copy_after_report_spam); $my_optpage_values[] = array( 'name' => 'sb_copy_after_report_spam', 'caption' => _("Copy Instead of Moving"), 'type' => SMOPT_TYPE_BOOLEAN, 'initial_value' => $sb_copy_after_report_spam, 'refresh' => SMOPT_REFRESH_NONE, ); } } if ($sb_move_after_report_not_spam_allow_override && (empty($sb_report_not_spam_by_move_to_folder) || $sb_report_not_spam_by_copy_to_folder)) { // Get folder list // if (empty($boxes)) { global $username, $key, $imapServerAddress, $imapPort, $data_dir; if (check_sm_version(1, 5, 2)) { $key = FALSE; include_once(SM_PATH . 'functions/imap_general.php'); } $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0); $boxes = sqimap_mailbox_list($imapConnection); array_unshift($boxes, array('unformatted-disp' => _("[Do not move]"), 'formatted' => _("[Do not move]"), 'unformatted-dm' => 0, 'unformatted' => 0, 'raw' => '', 'id' => 0, 'flags' => array())); sqimap_logout($imapConnection); } $sb_move_after_report_not_spam = getPref($data_dir, $username, 'sb_move_after_report_not_spam', $sb_move_after_report_not_spam); if ($sb_copy_after_report_not_spam && !$sb_copy_after_report_not_spam_allow_override) $opt_caption = _("Copy Non-Spam After Reporting To"); else $opt_caption = _("Move Non-Spam After Reporting To"); $my_optpage_values[] = array( 'name' => 'sb_move_after_report_not_spam', 'caption' => $opt_caption, 'type' => SMOPT_TYPE_FLDRLIST, 'posvals' => array('ignore' => $boxes), 'initial_value' => $sb_move_after_report_not_spam, 'refresh' => SMOPT_REFRESH_NONE, ); // add "copy instead of move" selection if needed // if ($sb_copy_after_report_not_spam_allow_override) { $sb_copy_after_report_not_spam = getPref($data_dir, $username, 'sb_copy_after_report_not_spam', $sb_copy_after_report_not_spam); $my_optpage_values[] = array( 'name' => 'sb_copy_after_report_not_spam', 'caption' => _("Copy Instead of Moving"), 'type' => SMOPT_TYPE_BOOLEAN, 'initial_value' => $sb_copy_after_report_not_spam, 'refresh' => SMOPT_REFRESH_NONE, ); } } // all these tests below are the possible permutations of // configuration settings that will result in report-by-move, // move-after-report, delete-after-report, or the possiblility // that the user may enable one of them // (in which case we want to display the option to configure // moving to another message after reporting) // if ($sb_move_to_other_message_after_report_allow_override && $javascript_on && ($sb_report_spam_by_move_to_folder || $sb_report_not_spam_by_move_to_folder || ($sb_delete_after_report_allow_override || $sb_delete_after_report) || ($sb_move_after_report_spam_allow_override && ($sb_copy_after_report_spam_allow_override || !$sb_copy_after_report_spam)) || (!$sb_move_after_report_spam_allow_override && $sb_move_after_report_spam && !$sb_copy_after_report_spam) || ($sb_move_after_report_not_spam_allow_override && ($sb_copy_after_report_not_spam_allow_override || !$sb_copy_after_report_not_spam)) || (!$sb_move_after_report_not_spam_allow_override && $sb_move_after_report_not_spam && !$sb_copy_after_report_not_spam))) { $sb_move_to_other_message_after_report = getPref($data_dir, $username, 'sb_move_to_other_message_after_report', $sb_move_to_other_message_after_report); $my_optpage_values[] = array( 'name' => 'sb_move_to_other_message_after_report', //TODO: note to user that this only takes effect if a report-by-move, move-after-report or delete-after-report functionality is currently enabled?? //TODO: well, we could just always move to next/previous message after reporting if the user likes that.... but that's more screwing up the report code, which is very complicated at this point, so for now, we'll set this option aside 'caption' => _("Move To Next Message After Reporting"), 'type' => SMOPT_TYPE_STRLIST, 'initial_value' => $sb_move_to_other_message_after_report, 'posvals' => array('' => _("Return to Message List"), 'next' => _("Next"), 'previous' => _("Previous")), 'refresh' => SMOPT_REFRESH_NONE, ); } if ($sb_show_spam_button_folder_allow_override) { // Get folder list // if (empty($boxes)) { global $username, $key, $imapServerAddress, $imapPort, $data_dir; if (check_sm_version(1, 5, 2)) { $key = FALSE; include_once(SM_PATH . 'functions/imap_general.php'); } $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0); $boxes = sqimap_mailbox_list($imapConnection); array_unshift($boxes, array('unformatted-disp' => _("[Always Display]"), 'formatted' => _("[Always Display]"), 'unformatted-dm' => 0, 'unformatted' => 0, 'raw' => '', 'id' => 0, 'flags' => array())); sqimap_logout($imapConnection); } else // remove the "Do Not Move" entry { array_shift($boxes); array_unshift($boxes, array('unformatted-disp' => _("[Always Display]"), 'formatted' => _("[Always Display]"), 'unformatted-dm' => 0, 'unformatted' => 0, 'raw' => '', 'id' => 0, 'flags' => array())); } $sb_show_spam_button_folder = getPref($data_dir, $username, 'sb_show_spam_button_folder', $sb_show_spam_button_folder); // this option used to be a string; these lines convert // values that may have already been stored in user prefs // as strings into proper array format (also unpacks // serialized arrays for SM v1.4.14+)... perhaps this // code should be removed a year (or more?) after 1.4.x // supports multiple select folder lists on the options page // (but not the unserialize() call) // if (empty($sb_show_spam_button_folder)) $sb_show_spam_button_folder = array(); else if (check_sm_version(1, 4, 14) && !is_array($sb_show_spam_button_folder)) $sb_show_spam_button_folder = unserialize($sb_show_spam_button_folder); if (!is_array($sb_show_spam_button_folder)) $sb_show_spam_button_folder = array($sb_show_spam_button_folder); if (check_sm_version(1, 4, 14)) { $my_optpage_values[] = array( 'name' => 'sb_show_spam_button_folder', 'caption' => _("Display Spam Button in Folders"), 'type' => SMOPT_TYPE_FLDRLIST_MULTI, 'posvals' => array('ignore' => $boxes), 'initial_value' => $sb_show_spam_button_folder, 'refresh' => SMOPT_REFRESH_NONE, ); } else { // In 1.4.13 and below, SM options don't allow multiple // select folder lists... // until they do, just use the first array element // $sb_show_spam_button_folder = array_shift($sb_show_spam_button_folder); $my_optpage_values[] = array( 'name' => 'sb_show_spam_button_folder', 'caption' => _("Display Spam Button in Folder"), 'type' => SMOPT_TYPE_FLDRLIST, 'posvals' => array('ignore' => $boxes), 'initial_value' => $sb_show_spam_button_folder, 'refresh' => SMOPT_REFRESH_NONE, ); } } if ($sb_show_not_spam_button_folder_allow_override) { // Get folder list // if (empty($boxes)) { global $username, $key, $imapServerAddress, $imapPort, $data_dir; if (check_sm_version(1, 5, 2)) { $key = FALSE; include_once(SM_PATH . 'functions/imap_general.php'); } $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0); $boxes = sqimap_mailbox_list($imapConnection); array_unshift($boxes, array('unformatted-disp' => _("[Always Display]"), 'formatted' => _("[Always Display]"), 'unformatted-dm' => 0, 'unformatted' => 0, 'raw' => '', 'id' => 0, 'flags' => array())); sqimap_logout($imapConnection); } // remove the "Do Not Move" entry (but only if it's there) else if (!$sb_show_spam_button_folder_allow_override) { array_shift($boxes); array_unshift($boxes, array('unformatted-disp' => _("[Always Display]"), 'formatted' => _("[Always Display]"), 'unformatted-dm' => 0, 'unformatted' => 0, 'raw' => '', 'id' => 0, 'flags' => array())); } $sb_show_not_spam_button_folder = getPref($data_dir, $username, 'sb_show_not_spam_button_folder', $sb_show_not_spam_button_folder); // this option used to be a string; these lines convert // values that may have already been stored in user prefs // as strings into proper array format (also unpacks // serialized arrays for SM v1.4.14+)... perhaps this // code should be removed a year (or more?) after 1.4.x // supports multiple select folder lists on the options page // (but not the unserialize() call) // if (empty($sb_show_not_spam_button_folder)) $sb_show_not_spam_button_folder = array(); else if (check_sm_version(1, 4, 14) && !is_array($sb_show_not_spam_button_folder)) $sb_show_not_spam_button_folder = unserialize($sb_show_not_spam_button_folder); if (!is_array($sb_show_not_spam_button_folder)) $sb_show_not_spam_button_folder = array($sb_show_not_spam_button_folder); if (check_sm_version(1, 4, 14)) { $my_optpage_values[] = array( 'name' => 'sb_show_not_spam_button_folder', 'caption' => _("Display Non-Spam Button in Folders"), 'type' => SMOPT_TYPE_FLDRLIST_MULTI, 'posvals' => array('ignore' => $boxes), 'initial_value' => $sb_show_not_spam_button_folder, 'refresh' => SMOPT_REFRESH_NONE, ); } else { // In 1.4.13 and below, SM options don't allow multiple // select folder lists... // until they do, just use the first array element // $sb_show_not_spam_button_folder = array_shift($sb_show_not_spam_button_folder); $my_optpage_values[] = array( 'name' => 'sb_show_not_spam_button_folder', 'caption' => _("Display Non-Spam Button in Folder"), 'type' => SMOPT_TYPE_FLDRLIST, 'posvals' => array('ignore' => $boxes), 'initial_value' => $sb_show_not_spam_button_folder[0], 'refresh' => SMOPT_REFRESH_NONE, ); } } if ($sb_suppress_spam_button_folder_allow_override) { // Get folder list // if (empty($boxes)) { global $username, $key, $imapServerAddress, $imapPort, $data_dir; if (check_sm_version(1, 5, 2)) { $key = FALSE; include_once(SM_PATH . 'functions/imap_general.php'); } $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0); $boxes = sqimap_mailbox_list($imapConnection); array_unshift($boxes, array('unformatted-disp' => _("[Always Display]"), 'formatted' => _("[Always Display]"), 'unformatted-dm' => 0, 'unformatted' => 0, 'raw' => '', 'id' => 0, 'flags' => array())); sqimap_logout($imapConnection); } // remove the "Do Not Move" entry (but only if it's there) else if (!$sb_show_spam_button_folder_allow_override && !$sb_show_not_spam_button_folder_allow_override) { array_shift($boxes); array_unshift($boxes, array('unformatted-disp' => _("[Always Display]"), 'formatted' => _("[Always Display]"), 'unformatted-dm' => 0, 'unformatted' => 0, 'raw' => '', 'id' => 0, 'flags' => array())); } $sb_suppress_spam_button_folder = getPref($data_dir, $username, 'sb_suppress_spam_button_folder', $sb_suppress_spam_button_folder); // this option used to be a string; these lines convert // values that may have already been stored in user prefs // as strings into proper array format (also unpacks // serialized arrays for SM v1.4.14+)... perhaps this // code should be removed a year (or more?) after 1.4.x // supports multiple select folder lists on the options page // (but not the unserialize() call) // if (empty($sb_suppress_spam_button_folder)) $sb_suppress_spam_button_folder = array(); else if (check_sm_version(1, 4, 14) && !is_array($sb_suppress_spam_button_folder)) $sb_suppress_spam_button_folder = unserialize($sb_suppress_spam_button_folder); if (!is_array($sb_suppress_spam_button_folder)) $sb_suppress_spam_button_folder = array($sb_suppress_spam_button_folder); if (check_sm_version(1, 4, 14)) { $my_optpage_values[] = array( 'name' => 'sb_suppress_spam_button_folder', 'caption' => _("Don't Display Spam Button in Folders"), 'type' => SMOPT_TYPE_FLDRLIST_MULTI, 'posvals' => array('ignore' => $boxes), 'initial_value' => $sb_suppress_spam_button_folder, 'refresh' => SMOPT_REFRESH_NONE, ); } else { // In 1.4.13 and below, SM options don't allow multiple // select folder lists... // until they do, just use the first array element // $sb_suppress_spam_button_folder = array_shift($sb_suppress_spam_button_folder); $my_optpage_values[] = array( 'name' => 'sb_suppress_spam_button_folder', 'caption' => _("Don't Display Spam Button in Folder"), 'type' => SMOPT_TYPE_FLDRLIST, 'posvals' => array('ignore' => $boxes), 'initial_value' => $sb_suppress_spam_button_folder[0], 'refresh' => SMOPT_REFRESH_NONE, ); } } if ($sb_suppress_not_spam_button_folder_allow_override) { // Get folder list // if (empty($boxes)) { global $username, $key, $imapServerAddress, $imapPort, $data_dir; if (check_sm_version(1, 5, 2)) { $key = FALSE; include_once(SM_PATH . 'functions/imap_general.php'); } $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0); $boxes = sqimap_mailbox_list($imapConnection); array_unshift($boxes, array('unformatted-disp' => _("[Always Display]"), 'formatted' => _("[Always Display]"), 'unformatted-dm' => 0, 'unformatted' => 0, 'raw' => '', 'id' => 0, 'flags' => array())); sqimap_logout($imapConnection); } // remove the "Do Not Move" entry (but only if it's there) else if (!$sb_show_spam_button_folder_allow_override && !$sb_show_not_spam_button_folder_allow_override && !$sb_suppress_spam_button_folder_allow_override) { array_shift($boxes); array_unshift($boxes, array('unformatted-disp' => _("[Always Display]"), 'formatted' => _("[Always Display]"), 'unformatted-dm' => 0, 'unformatted' => 0, 'raw' => '', 'id' => 0, 'flags' => array())); } $sb_suppress_not_spam_button_folder = getPref($data_dir, $username, 'sb_suppress_not_spam_button_folder', $sb_suppress_not_spam_button_folder); // this option used to be a string; these lines convert // values that may have already been stored in user prefs // as strings into proper array format (also unpacks // serialized arrays for SM v1.4.14+)... perhaps this // code should be removed a year (or more?) after 1.4.x // supports multiple select folder lists on the options page // (but not the unserialize() call) // if (empty($sb_suppress_not_spam_button_folder)) $sb_suppress_not_spam_button_folder = array(); else if (check_sm_version(1, 4, 14) && !is_array($sb_suppress_not_spam_button_folder)) $sb_suppress_not_spam_button_folder = unserialize($sb_suppress_not_spam_button_folder); if (!is_array($sb_suppress_not_spam_button_folder)) $sb_suppress_not_spam_button_folder = array($sb_suppress_not_spam_button_folder); if (check_sm_version(1, 4, 14)) { $my_optpage_values[] = array( 'name' => 'sb_suppress_not_spam_button_folder', 'caption' => _("Don't Display Non-Spam Button in Folders"), 'type' => SMOPT_TYPE_FLDRLIST_MULTI, 'posvals' => array('ignore' => $boxes), 'initial_value' => $sb_suppress_not_spam_button_folder, 'refresh' => SMOPT_REFRESH_NONE, ); } else { // In 1.4.13 and below, SM options don't allow multiple // select folder lists... // until they do, just use the first array element // $sb_suppress_not_spam_button_folder = array_shift($sb_suppress_not_spam_button_folder); $my_optpage_values[] = array( 'name' => 'sb_suppress_not_spam_button_folder', 'caption' => _("Don't Display Non-Spam Button in Folder"), 'type' => SMOPT_TYPE_FLDRLIST, 'posvals' => array('ignore' => $boxes), 'initial_value' => $sb_suppress_not_spam_button_folder, 'refresh' => SMOPT_REFRESH_NONE, ); } } if (!empty($my_optpage_values)) { $optpage_data['grps']['spam_buttons'] = _("Spam Reporting"); $optpage_data['vals']['spam_buttons'] = $my_optpage_values; } sq_change_text_domain('squirrelmail'); } spam_buttons/config_example.php0000644000000000000000000014005411203033006015753 0ustar rootroot, * Licensed under the GNU GPL. For full terms see the file COPYING. * * @package plugins * @subpackage spam_buttons * * See below, starting with "GENERAL OPTIONS" for the beginning * of the configuration section. * */ global $show_spam_buttons_on_read_body, $show_spam_buttons_on_message_list, $show_spam_link_on_read_body, $is_spam_shell_command, $is_spam_resend_destination, $is_not_spam_shell_command, $is_not_spam_resend_destination, $show_not_spam_button, $spam_button_text, $not_spam_button_text, $spam_report_email_method, $is_spam_subject_prefix, $is_not_spam_subject_prefix, $show_is_spam_button, $spam_report_smtpServerAddress, $spam_report_smtpPort, $spam_report_useSendmail, $spam_report_smtp_auth_mech, $spam_report_use_smtp_tls, $sb_debug, $sb_reselect_messages, $sb_reselect_messages_allow_override, $sb_delete_after_report, $sb_delete_after_report_allow_override, $sb_move_after_report_spam, $sb_move_after_report_spam_allow_override, $sb_move_after_report_not_spam, $sb_move_after_report_not_spam_allow_override, $sb_report_spam_by_move_to_folder, $sb_report_not_spam_by_move_to_folder, $sb_copy_after_report_spam_allow_override, $sb_copy_after_report_spam, $sb_copy_after_report_not_spam_allow_override, $sb_copy_after_report_not_spam, $sb_report_spam_by_copy_to_folder, $sb_report_not_spam_by_copy_to_folder, $sb_suppress_spam_button_folder, $sb_suppress_not_spam_button_folder, $sb_suppress_spam_button_folder_allow_override, $is_spam_keep_copy_in_sent, $sb_suppress_not_spam_button_folder_allow_override, $sb_spam_header_name, $sb_not_spam_header_name, $extra_buttons, $sb_spam_header_value, $sb_not_spam_header_value, $is_not_spam_keep_copy_in_sent, $sb_show_spam_button_folder, $sb_show_spam_button_folder_allow_override, $sb_show_not_spam_button_folder, $sb_show_not_spam_button_folder_allow_override, $reported_spam_text, $reported_not_spam_text, $sb_move_to_other_message_after_report, $sb_auto_create_destination_folder, $sb_move_to_other_message_after_report_allow_override, $sb_report_spam_by_custom_function, $sb_report_not_spam_by_custom_function; // ------------------------------------------------------------------- // // GENERAL OPTIONS // // You may change the button text, but if you do, there is a good // chance that those buttons will ONLY be displayed in one language // (unless you add your own translations to your locale files) // (however, the text "Report Spam" will be translated if you use // that) // // $spam_button_text = 'Report Spam'; $spam_button_text = 'Spam'; $not_spam_button_text = 'Not Spam'; // You may change the report confirmation text, but if you do, there // is a good chance that those buttons will ONLY be displayed in one // language (unless you add your own translations to your locale files) // $reported_spam_text = 'Successfully reported as spam'; $reported_not_spam_text = 'Successfully reported as non-spam'; // You can turn either of the buttons on/off as needed // // 0 = don't display button, 1 = display button // $show_not_spam_button = 1; $show_is_spam_button = 1; // Show spam buttons on message list page? // // 0 = no, 1 = yes // $show_spam_buttons_on_message_list = 1; // Show spam link when reading a message? // // 0 = no, 1 = yes // $show_spam_link_on_read_body = 1; // Show spam buttons when reading a message? // // NOTE: This is only functional as of // SquirrelMail 1.5.0 // // 0 = no, 1 = yes // $show_spam_buttons_on_read_body = 1; // When viewing an individual message, this plugin can determine if // it was tagged as spam or ham by your anti-spam scanner if a certain // header ($sb_spam_header_name) is added to the message. By comparing // the value of that header to what is configured here // ($sb_spam_header_value), this plugin can display only the HAM (not // spam) button on messages marked as spam, or the SPAM button on messages // marked as ham (not spam), or both buttons otherwise. // // When in use, this functionality will override // $sb_suppress_spam_button_folder, $sb_suppress_not_spam_button_folder // $sb_show_spam_button_folder and $sb_show_not_spam_button_folder // (buttons/links displayed in the read-message screen will be based on // the message headers and NOT what folder the message is in). // // Note that $sb_spam_header_name and $sb_not_spam_header_name are usually // the same thing in most spam scanner systems. // // The values for $sb_spam_header_value and $sb_not_spam_header_value // are regular expressions that will be used to compare the actual // message header values. // // $sb_spam_header_name = 'X-Spam-Status'; // $sb_spam_header_value = '/^Yes/i'; // $sb_not_spam_header_name = 'X-Spam-Status'; // $sb_not_spam_header_value = '/^No/i'; // $sb_spam_header_name = ''; $sb_spam_header_value = ''; $sb_not_spam_header_name = ''; $sb_not_spam_header_value = ''; // When any one of the report-by-move/copy or move/copy-after-report // options is set to a folder that does not exist for any one user, // should it be created automatically? If not, an error will occur // when the user reports spam/ham. // // 0 = don't create folders automatically // 1 = create folders if they do not exist upon spam/ham report // $sb_auto_create_destination_folder = 0; // Debugging: Turning this on will dump out the command text, the // message body and the results of the spam report if // done using a shell command. // If reported via email (attachment method only), you // currently only get the destination address and a // parsed version of the message body being reported. // // Note that you will get more verbose output from a sa-learn // command if you add the -D flag to the commands below (make sure // to remove it when you are done debugging!). // // 0 = off, 1 = on // $sb_debug = 0; // ------------------------------------------------------------------- // // BUTTON/LINK SUPPRESSION OPTIONS // // When the user is in this folder (or folders), suppress // all SPAM button/links // // Set to an empty list to show the spam button in all folders, // or the exact name of the specified spam folder(s) (the format // of which may depend on your IMAP server). // // In the case of collision with $sb_show_spam_button_folder // (see below), this setting will lose. // // $sb_suppress_spam_button_folder = array('INBOX.Spam'); // $sb_suppress_spam_button_folder = array('INBOX.Spam', 'INBOX.Junk'); // $sb_suppress_spam_button_folder = array(); // Should users be able to choose what the value // of $sb_suppress_spam_button_folder is? Set to 1 // if so, or set to 0 (zero) if the administrator's // setting above goes for all users. // $sb_suppress_spam_button_folder_allow_override = 1; // When the user is in this folder (or folders), suppress // all HAM (not spam) button/links // // Set to an empty list to show the ham button in all folders, // or the exact name of the specified ham folder(s) (the format // of which may depend on your IMAP server). // // In the case of collision with $sb_show_not_spam_button_folder // (see below), this setting will lose. // // $sb_suppress_not_spam_button_folder = array('INBOX.Ham'); // $sb_suppress_not_spam_button_folder = array('INBOX.Ham', 'INBOX.Personal'); // $sb_suppress_not_spam_button_folder = array(); // Should users be able to choose what the value // of $sb_suppress_not_spam_button_folder is? Set to 1 // if so, or set to 0 (zero) if the administrator's // setting above goes for all users. // $sb_suppress_not_spam_button_folder_allow_override = 0; // ------------------------------------------------------------------- // // BUTTON/LINK INCLUSION OPTIONS // // Only when the user is in this folder (or folders), // show SPAM button/links // // When this option is set to anything other than an // empty list, spam buttons/links won't be shown in // any folder other than the one(s) specified here. // // In the case of collision with // $sb_suppress_spam_button_folder, this setting will win. // // If set, this value must contain the exact name(s) // of the specified folder(s) (the format of which // may depend on your IMAP server). // // $sb_show_spam_button_folder = array('INBOX.Ham'); // $sb_show_spam_button_folder = array('INBOX.Ham', 'INBOX.Personal'); // $sb_show_spam_button_folder = array(); // Should users be able to choose what the value // of $sb_show_spam_button_folder is? Set to 1 // if so, or set to 0 (zero) if the administrator's // setting above goes for all users. // $sb_show_spam_button_folder_allow_override = 0; // Only when the user is in this folder (or folders), // show HAM (not spam) button/links // // When this option is set to anything other than an // empty list, ham buttons/links won't be shown in // any folder other than the one(s) specified here. // // In the case of collision with // $sb_suppress_not_spam_button_folder, this setting will win. // // If set, this value must contain the exact name(s) // of the specified folder(s) (the format of which // may depend on your IMAP server). // // $sb_show_not_spam_button_folder = array('INBOX.Spam'); // $sb_show_not_spam_button_folder = array('INBOX.Spam', 'INBOX.Junk'); // $sb_show_not_spam_button_folder = array(); // Should users be able to choose what the value // of $sb_show_not_spam_button_folder is? Set to 1 // if so, or set to 0 (zero) if the administrator's // setting above goes for all users. // $sb_show_not_spam_button_folder_allow_override = 1; // ------------------------------------------------------------------- // // POST-REPORT OPTIONS // // When reporting spam (NOT ham), should messages // be deleted afterward? // // NOTE that this will be ignored if $sb_move_after_report_spam // (or the user-overridden value for such) is turned on. // // NOTE that when using the move-to-folder type // reporting method, this feature will be disabled. // // 0 = no, 1 = yes // $sb_delete_after_report = 0; // Should users be able to choose what the value // of $sb_delete_after_report is? Set to 1 if so, // or set to 0 (zero) if the administrator's // setting above goes for all users. // $sb_delete_after_report_allow_override = 1; // When reporting spam, should messages be moved // to another folder afterward? // // Set to an empty string to disable, or the exact // name of the target folder (the format of which // may depend on your IMAP server). // // NOTE that this will take precedence over // $sb_delete_after_report. // // NOTE that when using the move-to-folder type // reporting method, this feature will be disabled. // // $sb_move_after_report_spam = 'INBOX.Spam'; // $sb_move_after_report_spam = ''; // Should users be able to choose what the value // of $sb_move_after_report_spam is? Set to 1 if so, // or set to 0 (zero) if the administrator's // setting above goes for all users. // $sb_move_after_report_spam_allow_override = 1; // Should $sb_move_after_report_spam COPY reported // messages instead of moving them? // // 0 = no, just move messages, 1 = yes, copy messages // // This setting has no effect when // $sb_move_after_report_spam is not enabled. // $sb_copy_after_report_spam = 0; // Should users be able to choose what the value // of $sb_copy_after_report_spam is? Set to 1 if so, // or set to 0 (zero) if the administrator's // setting above goes for all users. // $sb_copy_after_report_spam_allow_override = 1; // When reporting non-spam, should messages be moved // to another folder afterward? // // Set to an empty string to disable, or the exact // name of the target folder (the format of which // may depend on your IMAP server). // // NOTE that when using the move-to-folder type // reporting method, this feature will be disabled. // // $sb_move_after_report_not_spam = 'INBOX.Ham'; // $sb_move_after_report_not_spam = ''; // Should users be able to choose what the value // of $sb_move_after_report_not_spam is? Set to 1 if so, // or set to 0 (zero) if the administrator's // setting above goes for all users. // $sb_move_after_report_not_spam_allow_override = 1; // Should $sb_move_after_report_not_spam COPY reported // messages instead of moving them? // // 0 = no, just move messages, 1 = yes, copy messages // // This setting has no effect when // $sb_move_after_report_not_spam is not enabled. // $sb_copy_after_report_not_spam = 0; // Should users be able to choose what the value // of $sb_copy_after_report_not_spam is? Set to 1 if so, // or set to 0 (zero) if the administrator's // setting above goes for all users. // $sb_copy_after_report_not_spam_allow_override = 1; // When selecting messages to report from the // message list page, the messages will be re- // selected after they are reported (as of // SquirrelMail 1.4.11 and 1.5.2). You can turn // this functionality off by setting this to zero. // $sb_reselect_messages = 1; // Should users be able to choose what the value // of $sb_reselect_messages is? Set to 1 if so, // or set to 0 (zero) if the administrator's // setting above goes for all users. // $sb_reselect_messages_allow_override = 1; // When either report-by-move or delete-after-report is // enabled, should the user be directed to the next or // previous message after the report, or just back to // the message list? // // Acceptable values are "next", "previous" and "" (empty), // which indicates that the user will be returned to the // message list. // // $sb_move_to_other_message_after_report = 'next'; // $sb_move_to_other_message_after_report = 'previous'; // $sb_move_to_other_message_after_report = ''; // $sb_move_to_other_message_after_report = ''; // Should users be able to choose what the value // of $sb_move_to_other_message_after_report is? // Set to 1 if so, or set to 0 (zero) if the // administrator's setting above goes for all users. // $sb_move_to_other_message_after_report_allow_override = 1; // ------------------------------------------------------------------- // // REPORT BY MOVE-TO-FOLDER OPTIONS // // Be sure if you use this that you have NOT turned on // reporting by email, by shell command or by custom function. // // This reporting method does not acutually make any reports itself. // Instead, the message is moved to the specified folder and some // other process is assumed to examine the messages in that folder // on a regular basis. // // If you enable this reporting method, the report-and-delete and // report-and-move functions above will be automatically disabled. // // You will need to set these values to the exact name of the target // folders where messages will be moved. The format of the folder // names may depend on your IMAP server. // // $sb_report_spam_by_move_to_folder = 'INBOX.Spam'; // $sb_report_not_spam_by_move_to_folder = 'INBOX.Ham'; // $sb_report_spam_by_move_to_folder = ''; $sb_report_not_spam_by_move_to_folder = ''; // If messages should be copied instead of moved, set either of these // settings to 1. Leave as 0 (zero) if messages should be moved. // // Note that these settings have no effect if their counterparts // above are not enabled. // $sb_report_spam_by_copy_to_folder = 0; $sb_report_not_spam_by_copy_to_folder = 0; // ------------------------------------------------------------------- // // REPORT-BY-SHELL COMMAND OPTIONS // // Be sure if you use this that you have NOT turned on // reporting by email, by move-to-folder or by custom function. // // If you use a command-line utility for reporting spam/non-spam, // this is where you set it up. This plugin will append " < message" // to the end of such a command (without the quotes), where "message" // will be a file containing the full message as it was originally // received. // // If you need to include any information about the user for which // the report is being made, you can use these constants in your command: // // ###EMAIL_PREF### Will be replaced with the user's // main email address preference // setting (under Options -> Personal // Information) (email addresses under // Multiple Identiies not supported) // // ###EMAIL_ADDRESS### Will be replaced with the user's // full email address (based on the // login username and user's domain) // // ###USERNAME### Will be replaced with the username // portion of the user's email address // // ###DOMAIN### Will be replaced with the domain // portion of the user's email address // // // // Note that you are not necessarily limited to just calling a spam // reporting application; you can also do clever things such as dump // the message to a file that can be used to do cron-based reporting // at a later time. For example: // // $is_spam_shell_command = 'cat >> /path/to/spam-###EMAIL_ADDRESS###'; // $is_not_spam_shell_command = 'cat >> /path/to/ham-###EMAIL_ADDRESS###'; // // // // Sample for Bogofilter: // // $is_spam_shell_command = 'HOME=/home/###USERNAME### sudo -u ###USERNAME### /usr/bin/bogofilter -s'; // $is_not_spam_shell_command = 'HOME=/home/###USERNAME### sudo -u ###USERNAME### /usr/bin/bogofilter -n'; // // // // Sample for CRM114: // // $is_spam_shell_command = '/usr/bin/crm -u /home/crm114 mailfilter.crm --learnspam'; // $is_not_spam_shell_command = '/usr/bin/crm -u /home/crm114 mailfilter.crm --learnnonspam'; // // // // Sample for DSPAM: // // $is_spam_shell_command = '/usr/local/bin/dspam --user ###EMAIL_ADDRESS### --mode=teft --class=spam --source=error --client'; // $is_not_spam_shell_command = '/usr/local/bin/dspam --user ###EMAIL_ADDRESS### --mode=teft --class=innocent --source=error --client'; // // // // Sample for SpamAssassin: // // $is_spam_shell_command = '/usr/bin/sa-learn --spam --configpath=/etc/spamassassin -p /root/.spamassassin/user_prefs'; // $is_not_spam_shell_command = '/usr/bin/sa-learn --ham --configpath=/etc/spamassassin -p /root/.spamassassin/user_prefs'; // // // // Sample for SpamAssassin per-user configuration: // // $is_spam_shell_command = '/usr/bin/sa-learn --spam --username=###EMAIL_ADDRESS###'; // $is_not_spam_shell_command = '/usr/bin/sa-learn --ham --username=###EMAIL_ADDRESS###'; // // // // Sample for SpamAssassin per-user configuration using spamc/spamd: // // $is_spam_shell_command = '/usr/bin/spamc -L spam -d localhost -u ###EMAIL_ADDRESS###'; // $is_not_spam_shell_command = '/usr/bin/spamc -L ham -d localhost -u ###EMAIL_ADDRESS###'; // // // // Advanced sample for SpamAssassin: // // In order to make sure you are running sa-learn (or equivalent) as the correct user // (else it will be run as the user that your web server runs as), you may need to run // the command with sudo. In /etc/sudoers, you will want to set this: // // web_server_user ALL=(sa_user) NOPASSWD: /usr/bin/sa-learn, /usr/bin/spamassassin, /usr/bin/spamc // // Where you need to change "web_server_user" to the actual userID of the user running // your web server, and "sa_user" to the user that should run sa-learn (or spamassasin // or spamc). // // After that, one of the following command pairs should work for you (remember to // replace "sa_user" with the correct username): // // $is_spam_shell_command = 'sudo -u sa_user /usr/bin/sa-learn --spam'; // $is_not_spam_shell_command = 'sudo -u sa_user /usr/bin/sa-learn --ham'; // // $is_spam_shell_command = 'sudo -u sa_user /usr/bin/spamassassin -r --configpath=/etc/spamassassin -p /root/.spamassassin/user_prefs'; // $is_not_spam_shell_command = 'sudo -u sa_user /usr/bin/spamassassin -k --configpath=/etc/spamassassin -p /root/.spamassassin/user_prefs'; // // $is_spam_shell_command = 'sudo -u sa_user /usr/bin/spamc -L spam'; // $is_not_spam_shell_command = 'sudo -u sa_user /usr/bin/spamc -L ham'; // // // $is_spam_shell_command = ''; $is_not_spam_shell_command = ''; // ------------------------------------------------------------------- // // REPORT-BY-EMAIL OPTIONS // // Be sure if you use this that you have NOT turned on reporting // by shell command, by move-to-folder or by custom function. // // If you resend the message in order to report it as spam/non-spam, // specify the destination address here. // // If you need to include any information about the user for which // the report is being made, you can use these constants in the // destination address: // // ###EMAIL_PREF### Will be replaced with the user's // main email address preference // setting (under Options -> Personal // Information) (email addresses under // Multiple Identiies not supported) // // ###EMAIL_ADDRESS### Will be replaced with the user's // full email address (based on the // login username and user's domain) // // ###USERNAME### Will be replaced with the username // portion of the user's email address // // ###DOMAIN### Will be replaced with the domain // portion of the user's email address // // // $is_spam_resend_destination = 'spam_report'; // let SM append user's domain automatically // $is_not_spam_resend_destination = 'not_spam_report'; // // $is_spam_resend_destination = 'spam-###USERNAME###@###DOMAIN###'; // $is_not_spam_resend_destination = 'ham-###USERNAME###@###DOMAIN###'; // $is_spam_resend_destination = ''; $is_not_spam_resend_destination = ''; // When reporting via email, should the message be resent (leaving // all message headers intact), or should it be sent as an attachment? // // resend = 'bounce' // attach = 'attachment' // // $spam_report_email_method = 'bounce'; // $spam_report_email_method = 'attachment'; // When reporting via email by sending as an attachment, // should a copy of the spam notification message (with // the offending message attachment) be placed in the // user's sent folder? // // 1 = yes, 0 (zero) = no // $is_spam_keep_copy_in_sent = 0; $is_not_spam_keep_copy_in_sent = 0; // When reporting via email (at least when sending as attachment), you // may indicate any extra subject information here (default empty) // // When set to "SPAM", the subject might end up looking like "[SPAM: Buy our product!]" // $is_spam_subject_prefix = 'SPAM'; $is_not_spam_subject_prefix = 'HAM'; // You may also specify overrides for the SMTP server for the // email only (see SquirrelMail's main configuration file or // use config/conf.pl to understand what these settings normally // are). // // Set to empty strings to use system defaults. // $spam_report_smtpServerAddress = ''; $spam_report_smtpPort = ''; $spam_report_useSendmail = ''; $spam_report_smtp_auth_mech = ''; $spam_report_use_smtp_tls = ''; // ------------------------------------------------------------------- // // REPORT-BY-CUSTOM-FUNCTION OPTIONS // // Be sure if you use this that you have NOT turned on // reporting by email, by shell command or by move-to-folder. // // You must provide any custom PHP function defined here. // Each of these functions will be called with two parameters, // the first being an array of message ID strings for each // of the message(s) being reported (even when there is only // one message being reported). The second parameter will // usually be zero, but when the message being reported is an // attachment to another message, it will be its entity ID // within its parent message. // // The functions must return an empty string when all messages // were reported successfully, or an error message string // if reporting failed or any other problem occurred. // // Leave these empty when not using custom PHP callbacks // for spam/ham reporting. // // Sample custom functions that report the spam/ham by adding // the sender to a black/white-list are included near the // bottom of this file. // // $sb_report_spam_by_custom_function = 'report_spam_by_blacklist'; // $sb_report_not_spam_by_custom_function = 'report_ham_by_whitelist'; // $sb_report_spam_by_custom_function = ''; $sb_report_not_spam_by_custom_function = ''; // ------------------------------------------------------------------- // // EXTRA BUTTONS AND LINKS // // Any number of additional (custom) buttons or links may // be added to the SquirrelMail interface by declaring // them and their handlers here. // // Define any extra buttons or links here. // // Each one is keyed by its displayable name - what // the user will see in the interface. This text // will be passed through SquirrelMail's translation // engine, so if you use one of the sample names included // in the Spam Buttons translation file, it will be // translated into other languages (assuming translation // availability). You can also add your own translations // as needed for different text values. Currently, these // values are included as suggestions: // // Whitelist // Whitelist Sender // Blacklist // Blacklist Sender // // For each of these button/link names, a six-element array // is needed: // // The first element determines if the button will show up // on the message list screen. It can be set to 1 to // indicate that it should always be shown there, 0 (zero) // to indicate that it should never be shown there, or the // name of a custom callback function that can be used to // perform more complex operations to determine if the // button should be shown or not. If you define a custom // callback function, it will be called with two // arguments: first, the string "MESSAGE_LIST_BUTTON" (which // indicates that the plugin is asking if the button can be // shown on the message list page), and second, the username // of the current user who is logged in. The function must // then return either TRUE to indicate that the button is // to be shown, or FALSE when it should not. // // The second element determines if the link will show up // on the message view screen. It can be set to 1 to // indicate that it should always be shown there, 0 (zero) // to indicate that it should never be shown there, or the // name of a custom callback function that can be used to // perform more complex operations to determine if the // link should be shown or not. If you define a custom // callback function, it will be called with five // arguments: first, the string "MESSAGE_VIEW_LINK" (which // indicates that the plugin is asking if the link can be // shown on the message view page), second, the username // of the current user who is logged in, third, the email // address of the sender of the message currently being // viewed (it is possible to get more information about // the message if needed - see the example function below // to learn how), fourth, the message ID of the message // currently being viewed, and fifth, the message entity ID // if the message being viewed is an attachment to another // message (if not, it will be empty). The function must // then return either TRUE to indicate that the link is to // be shown, or FALSE when it should not. // // The third element determines if the button (as opposed to // the link explained above) will show up on the message view // screen (only applicable for SquirrelMail 1.5.2+). It can // be set to 1 to indicate that it should always be shown // there, 0 (zero) to indicate that it should never be shown // there, or the name of a custom callback function that can // be used to perform more complex operations to determine if // the button should be shown or not. If you define a custom // callback function, it will be called with five arguments: // first, the string "MESSAGE_VIEW_BUTTON" (which indicates // that the plugin is asking if the button can be shown on the // message view page), second, the username of the current // user who is logged in, third, the email address of the // sender of the message currently being viewed (it is possible // to get more information about the message if needed - see // the example function below to learn how) fourth, the message // ID of the message currently being viewed, and fifth, the // message entity ID if the message being viewed is an // attachment to another message (if not, it will be empty). // The function must then return either TRUE to indicate that // the button is to be shown, or FALSE when it should not. // // The fourth element is the name of the callback function // that will handle the requested action when this button // or link is clicked by the user. You must define this // function yourself (see below for an example). When called, // it is given five arguments, the first of which is the name // of the button that was clicked, although if your button names // have any non-alphanumeric characters in them (such as dashes, // spaces, etc.), those will be converted to underscores. The // second argument is the username of the user who is currently // logged in. The third argument is the email address of the // sender of the message that is being processed (it is possible // to get more information about the message if needed - see the // example function below to learn how). The fourth argument is // the message ID for the message that needs to be processed. // The fifth parameter is the message entity ID if the message // being processed is an attachment to another message (if not, // it will be empty). The function must then return either a // boolean (TRUE/FALSE) success indicator *OR* an array with two // elements. When using an array return value, the first element // is a boolean value that is TRUE if the message was processed // normally and FALSE if some error occured. The second element // is a string containing a note that will be displayed to the // user upon completion. Note that this message will be ignored // pending the following: // // The fifth and sixth elements are text strings that contain // the messages that will be displayed to the user upon // successful (but not failed) execution of a button or link // click. The fifth element is the message used when only one // message has been processed, and the sixth is the message used // when more than one message has been processed (this presumes // Germanic plurality rules, but these strings will be used with // ngettext(), so translators can correctly use their language's // native plurality rules) You may leave these blank and the // message returned by the callback function defined just above // will be used instead. This text will be passed through // SquirrelMail's translation engine, so if you use sample messages // included in the Spam Buttons translation file, it will be // translated into other languages (assuming translation // availability). You can also add your own translations as // needed for different message values. Currently, these messages // are included as suggestions: // // Sender has been blacklisted // Senders have been blacklisted // Sender has been whitelisted // Senders have been whitelisted // // $extra_buttons = array('Blacklist' => array(1, // 'is_not_blacklisted', // see below // 0, // 'blacklist', // see below // 'Sender has been blacklisted', // 'Senders have been blacklisted'), // 'Whitelist' => array(1, // 'is_not_whitelisted', // see below // 0, // 'whitelist', // see below // 'Sender has been whitelisted', // 'Senders have been whitelisted')); // $extra_buttons = array(); /** * Example custom button test function * * Determines if the current user has not yet whitelisted the given sender. * * Implementation is left to your imagination. * * @param string $action A string indicating what button or link * is being created ("MESSAGE_LIST_BUTTON", * "MESSAGE_VIEW_LINK", or * "MESSAGE_VIEW_BUTTON"). * @param string $user The user whose whitelist we should check. * @param string $sender The sender to check for (will be empty * when $action is "MESSAGE_LIST_BUTTON"). * @param string $message_id The ID of the message currently being * viewed, if any (will be empty when * $action is "MESSAGE_LIST_BUTTON"). * @param string $entity_id The entity ID of the message currently * being viewed when it is an attachment * to another message, if any (will be * empty when it is not an attachment, or * when $action is "MESSAGE_LIST_BUTTON"). * * @return boolean TRUE if the sender has NOT been whitelisted, * FALSE otherwise. * */ function is_not_whitelisted($action, $user, $sender, $message_id, $entity_id) { // you need to supply the functionality herein // return TRUE; // here is how you can use the Server Settings plugin // to ask it about a value on the server (assumes // you have a setting called "whitelist" that is // correctly configured therein) // include_once(SM_PATH . 'plugins/server_settings/functions.php'); return !server_settings_test_value('whitelist', $sender); // here is how you can retrieve additional headers from // the current message, in case you need them... // // this retrieves the message's Subject header in the format // array(0 => 'Subject:', 1 => 'This is my message subject') // $subject = ''; if (!empty($message_id)) $subject = sb_get_message_header($message_id, $entity_id, 'Subject'); } /** * Example custom button test function * * Determines if the current user has not yet blacklisted the given sender. * * Implementation is left to your imagination. * * @param string $action A string indicating what button or link * is being created ("MESSAGE_LIST_BUTTON", * "MESSAGE_VIEW_LINK", or * "MESSAGE_VIEW_BUTTON"). * @param string $user The user whose whitelist we should check. * @param string $sender The sender to check for (will be empty * when $action is "MESSAGE_LIST_BUTTON"). * @param string $message_id The ID of the message currently being * viewed, if any (will be empty when * $action is "MESSAGE_LIST_BUTTON"). * @param string $entity_id The entity ID of the message currently * being viewed when it is an attachment * to another message, if any (will be * empty when it is not an attachment, or * when $action is "MESSAGE_LIST_BUTTON"). * * @return boolean TRUE if the sender has NOT been blacklisted, * FALSE otherwise. * */ function is_not_blacklisted($action, $user, $sender, $message_id, $entity_id) { // you need to supply the functionality herein // return TRUE; // here is how you can use the Server Settings plugin // to ask it about a value on the server (assumes // you have a setting called "blacklist" that is // correctly configured therein) // include_once(SM_PATH . 'plugins/server_settings/functions.php'); return !server_settings_test_value('blacklist', $sender); // here is how you can retrieve additional headers from // the current message, in case you need them... // // this retrieves the message's Subject header in the format // array(0 => 'Subject:', 1 => 'This is my message subject') // $subject = ''; if (!empty($message_id)) $subject = sb_get_message_header($message_id, $entity_id, 'Subject'); } /** * Example custom button handler function * * Whitelist the given sender. * * Implementation is left to your imagination. * * @param string $button_name The name of the button or link * (with non-alphanumerics having * been replaced with underscores). * @param string $user The user whose whitelist we are adding to. * @param string $sender The sender to whitelist. * @param string $message_id The ID of the message currently being * processed. * @param string $entity_id The entity ID of the message currently * being processed when it is an attachment * to another message (otherwise, it will * be empty). * * @return array A two-element array, the first element being * a boolean value that is TRUE if the sender was * added to the whitelist normally and FALSE if * some error occured. The second element is a * string containing a note that usually contains * any error information that should be shown to * the user when an error occurs. * */ function whitelist($button_name, $user, $sender, $message_id, $entity_id) { // you need to supply the functionality herein // return TRUE; // if multiple entries into the whitelist is a possilbe problem // (caused by multiple clicks of a button from the message *list* // screen), then you make sure the user isn't already listed: // if (!is_not_whitelisted('', $user, $sender, $message_id, $entity_id)) return array(TRUE, ''); // here is how you can use the Server Settings plugin // to send the value to the server backend (assumes // you have a setting called "whitelist" that is // correctly configured therein) // include_once(SM_PATH . 'plugins/server_settings/functions.php'); if (server_settings_update_value('whitelist', $sender, '', '', TRUE)) return array(TRUE, ''); else return array(FALSE, 'ERROR attempting to whitelist ' . $sender); // here is how you can retrieve additional headers from // the current message, in case you need them... // // this retrieves the message's Subject header in the format // array(0 => 'Subject:', 1 => 'This is my message subject') // $subject = sb_get_message_header($message_id, $entity_id, 'Subject'); } /** * Example custom button handler function * * Blacklist the given sender. * * Implementation is left to your imagination. * * @param string $button_name The name of the button or link * (with non-alphanumerics having * been replaced with underscores). * @param string $user The user whose blacklist we are adding to. * @param string $sender The sender to blacklist. * @param string $message_id The ID of the message currently being * processed. * @param string $entity_id The entity ID of the message currently * being processed when it is an attachment * to another message (otherwise, it will * be empty). * * @return array A two-element array, the first element being * a boolean value that is TRUE if the sender was * added to the blacklist normally and FALSE if * some error occured. The second element is a * string containing a note that usually contains * any error information that should be shown to * the user when an error occurs. * */ function blacklist($button_name, $user, $sender, $message_id, $entity_id) { // you need to supply the functionality herein // return TRUE; // if multiple entries into the blacklist is a possilbe problem // (caused by multiple clicks of a button from the message *list* // screen), then you make sure the user isn't already listed: // if (!is_not_blacklisted('', $user, $sender, $message_id, $entity_id)) return array(TRUE, ''); // here is how you can use the Server Settings plugin // to send the value to the server backend (assumes // you have a setting called "blacklist" that is // correctly configured therein) // include_once(SM_PATH . 'plugins/server_settings/functions.php'); if (server_settings_update_value('blacklist', $sender, '', '', TRUE)) return array(TRUE, ''); else return array(FALSE, 'ERROR attempting to blacklist ' . $sender); // here is how you can retrieve additional headers from // the current message, in case you need them... // // this retrieves the message's Subject header in the format // array(0 => 'Subject:', 1 => 'This is my message subject') // $subject = sb_get_message_header($message_id, $entity_id, 'Subject'); } /** * Example custom spam report handler * * Reports one or more spam by blacklisting the message sender(s). * * This function is intended as an example for use with the * report-by-custom-function ($sb_report_spam_by_custom_function) * feature, and NOT particularly for use with the extra buttons * functionality, although it does also call to the example * blacklist() function above that is also used by the sample * extra button settings. * * @param array $message_ids An array of message IDs to be reported. * @param string $passed_ent_id The message entity being reported * (zero if the message itself is being * reported (only applicable when there * is just one element in the $message_ids * array)) * * @return string An error message if an error occurred, * empty string otherwise * */ function report_spam_by_blacklist($message_ids, $passed_ent_id) { // you need to supply the functionality herein // return ''; global $username, $sb_debug; $error = ''; $me = 'report_spam_by_blacklist'; include_once(SM_PATH . 'plugins/spam_buttons/functions.php'); spam_buttons_init(); // just loop through the messages, reporting one at a time // if (is_array($message_ids)) foreach ($message_ids as $messageID) { // here is how you can retrieve additional headers from // the message, in case you need them... // // this retrieves the message's From header in the format // array(0 => 'From:', 1 => '"Jose" ') // $sender = sb_get_message_header($messageID, $passed_ent_id, 'From'); // this parses out just the email address portion of the From header // if (function_exists('parseRFC822Address')) { $sender = parseRFC822Address($sender[1], 1); $sender = $sender[0][2] . '@' . $sender[0][3]; } else { $sender = parseAddress($sender[1], 1); $sender = $sender[0][0]; } // now, blacklist the sender // $ret = blacklist('', $username, $sender, $messageID, $passed_ent_id); if (is_array($ret) && empty($ret[0]) && !empty($ret[1])) $error = $ret[1]; // dump stuff out if debugging // if ($sb_debug) { echo '
REPORTED BY CUSTOM FUNCTION: ' . $me . '

'; echo '
SENDER REPORTED: ' . $sender . '

'; echo '
RESULTS FROM REPORT: (' . $error . ')

'; exit; } // oops, report failed - put together nicely formatted error message // if (!empty($error)) { $previous_domain = sq_change_text_domain('spam_buttons'); if (empty($passed_ent_id)) $error = str_replace(array('%1', '%2'), array($messageID, $error), _("ERROR: Problem reporting message ID %1: %2")); else $error = str_replace(array('%1', '%2', '%3'), array($messageID, $passed_ent_id, $error), _("ERROR: Problem reporting message ID %1 (entity %2): %3")); sq_change_text_domain($previous_domain); break; // out of foreach loop } } return $error; } /** * Example custom ham report handler * * Reports one or more ham by whitelisting the message sender(s). * * This function is intended as an example for use with the * report-by-custom-function ($sb_report_not_spam_by_custom_function) * feature, and NOT particularly for use with the extra buttons * functionality, although it does also call to the example * whitelist() function above that is also used by the sample * extra button settings. * * @param array $message_ids An array of message IDs to be reported. * @param string $passed_ent_id The message entity being reported * (zero if the message itself is being * reported (only applicable when there * is just one element in the $message_ids * array)) * * @return string An error message if an error occurred, * empty string otherwise * */ function report_ham_by_whitelist($message_ids, $passed_ent_id) { // you need to supply the functionality herein // return ''; global $username, $sb_debug; $error = ''; $me = 'report_spam_by_whitelist'; include_once(SM_PATH . 'plugins/spam_buttons/functions.php'); spam_buttons_init(); // just loop through the messages, reporting one at a time // if (is_array($message_ids)) foreach ($message_ids as $messageID) { // here is how you can retrieve additional headers from // the message, in case you need them... // // this retrieves the message's From header in the format // array(0 => 'From:', 1 => '"Jose" ') // $sender = sb_get_message_header($messageID, $passed_ent_id, 'From'); // this parses out just the email address portion of the From header // if (function_exists('parseRFC822Address')) { $sender = parseRFC822Address($sender[1], 1); $sender = $sender[0][2] . '@' . $sender[0][3]; } else { $sender = parseAddress($sender[1], 1); $sender = $sender[0][0]; } // now, whitelist the sender // $ret = whitelist('', $username, $sender, $messageID, $passed_ent_id); if (is_array($ret) && empty($ret[0]) && !empty($ret[1])) $error = $ret[1]; // dump stuff out if debugging // if ($sb_debug) { echo '
REPORTED BY CUSTOM FUNCTION: ' . $me . '

'; echo '
SENDER REPORTED: ' . $sender . '

'; echo '
RESULTS FROM REPORT: (' . $error . ')

'; exit; } // oops, report failed - put together nicely formatted error message // if (!empty($error)) { $previous_domain = sq_change_text_domain('spam_buttons'); if (empty($passed_ent_id)) $error = str_replace(array('%1', '%2'), array($messageID, $error), _("ERROR: Problem reporting message ID %1: %2")); else $error = str_replace(array('%1', '%2', '%3'), array($messageID, $passed_ent_id, $error), _("ERROR: Problem reporting message ID %1 (entity %2): %3")); sq_change_text_domain($previous_domain); break; // out of foreach loop } } return $error; } spam_buttons/spam_buttons.pot0000644000000000000000000001456511201130663015540 0ustar rootroot# LANGUAGE (xx_XX) SquirrelMail Spam Buttons Plugin Translation # Copyright (c) 2005-2009 The SquirrelMail Project Team # This file is distributed under the same license as the SquirrelMail package. # FIRST AUTHOR , YEAR. # $Id$ #, fuzzy msgid "" msgstr "" "Project-Id-Version: spam_buttons 2.3\n" "Report-Msgid-Bugs-To: Paul Lesniewski \n" "POT-Creation-Date: 2009-05-17 08:40-0700\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=CHARSET\n" "Content-Transfer-Encoding: 8bit\n" "Plural-Forms: nplurals=INTEGER; plural=EXPRESSION;\n" #: bounce_send.php:83 msgid "No resend destination specified" msgstr "" #: bounce_send.php:212 msgid "Could not establish connection to outgoing mail server" msgstr "" #: bounce_send.php:314 report.php:1660 #, php-format msgid "Could not find requested message: %s" msgstr "" #: bounce_send.php:349 msgid "" "Could not send report: \n" "%1\n" "%2 %3" msgstr "" #: bounce_send.php:351 msgid "Could not send report:
%1
%2 %3
" msgstr "" #: buttons.php:687 buttons.php:701 buttons.php:745 buttons.php:801 #, php-format msgid "" "Spam Buttons plugin is not configured correctly! Check custom button " "configuration array for \"%s\"" msgstr "" #: buttons.php:803 #, php-format msgid "Function \"%s\" not found in Spam Buttons plugin" msgstr "" #: compose_functions-1.4.10.php:481 compose_functions-1.4.11.php:521 #: compose_functions-1.4.14.php:532 compose_functions-1.5.2.php:494 #, php-format msgid "Error: Draft folder %s does not exist." msgstr "" #: compose_functions-1.4.10.php:493 msgid "Server replied: " msgstr "" #: compose_functions-1.4.11.php:272 compose_functions-1.4.11.php:289 #: compose_functions-1.4.14.php:269 compose_functions-1.4.14.php:286 msgid "Subject" msgstr "" #: compose_functions-1.4.11.php:273 compose_functions-1.4.11.php:290 #: compose_functions-1.4.14.php:270 compose_functions-1.4.14.php:287 msgid "From" msgstr "" #: compose_functions-1.4.11.php:274 compose_functions-1.4.11.php:291 #: compose_functions-1.4.14.php:271 compose_functions-1.4.14.php:288 msgid "Date" msgstr "" #: compose_functions-1.4.11.php:275 compose_functions-1.4.11.php:292 #: compose_functions-1.4.14.php:272 compose_functions-1.4.14.php:289 msgid "To" msgstr "" #: compose_functions-1.4.11.php:276 compose_functions-1.4.11.php:296 #: compose_functions-1.4.14.php:273 compose_functions-1.4.14.php:293 msgid "Cc" msgstr "" #: compose_functions-1.4.11.php:288 compose_functions-1.4.14.php:285 msgid "Original Message" msgstr "" #: compose_functions-1.4.11.php:533 compose_functions-1.4.14.php:544 #: compose_functions-1.5.2.php:506 msgid "Message not sent." msgstr "" #: compose_functions-1.4.11.php:533 compose_functions-1.4.14.php:544 #: compose_functions-1.5.2.php:512 msgid "Server replied:" msgstr "" #: config_example.php:1253 config_example.php:1366 config.php:1298 #: config.php:1411 msgid "ERROR: Problem reporting message ID %1: %2" msgstr "" #: config_example.php:1257 config_example.php:1370 config.php:1302 #: config.php:1415 msgid "ERROR: Problem reporting message ID %1 (entity %2): %3" msgstr "" #: options.php:60 msgid "Reselect Messages After Reporting" msgstr "" #: options.php:75 msgid "Delete Spam After Reporting" msgstr "" #: options.php:98 options.php:99 options.php:161 options.php:162 msgid "[Do not move]" msgstr "" #: options.php:112 msgid "Copy Spam After Reporting To" msgstr "" #: options.php:114 msgid "Move Spam After Reporting To" msgstr "" #: options.php:135 options.php:199 msgid "Copy Instead of Moving" msgstr "" #: options.php:176 msgid "Copy Non-Spam After Reporting To" msgstr "" #: options.php:178 msgid "Move Non-Spam After Reporting To" msgstr "" #: options.php:233 msgid "Move To Next Message After Reporting" msgstr "" #: options.php:236 msgid "Return to Message List" msgstr "" #: options.php:237 msgid "Next" msgstr "" #: options.php:238 msgid "Previous" msgstr "" #: options.php:259 options.php:260 options.php:271 options.php:272 #: options.php:349 options.php:350 options.php:363 options.php:364 #: options.php:440 options.php:441 options.php:455 options.php:456 #: options.php:532 options.php:533 options.php:548 options.php:549 msgid "[Always Display]" msgstr "" #: options.php:305 msgid "Display Spam Button in Folders" msgstr "" #: options.php:323 msgid "Display Spam Button in Folder" msgstr "" #: options.php:396 msgid "Display Non-Spam Button in Folders" msgstr "" #: options.php:414 msgid "Display Non-Spam Button in Folder" msgstr "" #: options.php:488 msgid "Don't Display Spam Button in Folders" msgstr "" #: options.php:506 msgid "Don't Display Spam Button in Folder" msgstr "" #: options.php:582 msgid "Don't Display Non-Spam Button in Folders" msgstr "" #: options.php:600 msgid "Don't Display Non-Spam Button in Folder" msgstr "" #: options.php:613 msgid "Spam Reporting" msgstr "" #: report.php:1328 msgid "The reported message is no longer available in this folder" msgstr "" #: report.php:1560 msgid "ERROR: Report could not be delivered" msgstr "" #: report.php:1726 msgid "" "ERROR: Could not open temp file; check attachments directory permissions" msgstr "" #: report.php:1738 msgid "ERROR %1: Problem reporting message ID %2: %3" msgstr "" #: report.php:1742 msgid "ERROR %1: Problem reporting message ID %2 (entity %4): %3" msgstr "" #: report.php:1973 #, php-format msgid "Function %s not found in Spam Buttons plugin" msgstr "" #: setup.php:112 msgid "Spam" msgstr "" #: setup.php:113 msgid "Report Spam" msgstr "" #: setup.php:114 msgid "Not Spam" msgstr "" #: setup.php:115 msgid "Successfully reported as spam" msgstr "" #: setup.php:116 msgid "Successfully reported as non-spam" msgstr "" #: setup.php:117 msgid "Whitelist" msgstr "" #: setup.php:118 msgid "Whitelist Sender" msgstr "" #: setup.php:119 msgid "Blacklist" msgstr "" #: setup.php:120 setup.php:121 msgid "Blacklist Sender" msgstr "" #: setup.php:122 setup.php:123 msgid "Sender has been blacklisted" msgid_plural "Senders have been blacklisted" msgstr[0] "" msgstr[1] "" #: setup.php:124 msgid "Senders have been blacklisted" msgstr "" #: setup.php:125 setup.php:126 msgid "Sender has been whitelisted" msgid_plural "Senders have been whitelisted" msgstr[0] "" msgstr[1] "" #: setup.php:127 msgid "Senders have been whitelisted" msgstr "" spam_buttons/patches/0000755000000000000000000000000011203034305013710 5ustar rootrootspam_buttons/patches/spam_buttons-squirrelmail-1.4.3.diff0000644000000000000000000000077310671754243022461 0ustar rootroot--- ../../functions/mailbox_display.php.orig 2007-09-12 05:14:46.000000000 -0700 +++ ../../functions/mailbox_display.php 2007-09-12 05:14:41.000000000 -0700 @@ -714,6 +714,7 @@ getMbxList($imapConnection); echo getButton('SUBMIT', 'moveButton',_("Move")) . "\n"; echo getButton('SUBMIT', 'attache',_("Forward")) . "\n"; + do_hook('mailbox_display_buttons'); echo " \n" . html_tag( 'td', '', 'right', '', 'nowrap' ); spam_buttons/patches/index.php0000644000000000000000000000077511127347320015552 0ustar rootroot\n" . html_tag( 'td', '', 'right', '', 'nowrap' ); spam_buttons/patches/spam_buttons-squirrelmail-1.4.4.diff0000644000000000000000000000076310212521464022445 0ustar rootroot--- ../../functions/mailbox_display.php.orig 2005-03-05 00:01:23.000000000 -0800 +++ ../../functions/mailbox_display.php 2005-03-05 00:01:07.000000000 -0800 @@ -718,6 +718,7 @@ getMbxList($imapConnection); echo getButton('SUBMIT', 'moveButton',_("Move")) . "\n"; echo getButton('SUBMIT', 'attache',_("Forward")) . "\n"; + do_hook('mailbox_display_buttons'); echo " \n" . html_tag( 'td', '', 'right', '', 'nowrap' ); spam_buttons/patches/.htaccess0000644000000000000000000000001611203034305015503 0ustar rootrootDeny from All spam_buttons/patches/spam_buttons-squirrelmail-1.5.1.diff0000644000000000000000000000067510741106226022447 0ustar rootroot--- ../../functions/mailbox_display.php.orig 2008-01-09 00:35:15.000000000 -0800 +++ ../../functions/mailbox_display.php 2008-01-09 00:57:05.000000000 -0800 @@ -1100,6 +1100,8 @@ } $aFormElements['account'] = array($iAccount,'hidden'); } + $ret = do_hook('message_list_controls', $aFormElements); + if (is_array($ret[1])) $aFormElements = $ret[1]; /* * This is the beginning of the message list table. spam_buttons/compose_functions-1.4.10.php0000644000000000000000000006334311127347155017276 0ustar rootroot, * Licensed under the GNU GPL. For full terms see the file COPYING. * * @package plugins * @subpackage spam_buttons * */ // // ripped from src/compose.php // /* This function is used when not sending or adding attachments */ function newMail ($mailbox='', $passed_id='', $passed_ent_id='', $action='', $session='') { global $editor_size, $default_use_priority, $body, $idents, $use_signature, $data_dir, $username, $username, $key, $imapServerAddress, $imapPort, $compose_messages, $composeMessage, $body_quote; global $languages, $squirrelmail_language, $default_charset; /* * Set $default_charset to correspond with the user's selection * of language interface. $default_charset global is not correct, * if message is composed in new window. */ set_my_charset(); $send_to = $send_to_cc = $send_to_bcc = $subject = $identity = ''; $mailprio = 3; if ($passed_id) { $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0); sqimap_mailbox_select($imapConnection, $mailbox); $message = sqimap_get_message($imapConnection, $passed_id, $mailbox); $body = ''; if ($passed_ent_id) { /* redefine the messsage in case of message/rfc822 */ $message = $message->getEntity($passed_ent_id); /* message is an entity which contains the envelope and type0=message * and type1=rfc822. The actual entities are childs from * $message->entities[0]. That's where the encoding and is located */ $entities = $message->entities[0]->findDisplayEntity (array(), $alt_order = array('text/plain')); if (!count($entities)) { $entities = $message->entities[0]->findDisplayEntity (array(), $alt_order = array('text/plain','html/plain')); } $orig_header = $message->rfc822_header; /* here is the envelope located */ /* redefine the message for picking up the attachments */ $message = $message->entities[0]; } else { $entities = $message->findDisplayEntity (array(), $alt_order = array('text/plain')); if (!count($entities)) { $entities = $message->findDisplayEntity (array(), $alt_order = array('text/plain', 'html/plain')); } $orig_header = $message->rfc822_header; } $type0 = $message->type0; $type1 = $message->type1; foreach ($entities as $ent) { $msg = $message->getEntity($ent); $type0 = $msg->type0; $type1 = $msg->type1; $unencoded_bodypart = mime_fetch_body($imapConnection, $passed_id, $ent); $body_part_entity = $message->getEntity($ent); $bodypart = decodeBody($unencoded_bodypart, $body_part_entity->header->encoding); if ($type1 == 'html') { $bodypart = str_replace("\n", ' ', $bodypart); $bodypart = preg_replace(array('/<\/?p>/i','/
<\/div>/i','//i','/<\/?div>/i'), "\n", $bodypart); $bodypart = str_replace(array(' ','>','<'),array(' ','>','<'),$bodypart); $bodypart = strip_tags($bodypart); } if (isset($languages[$squirrelmail_language]['XTRA_CODE']) && function_exists($languages[$squirrelmail_language]['XTRA_CODE'] . '_decode')) { if (mb_detect_encoding($bodypart) != 'ASCII') { $bodypart = call_user_func($languages[$squirrelmail_language]['XTRA_CODE'] . '_decode', $bodypart); } } if (isset($body_part_entity->header->parameters['charset'])) { $actual = $body_part_entity->header->parameters['charset']; } else { $actual = 'us-ascii'; } if ( $actual && is_conversion_safe($actual) && $actual != $default_charset){ $bodypart = charset_convert($actual,$bodypart,$default_charset,false); } $body .= $bodypart; } if ($default_use_priority) { $mailprio = substr($orig_header->priority,0,1); if (!$mailprio) { $mailprio = 3; } } else { $mailprio = ''; } //ClearAttachments($session); $identity = ''; $from_o = $orig_header->from; if (is_array($from_o)) { if (isset($from_o[0])) { $from_o = $from_o[0]; } } if (is_object($from_o)) { $orig_from = $from_o->getAddress(); } else { $orig_from = ''; } $identities = array(); if (count($idents) > 1) { foreach($idents as $nr=>$data) { if($enc_from_name == $orig_from) { $identity = $nr; break; } $identities[] = $enc_from_name; } $identity_match = $orig_header->findAddress($identities); if ($identity_match) { $identity = $identity_match; } } switch ($action) { case ('draft'): $use_signature = FALSE; $composeMessage->rfc822_header = $orig_header; $send_to = decodeHeader($orig_header->getAddr_s('to'),false,false,true); $send_to_cc = decodeHeader($orig_header->getAddr_s('cc'),false,false,true); $send_to_bcc = decodeHeader($orig_header->getAddr_s('bcc'),false,false,true); $send_from = $orig_header->getAddr_s('from'); $send_from_parts = new AddressStructure(); $send_from_parts = $orig_header->parseAddress($send_from); $send_from_add = $send_from_parts->mailbox . '@' . $send_from_parts->host; $identities = get_identities(); if (count($identities) > 0) { foreach($identities as $iddata) { if ($send_from_add == $iddata['email_address']) { $identity = $iddata['index']; break; } } } $subject = decodeHeader($orig_header->subject,false,false,true); /* remember the references and in-reply-to headers in case of an reply */ $composeMessage->rfc822_header->more_headers['References'] = $orig_header->references; $composeMessage->rfc822_header->more_headers['In-Reply-To'] = $orig_header->in_reply_to; // rewrap the body to clean up quotations and line lengths sqBodyWrap($body, $editor_size); $composeMessage = getAttachments($message, $composeMessage, $passed_id, $entities, $imapConnection); break; case ('edit_as_new'): $send_to = decodeHeader($orig_header->getAddr_s('to'),false,false,true); $send_to_cc = decodeHeader($orig_header->getAddr_s('cc'),false,false,true); $send_to_bcc = decodeHeader($orig_header->getAddr_s('bcc'),false,false,true); $subject = decodeHeader($orig_header->subject,false,false,true); $mailprio = $orig_header->priority; $orig_from = ''; $composeMessage = getAttachments($message, $composeMessage, $passed_id, $entities, $imapConnection); // rewrap the body to clean up quotations and line lengths sqBodyWrap($body, $editor_size); break; case ('forward'): $send_to = ''; $subject = getforwardSubject(decodeHeader($orig_header->subject,false,false,true)); $body = getforwardHeader($orig_header) . $body; // the logic for calling sqUnWordWrap here would be to allow the browser to wrap the lines // forwarded message text should be as undisturbed as possible, so commenting out this call // sqUnWordWrap($body); $composeMessage = getAttachments($message, $composeMessage, $passed_id, $entities, $imapConnection); //add a blank line after the forward headers $body = "\n" . $body; break; case ('forward_as_attachment'): $subject = getforwardSubject(decodeHeader($orig_header->subject,false,false,true)); $composeMessage = getMessage_RFC822_Attachment($message, $composeMessage, $passed_id, $passed_ent_id, $imapConnection); $body = ''; break; case ('reply_all'): if(isset($orig_header->mail_followup_to) && $orig_header->mail_followup_to) { $send_to = $orig_header->getAddr_s('mail_followup_to'); } else { $send_to_cc = replyAllString($orig_header); $send_to_cc = decodeHeader($send_to_cc,false,false,true); } case ('reply'): // skip this if send_to was already set right above here if(!$send_to) { $send_to = $orig_header->reply_to; if (is_array($send_to) && count($send_to)) { $send_to = $orig_header->getAddr_s('reply_to'); } else if (is_object($send_to)) { /* unneccesarry, just for failsafe purpose */ $send_to = $orig_header->getAddr_s('reply_to'); } else { $send_to = $orig_header->getAddr_s('from'); } } $send_to = decodeHeader($send_to,false,false,true); $subject = decodeHeader($orig_header->subject,false,false,true); $subject = str_replace('"', "'", $subject); $subject = trim($subject); if (substr(strtolower($subject), 0, 3) != 're:') { $subject = 'Re: ' . $subject; } /* this corrects some wrapping/quoting problems on replies */ $rewrap_body = explode("\n", $body); $from = (is_array($orig_header->from)) ? $orig_header->from[0] : $orig_header->from; $body = ''; $strip_sigs = getPref($data_dir, $username, 'strip_sigs'); foreach ($rewrap_body as $line) { if ($strip_sigs && substr($line,0,3) == '-- ') { break; } if (preg_match("/^(>+)/", $line, $matches)) { $gt = $matches[1]; $body .= $body_quote . str_replace("\n", "\n$body_quote$gt ", rtrim($line)) ."\n"; } else { $body .= $body_quote . (!empty($body_quote) ? ' ' : '') . str_replace("\n", "\n$body_quote" . (!empty($body_quote) ? ' ' : ''), rtrim($line)) . "\n"; } } //rewrap the body to clean up quotations and line lengths $body = sqBodyWrap ($body, $editor_size); $body = getReplyCitation($from , $orig_header->date) . $body; $composeMessage->reply_rfc822_header = $orig_header; break; default: break; } /// CHANGE FOR SPAM_BUTTONS PLUGIN /// $compose_messages[$session] = $composeMessage; /// sqsession_register($compose_messages, 'compose_messages'); /// session_write_close(); /// sqimap_logout($imapConnection); } $ret = array( 'send_to' => $send_to, 'send_to_cc' => $send_to_cc, 'send_to_bcc' => $send_to_bcc, 'subject' => $subject, 'mailprio' => $mailprio, 'body' => $body, 'identity' => $identity ); return ($ret); } /* function newMail() */ function getforwardSubject($subject) { if ((substr(strtolower($subject), 0, 4) != 'fwd:') && (substr(strtolower($subject), 0, 5) != '[fwd:') && (substr(strtolower($subject), 0, 6) != '[ fwd:')) { $subject = '[Fwd: ' . $subject . ']'; } return $subject; } function getMessage_RFC822_Attachment($message, $composeMessage, $passed_id, $passed_ent_id='', $imapConnection) { global $attachment_dir, $username, $data_dir; $hashed_attachment_dir = getHashedDir($username, $attachment_dir); if (!$passed_ent_id) { $body_a = sqimap_run_command($imapConnection, 'FETCH '.$passed_id.' BODY.PEEK[]', TRUE, $response, $readmessage, TRUE); } else { $body_a = sqimap_run_command($imapConnection, 'FETCH '.$passed_id.' BODY.PEEK['.$passed_ent_id.']', TRUE, $response, $readmessage, TRUE); $message = $message->parent; } if ($response == 'OK') { $subject = encodeHeader($message->rfc822_header->subject); array_shift($body_a); array_pop($body_a); $body = implode('', $body_a) . "\r\n"; $localfilename = GenerateRandomString(32, 'FILE', 7); $full_localfilename = "$hashed_attachment_dir/$localfilename"; $fp = fopen($full_localfilename, 'w'); fwrite ($fp, $body); fclose($fp); $composeMessage->initAttachment('message/rfc822',$subject.'.msg', $full_localfilename); } return $composeMessage; } /** * temporary function to make use of the deliver class. * In the future the responsable backend should be automaticly loaded * and conf.pl should show a list of available backends. * The message also should be constructed by the message class. */ function deliverMessage($composeMessage, $draft=false) { global $send_to, $send_to_cc, $send_to_bcc, $mailprio, $subject, $body, $username, $popuser, $usernamedata, $identity, $idents, $data_dir, $request_mdn, $request_dr, $default_charset, $color, $useSendmail, $domain, $action, $default_move_to_sent, $move_to_sent; global $imapServerAddress, $imapPort, $sent_folder, $key; /* --- do we need to do overrides again here? should not need to, but // someone reported problems with the default not being overriden // when using this reporting method --- global $spam_report_email_method, $spam_report_smtpServerAddress, $spam_report_smtpPort, $spam_report_useSendmail, $spam_report_smtp_auth_mech, $spam_report_use_smtp_tls, $smtpServerAddress, $smtpPort, $useSendmail, $smtp_auth_mech, $use_smtp_tls, $sb_debug; spam_buttons_init(); // take care of overrides for SMTP server // if (!empty($spam_report_smtpServerAddress)) $smtpServerAddress = $spam_report_smtpServerAddress; if (!empty($spam_report_smtpPort)) $smtpPort = $spam_report_smtpPort; if ($spam_report_useSendmail !== '') $useSendmail = $spam_report_useSendmail; if (!empty($spam_report_smtp_auth_mech)) $smtp_auth_mech = $spam_report_smtp_auth_mech; if (!empty($spam_report_use_smtp_tls)) $use_smtp_tls = $spam_report_use_smtp_tls; --- */ $rfc822_header = $composeMessage->rfc822_header; $abook = addressbook_init(false, true); $rfc822_header->to = $rfc822_header->parseAddress($send_to,true, array(), '', $domain, array(&$abook,'lookup')); $rfc822_header->cc = $rfc822_header->parseAddress($send_to_cc,true,array(), '',$domain, array(&$abook,'lookup')); $rfc822_header->bcc = $rfc822_header->parseAddress($send_to_bcc,true, array(), '',$domain, array(&$abook,'lookup')); $rfc822_header->priority = $mailprio; $rfc822_header->subject = $subject; $special_encoding=''; if (strtolower($default_charset) == 'iso-2022-jp') { if (mb_detect_encoding($body) == 'ASCII') { $special_encoding = '8bit'; } else { $body = mb_convert_encoding($body, 'JIS'); $special_encoding = '7bit'; } } $composeMessage->setBody($body); if (ereg("^([^@%/]+)[@%/](.+)$", $username, $usernamedata)) { $popuser = $usernamedata[1]; $domain = $usernamedata[2]; unset($usernamedata); } else { $popuser = $username; } $reply_to = ''; $from_mail = $idents[$identity]['email_address']; $full_name = $idents[$identity]['full_name']; $reply_to = $idents[$identity]['reply_to']; if (!$from_mail) { $from_mail = "$popuser@$domain"; } $rfc822_header->from = $rfc822_header->parseAddress($from_mail,true); if ($full_name) { $from = $rfc822_header->from[0]; if (!$from->host) $from->host = $domain; $full_name_encoded = encodeHeader($full_name); if ($full_name_encoded != $full_name) { $from_addr = $full_name_encoded .' <'.$from->mailbox.'@'.$from->host.'>'; } else { $from_addr = '"'.$full_name .'" <'.$from->mailbox.'@'.$from->host.'>'; } $rfc822_header->from = $rfc822_header->parseAddress($from_addr,true); } if ($reply_to) { $rfc822_header->reply_to = $rfc822_header->parseAddress($reply_to,true); } /* Receipt: On Read */ if (isset($request_mdn) && $request_mdn) { $rfc822_header->dnt = $rfc822_header->parseAddress($from_mail,true); } /* Receipt: On Delivery */ if (isset($request_dr) && $request_dr) { $rfc822_header->more_headers['Return-Receipt-To'] = $from_mail; } /* multipart messages */ if (count($composeMessage->entities)) { $message_body = new Message(); $message_body->body_part = $composeMessage->body_part; $composeMessage->body_part = ''; $mime_header = new MessageHeader; $mime_header->type0 = 'text'; $mime_header->type1 = 'plain'; if ($special_encoding) { $mime_header->encoding = $special_encoding; } else { $mime_header->encoding = '8bit'; } if ($default_charset) { $mime_header->parameters['charset'] = $default_charset; } $message_body->mime_header = $mime_header; array_unshift($composeMessage->entities, $message_body); $content_type = new ContentType('multipart/mixed'); } else { $content_type = new ContentType('text/plain'); if ($special_encoding) { $rfc822_header->encoding = $special_encoding; } else { $rfc822_header->encoding = '8bit'; } if ($default_charset) { $content_type->properties['charset']=$default_charset; } } $rfc822_header->content_type = $content_type; $composeMessage->rfc822_header = $rfc822_header; /* Here you can modify the message structure just before we hand it over to deliver */ /// CHANGE FOR SPAM_BUTTONS PLUGIN /// $hookReturn = do_hook('compose_send', $composeMessage); /// /* Get any changes made by plugins to $composeMessage. */ /// if ( is_object($hookReturn[1]) ) { /// $composeMessage = $hookReturn[1]; /// } if (!$useSendmail && !$draft) { require_once(SM_PATH . 'class/deliver/Deliver_SMTP.class.php'); $deliver = new Deliver_SMTP(); global $smtpServerAddress, $smtpPort, $pop_before_smtp; $authPop = (isset($pop_before_smtp) && $pop_before_smtp) ? true : false; get_smtp_user($user, $pass); $stream = $deliver->initStream($composeMessage,$domain,0, $smtpServerAddress, $smtpPort, $user, $pass, $authPop); } elseif (!$draft) { require_once(SM_PATH . 'class/deliver/Deliver_SendMail.class.php'); global $sendmail_path; $deliver = new Deliver_SendMail(); $stream = $deliver->initStream($composeMessage,$sendmail_path); } elseif ($draft) { global $draft_folder; require_once(SM_PATH . 'class/deliver/Deliver_IMAP.class.php'); $imap_stream = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0); if (sqimap_mailbox_exists ($imap_stream, $draft_folder)) { require_once(SM_PATH . 'class/deliver/Deliver_IMAP.class.php'); $imap_deliver = new Deliver_IMAP(); $length = $imap_deliver->mail($composeMessage); sqimap_append ($imap_stream, $draft_folder, $length); $imap_deliver->mail($composeMessage, $imap_stream); sqimap_append_done ($imap_stream, $draft_folder); sqimap_logout($imap_stream); unset ($imap_deliver); return $length; } else { $msg = '
'.sprintf(_("Error: Draft folder %s does not exist."), $draft_folder); plain_error_message($msg, $color); return false; } } $succes = false; if ($stream) { $length = $deliver->mail($composeMessage, $stream); $succes = $deliver->finalizeStream($stream); } if (!$succes) { $msg = $deliver->dlv_msg . '
' . _("Server replied: ") . $deliver->dlv_ret_nr . ' '. $deliver->dlv_server_msg; plain_error_message($msg, $color); } else { unset ($deliver); $move_to_sent = getPref($data_dir,$username,'move_to_sent'); $imap_stream = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0); /* Move to sent code */ /// CHANGE FOR SPAM_BUTTONS PLUGIN (added next 2 lines) global $sb_keep_copy_in_sent; if ($sb_keep_copy_in_sent) { if (isset($default_move_to_sent) && ($default_move_to_sent != 0)) { $svr_allow_sent = true; } else { $svr_allow_sent = false; } if (isset($sent_folder) && (($sent_folder != '') || ($sent_folder != 'none')) && sqimap_mailbox_exists( $imap_stream, $sent_folder)) { $fld_sent = true; } else { $fld_sent = false; } if ((isset($move_to_sent) && ($move_to_sent != 0)) || (!isset($move_to_sent))) { $lcl_allow_sent = true; } else { $lcl_allow_sent = false; } if (($fld_sent && $svr_allow_sent && !$lcl_allow_sent) || ($fld_sent && $lcl_allow_sent)) { global $passed_id, $mailbox, $action; if ($action == 'reply' || $action == 'reply_all') { $save_reply_with_orig=getPref($data_dir,$username,'save_reply_with_orig'); if ($save_reply_with_orig) { $sent_folder = $mailbox; } } sqimap_append ($imap_stream, $sent_folder, $length); require_once(SM_PATH . 'class/deliver/Deliver_IMAP.class.php'); $imap_deliver = new Deliver_IMAP(); $imap_deliver->mail($composeMessage, $imap_stream); sqimap_append_done ($imap_stream, $sent_folder); unset ($imap_deliver); } /// CHANGE FOR SPAM_BUTTONS PLUGIN (added next line) } global $passed_id, $mailbox, $action; ClearAttachments($composeMessage); if ($action == 'reply' || $action == 'reply_all') { sqimap_mailbox_select ($imap_stream, $mailbox); sqimap_messages_flag ($imap_stream, $passed_id, $passed_id, 'Answered', false); } sqimap_logout($imap_stream); } return $succes; } if (!function_exists('ClearAttachments')) { function ClearAttachments($composeMessage) { if ($composeMessage->att_local_name) { $attached_file = $composeMessage->att_local_name; if (file_exists($attached_file)) { unlink($attached_file); } } for ($i=0, $entCount=count($composeMessage->entities);$i< $entCount; ++$i) { ClearAttachments($composeMessage->entities[$i]); } } } if (!function_exists('is_conversion_safe')) { /** * Function informs if it is safe to convert given charset to the one that is used by user. * * It is safe to use conversion only if user uses utf-8 encoding and when * converted charset is similar to the one that is used by user. * * @param string $input_charset Charset of text that needs to be converted * @return bool is it possible to convert to user's charset */ function is_conversion_safe($input_charset) { global $languages, $sm_notAlias, $default_charset, $lossy_encoding; if (isset($lossy_encoding) && $lossy_encoding ) return true; // convert to lower case $input_charset = strtolower($input_charset); // Is user's locale Unicode based ? if ( $default_charset == "utf-8" ) { return true; } // Charsets that are similar switch ($default_charset): case "windows-1251": if ( $input_charset == "iso-8859-5" || $input_charset == "koi8-r" || $input_charset == "koi8-u" ) { return true; } else { return false; } case "windows-1257": if ( $input_charset == "iso-8859-13" || $input_charset == "iso-8859-4" ) { return true; } else { return false; } case "iso-8859-4": if ( $input_charset == "iso-8859-13" || $input_charset == "windows-1257" ) { return true; } else { return false; } case "iso-8859-5": if ( $input_charset == "windows-1251" || $input_charset == "koi8-r" || $input_charset == "koi8-u" ) { return true; } else { return false; } case "iso-8859-13": if ( $input_charset == "iso-8859-4" || $input_charset == "windows-1257" ) { return true; } else { return false; } case "koi8-r": if ( $input_charset == "windows-1251" || $input_charset == "iso-8859-5" || $input_charset == "koi8-u" ) { return true; } else { return false; } case "koi8-u": if ( $input_charset == "windows-1251" || $input_charset == "iso-8859-5" || $input_charset == "koi8-r" ) { return true; } else { return false; } default: return false; endswitch; } } spam_buttons/compose_functions-1.5.2.php0000644000000000000000000006534011127347205017213 0ustar rootroot, * Licensed under the GNU GPL. For full terms see the file COPYING. * * @package plugins * @subpackage spam_buttons * */ include_once(SM_PATH . 'functions/identity.php'); // // ripped from src/compose.php // /* This function is used when not sending or adding attachments */ function newMail ($mailbox='', $passed_id='', $passed_ent_id='', $action='', $session='') { global $editor_size, $default_use_priority, $body, $idents, $use_signature, $data_dir, $username, $key, $imapServerAddress, $imapPort, $composeMessage, $body_quote, $request_mdn, $request_dr, $mdn_user_support, $languages, $squirrelmail_language, $default_charset; /* * Set $default_charset to correspond with the user's selection * of language interface. $default_charset global is not correct, * if message is composed in new window. */ set_my_charset(); $send_to = $send_to_cc = $send_to_bcc = $subject = $identity = ''; $mailprio = 3; if ($passed_id) { $imapConnection = sqimap_login($username, false, $imapServerAddress, $imapPort, 0); sqimap_mailbox_select($imapConnection, $mailbox); $message = sqimap_get_message($imapConnection, $passed_id, $mailbox); $body = ''; if ($passed_ent_id) { /* redefine the messsage in case of message/rfc822 */ $message = $message->getEntity($passed_ent_id); /* message is an entity which contains the envelope and type0=message * and type1=rfc822. The actual entities are childs from * $message->entities[0]. That's where the encoding and is located */ $entities = $message->entities[0]->findDisplayEntity (array(), $alt_order = array('text/plain')); if (!count($entities)) { $entities = $message->entities[0]->findDisplayEntity (array(), $alt_order = array('text/plain','text/html')); } $orig_header = $message->rfc822_header; /* here is the envelope located */ /* redefine the message for picking up the attachments */ $message = $message->entities[0]; } else { $entities = $message->findDisplayEntity (array(), $alt_order = array('text/plain')); if (!count($entities)) { $entities = $message->findDisplayEntity (array(), $alt_order = array('text/plain','text/html')); } $orig_header = $message->rfc822_header; } $type0 = $message->type0; $type1 = $message->type1; foreach ($entities as $ent) { $msg = $message->getEntity($ent); $type0 = $msg->type0; $type1 = $msg->type1; $unencoded_bodypart = mime_fetch_body($imapConnection, $passed_id, $ent); $body_part_entity = $message->getEntity($ent); $bodypart = decodeBody($unencoded_bodypart, $body_part_entity->header->encoding); if ($type1 == 'html') { $bodypart = str_replace("\n", ' ', $bodypart); $bodypart = preg_replace(array('/<\/?p>/i','/
<\/div>/i','//i','/<\/?div>/i'), "\n", $bodypart); $bodypart = str_replace(array(' ','>','<'),array(' ','>','<'),$bodypart); $bodypart = strip_tags($bodypart); } if (isset($languages[$squirrelmail_language]['XTRA_CODE']) && function_exists($languages[$squirrelmail_language]['XTRA_CODE'] . '_decode')) { if (mb_detect_encoding($bodypart) != 'ASCII') { $bodypart = call_user_func($languages[$squirrelmail_language]['XTRA_CODE'] . '_decode', $bodypart); } } // charset encoding in compose form stuff if (isset($body_part_entity->header->parameters['charset'])) { $actual = $body_part_entity->header->parameters['charset']; } else { $actual = 'us-ascii'; } if ( $actual && is_conversion_safe($actual) && $actual != $default_charset){ $bodypart = charset_convert($actual,$bodypart,$default_charset,false); } // end of charset encoding in compose $body .= $bodypart; } if ($default_use_priority) { $mailprio = substr($orig_header->priority,0,1); if (!$mailprio) { $mailprio = 3; } } else { $mailprio = ''; } $from_o = $orig_header->from; if (is_array($from_o)) { if (isset($from_o[0])) { $from_o = $from_o[0]; } } if (is_object($from_o)) { $orig_from = $from_o->getAddress(); } else { $orig_from = ''; } $identities = array(); if (count($idents) > 1) { foreach($idents as $nr=>$data) { $enc_from_name = '"'.$data['full_name'].'" <'. $data['email_address'].'>'; if(strtolower($enc_from_name) == strtolower($orig_from)) { $identity = $nr; break; } $identities[] = $enc_from_name; } $identity_match = $orig_header->findAddress($identities); if ($identity_match) { $identity = $identity_match; } } switch ($action) { case ('draft'): $use_signature = FALSE; $composeMessage->rfc822_header = $orig_header; $send_to = decodeHeader($orig_header->getAddr_s('to'),false,false,true); $send_to_cc = decodeHeader($orig_header->getAddr_s('cc'),false,false,true); $send_to_bcc = decodeHeader($orig_header->getAddr_s('bcc'),false,false,true); $send_from = $orig_header->getAddr_s('from'); $send_from_parts = new AddressStructure(); $send_from_parts = $orig_header->parseAddress($send_from); $send_from_add = $send_from_parts->mailbox . '@' . $send_from_parts->host; $identity = find_identity(array($send_from_add)); $subject = decodeHeader($orig_header->subject,false,false,true); // Remember the receipt settings $request_mdn = $mdn_user_support && !empty($orig_header->dnt) ? '1' : '0'; $request_dr = $mdn_user_support && !empty($orig_header->drnt) ? '1' : '0'; /* remember the references and in-reply-to headers in case of an reply */ //FIXME: it would be better to fiddle with headers inside of the message object or possibly when delivering the message to its destination (drafts folder?); is this possible? $composeMessage->rfc822_header->more_headers['References'] = $orig_header->references; $composeMessage->rfc822_header->more_headers['In-Reply-To'] = $orig_header->in_reply_to; // rewrap the body to clean up quotations and line lengths sqBodyWrap($body, $editor_size); $composeMessage = getAttachments($message, $composeMessage, $passed_id, $entities, $imapConnection); break; case ('edit_as_new'): $send_to = decodeHeader($orig_header->getAddr_s('to'),false,false,true); $send_to_cc = decodeHeader($orig_header->getAddr_s('cc'),false,false,true); $send_to_bcc = decodeHeader($orig_header->getAddr_s('bcc'),false,false,true); $subject = decodeHeader($orig_header->subject,false,false,true); $mailprio = $orig_header->priority; $orig_from = ''; $composeMessage = getAttachments($message, $composeMessage, $passed_id, $entities, $imapConnection); // rewrap the body to clean up quotations and line lengths sqBodyWrap($body, $editor_size); break; case ('forward'): $send_to = ''; $subject = getforwardSubject(decodeHeader($orig_header->subject,false,false,true)); $body = getforwardHeader($orig_header) . $body; // the logic for calling sqUnWordWrap here would be to allow the browser to wrap the lines // forwarded message text should be as undisturbed as possible, so commenting out this call // sqUnWordWrap($body); $composeMessage = getAttachments($message, $composeMessage, $passed_id, $entities, $imapConnection); //add a blank line after the forward headers $body = "\n" . $body; break; case ('forward_as_attachment'): $subject = getforwardSubject(decodeHeader($orig_header->subject,false,false,true)); $composeMessage = getMessage_RFC822_Attachment($message, $composeMessage, $passed_id, $passed_ent_id, $imapConnection); $body = ''; break; case ('reply_all'): if(isset($orig_header->mail_followup_to) && $orig_header->mail_followup_to) { $send_to = $orig_header->getAddr_s('mail_followup_to'); } else { $send_to_cc = replyAllString($orig_header); $send_to_cc = decodeHeader($send_to_cc,false,false,true); } case ('reply'): // skip this if send_to was already set right above here if(!$send_to) { $send_to = $orig_header->reply_to; if (is_array($send_to) && count($send_to)) { $send_to = $orig_header->getAddr_s('reply_to'); } else if (is_object($send_to)) { /* unneccesarry, just for failsafe purpose */ $send_to = $orig_header->getAddr_s('reply_to'); } else { $send_to = $orig_header->getAddr_s('from'); } } $send_to = decodeHeader($send_to,false,false,true); $subject = decodeHeader($orig_header->subject,false,false,true); $subject = str_replace('"', "'", $subject); $subject = trim($subject); if (substr(strtolower($subject), 0, 3) != 're:') { $subject = 'Re: ' . $subject; } /* this corrects some wrapping/quoting problems on replies */ $rewrap_body = explode("\n", $body); $from = (is_array($orig_header->from) && !empty($orig_header->from)) ? $orig_header->from[0] : $orig_header->from; $body = ''; $strip_sigs = getPref($data_dir, $username, 'strip_sigs'); foreach ($rewrap_body as $line) { if ($strip_sigs && substr($line,0,3) == '-- ') { break; } if (preg_match("/^(>+)/", $line, $matches)) { $gt = $matches[1]; $body .= $body_quote . str_replace("\n", "\n$body_quote$gt ", rtrim($line)) ."\n"; } else { $body .= $body_quote . (!empty($body_quote) ? ' ' : '') . str_replace("\n", "\n$body_quote" . (!empty($body_quote) ? ' ' : ''), rtrim($line)) . "\n"; } } //rewrap the body to clean up quotations and line lengths $body = sqBodyWrap ($body, $editor_size); $body = getReplyCitation($from , $orig_header->date) . $body; $composeMessage->reply_rfc822_header = $orig_header; break; default: break; } //FIXME: we used to register $compose_messages in the session here, but not any more - so do we still need the session_write_close() and sqimap_logout() here? We probably need the IMAP logout, but what about the session closure? /// CHANGE FOR SPAM BUTTONS PLUGIN -- comment out next 2 lines /// session_write_close(); /// sqimap_logout($imapConnection); } $ret = array( 'send_to' => $send_to, 'send_to_cc' => $send_to_cc, 'send_to_bcc' => $send_to_bcc, 'subject' => $subject, 'mailprio' => $mailprio, 'body' => $body, 'identity' => $identity ); return ($ret); } /* function newMail() */ function getforwardSubject($subject) { if ((substr(strtolower($subject), 0, 4) != 'fwd:') && (substr(strtolower($subject), 0, 5) != '[fwd:') && (substr(strtolower($subject), 0, 6) != '[ fwd:')) { $subject = '[Fwd: ' . $subject . ']'; } return $subject; } function getMessage_RFC822_Attachment($message, $composeMessage, $passed_id, $passed_ent_id='', $imapConnection) { if (!$passed_ent_id) { $body_a = sqimap_run_command($imapConnection, 'FETCH '.$passed_id.' RFC822', TRUE, $response, $readmessage, TRUE); } else { $body_a = sqimap_run_command($imapConnection, 'FETCH '.$passed_id.' BODY['.$passed_ent_id.']', TRUE, $response, $readmessage, TRUE); $message = $message->parent; } if ($response == 'OK') { $subject = encodeHeader($message->rfc822_header->subject); array_shift($body_a); array_pop($body_a); $body = implode('', $body_a) . "\r\n"; global $username, $attachment_dir; $hashed_attachment_dir = getHashedDir($username, $attachment_dir); $localfilename = sq_get_attach_tempfile(); $fp = fopen($hashed_attachment_dir . '/' . $localfilename, 'wb'); fwrite ($fp, $body); fclose($fp); $composeMessage->initAttachment('message/rfc822',$subject.'.eml', $localfilename); } return $composeMessage; } /** * temporary function to make use of the deliver class. * In the future the responsible backend should be automaticly loaded * and conf.pl should show a list of available backends. * The message also should be constructed by the message class. * * @param object $composeMessage The message being sent. Please note * that it is passed by reference and * will be returned modified, with additional * headers, such as Message-ID, Date, In-Reply-To, * References, and so forth. * * @return boolean FALSE if delivery failed, or some non-FALSE value * upon success. * */ function deliverMessage(&$composeMessage, $draft=false) { global $send_to, $send_to_cc, $send_to_bcc, $mailprio, $subject, $body, $username, $identity, $idents, $data_dir, $request_mdn, $request_dr, $default_charset, $useSendmail, $domain, $action, $default_move_to_sent, $move_to_sent, $imapServerAddress, $imapPort, $sent_folder, $key; /// CHANGE FOR SPAM_BUTTONS PLUGIN /* --- do we need to do overrides again here? should not need to, but // someone reported problems with the default not being overriden // when using this reporting method --- global $spam_report_email_method, $spam_report_smtpServerAddress, $spam_report_smtpPort, $spam_report_useSendmail, $spam_report_smtp_auth_mech, $spam_report_use_smtp_tls, $smtpServerAddress, $smtpPort, $useSendmail, $smtp_auth_mech, $use_smtp_tls, $sb_debug; spam_buttons_init(); // take care of overrides for SMTP server // if (!empty($spam_report_smtpServerAddress)) $smtpServerAddress = $spam_report_smtpServerAddress; if (!empty($spam_report_smtpPort)) $smtpPort = $spam_report_smtpPort; if ($spam_report_useSendmail !== '') $useSendmail = $spam_report_useSendmail; if (!empty($spam_report_smtp_auth_mech)) $smtp_auth_mech = $spam_report_smtp_auth_mech; if (!empty($spam_report_use_smtp_tls)) $use_smtp_tls = $spam_report_use_smtp_tls; --- */ $rfc822_header = $composeMessage->rfc822_header; $abook = addressbook_init(false, true); $rfc822_header->to = $rfc822_header->parseAddress($send_to,true, array(), '', $domain, array(&$abook,'lookup')); $rfc822_header->cc = $rfc822_header->parseAddress($send_to_cc,true,array(), '',$domain, array(&$abook,'lookup')); $rfc822_header->bcc = $rfc822_header->parseAddress($send_to_bcc,true, array(), '',$domain, array(&$abook,'lookup')); $rfc822_header->priority = $mailprio; $rfc822_header->subject = $subject; $special_encoding=''; if (strtolower($default_charset) == 'iso-2022-jp') { if (mb_detect_encoding($body) == 'ASCII') { $special_encoding = '8bit'; } else { $body = mb_convert_encoding($body, 'JIS'); $special_encoding = '7bit'; } } $composeMessage->setBody($body); $reply_to = ''; $reply_to = $idents[$identity]['reply_to']; $from_addr = build_from_header($identity); $rfc822_header->from = $rfc822_header->parseAddress($from_addr,true); if ($reply_to) { $rfc822_header->reply_to = $rfc822_header->parseAddress($reply_to,true); } /* Receipt: On Read */ if (isset($request_mdn) && $request_mdn) { $rfc822_header->dnt = $rfc822_header->parseAddress($from_addr,true); } elseif (isset($rfc822_header->dnt)) { unset($rfc822_header->dnt); } /* Receipt: On Delivery */ if (!empty($request_dr)) { //FIXME: it would be better to fiddle with headers inside of the message object or possibly when delivering the message to its destination; is this possible? $rfc822_header->more_headers['Return-Receipt-To'] = $from->mailbox.'@'.$from->domain; } elseif (isset($rfc822_header->more_headers['Return-Receipt-To'])) { unset($rfc822_header->more_headers['Return-Receipt-To']); } /* multipart messages */ if (count($composeMessage->entities)) { $message_body = new Message(); $message_body->body_part = $composeMessage->body_part; $composeMessage->body_part = ''; $mime_header = new MessageHeader; $mime_header->type0 = 'text'; $mime_header->type1 = 'plain'; if ($special_encoding) { $mime_header->encoding = $special_encoding; } else { $mime_header->encoding = '8bit'; } if ($default_charset) { $mime_header->parameters['charset'] = $default_charset; } $message_body->mime_header = $mime_header; array_unshift($composeMessage->entities, $message_body); $content_type = new ContentType('multipart/mixed'); } else { $content_type = new ContentType('text/plain'); if ($special_encoding) { $rfc822_header->encoding = $special_encoding; } else { $rfc822_header->encoding = '8bit'; } if ($default_charset) { $content_type->properties['charset']=$default_charset; } } $rfc822_header->content_type = $content_type; $composeMessage->rfc822_header = $rfc822_header; if ($action == 'reply' || $action == 'reply_all') { global $passed_id, $passed_ent_id; $reply_id = $passed_id; $reply_ent_id = $passed_ent_id; } else { $reply_id = ''; $reply_ent_id = ''; } /* Here you can modify the message structure just before we hand it over to deliver; plugin authors note that $composeMessage is sent and modified by reference since 1.5.2 */ /// CHANGE FOR SPAM BUTTONS PLUGIN -- comment out next line /// do_hook('compose_send', $composeMessage); if (!$useSendmail && !$draft) { require_once(SM_PATH . 'class/deliver/Deliver_SMTP.class.php'); $deliver = new Deliver_SMTP(); global $smtpServerAddress, $smtpPort, $pop_before_smtp; $authPop = (isset($pop_before_smtp) && $pop_before_smtp) ? true : false; get_smtp_user($user, $pass); $stream = $deliver->initStream($composeMessage,$domain,0, $smtpServerAddress, $smtpPort, $user, $pass, $authPop); } elseif (!$draft) { require_once(SM_PATH . 'class/deliver/Deliver_SendMail.class.php'); global $sendmail_path, $sendmail_args; // Check for outdated configuration if (!isset($sendmail_args)) { if ($sendmail_path=='/var/qmail/bin/qmail-inject') { $sendmail_args = ''; } else { $sendmail_args = '-i -t'; } } $deliver = new Deliver_SendMail(array('sendmail_args'=>$sendmail_args)); $stream = $deliver->initStream($composeMessage,$sendmail_path); } elseif ($draft) { global $draft_folder; $imap_stream = sqimap_login($username, false, $imapServerAddress, $imapPort, 0); if (sqimap_mailbox_exists ($imap_stream, $draft_folder)) { require_once(SM_PATH . 'class/deliver/Deliver_IMAP.class.php'); $imap_deliver = new Deliver_IMAP(); $success = $imap_deliver->mail($composeMessage, $imap_stream, $reply_id, $reply_ent_id, $imap_stream, $draft_folder); sqimap_logout($imap_stream); unset ($imap_deliver); $composeMessage->purgeAttachments(); return $success; } else { //FIXME: htmlspecialchars is applied when msg is assigned to template; is it safe to remove it from the following line? //SPAM BUTTONS NOTE: htmlspecialchars is not applied to $draft_folder below in anticipation of the core using sq_htmlspecialchars when strings are assinged to the template $msg = "\n" . sprintf(_("Error: Draft folder %s does not exist."), $draft_folder); plain_error_message($msg); return false; } } $success = false; if ($stream) { $deliver->mail($composeMessage, $stream, $reply_id, $reply_ent_id); $success = $deliver->finalizeStream($stream); } if (!$success) { // $deliver->dlv_server_msg is not always server's reply $msg = _("Message not sent.") . "\n" . $deliver->dlv_msg; if (!empty($deliver->dlv_server_msg)) { // add 'server replied' part only when it is not empty. // Delivery error can be generated by delivery class itself $msg .= "\n" . _("Server replied:") . ' ' . $deliver->dlv_ret_nr . ' ' . //SPAM BUTTONS NOTE: htmlspecialchars is not applied to $deliver->dlv_server_msg below in anticipation of the core using sq_htmlspecialchars when strings are assinged to the template nl2br($deliver->dlv_server_msg); } plain_error_message($msg); } else { unset ($deliver); $imap_stream = sqimap_login($username, false, $imapServerAddress, $imapPort, 0); // mark as replied or forwarded if applicable // global $what, $iAccount, $startMessage, $passed_id, $mailbox; if ($action=='reply' || $action=='reply_all' || $action=='forward' || $action=='forward_as_attachment') { require(SM_PATH . 'functions/mailbox_display.php'); $aMailbox = sqm_api_mailbox_select($imap_stream, $iAccount, $mailbox,array('setindex' => $what, 'offset' => $startMessage),array()); switch($action) { case 'reply': case 'reply_all': // check if we are allowed to set the \\Answered flag if (in_array('\\answered',$aMailbox['PERMANENTFLAGS'], true)) { $aUpdatedMsgs = sqimap_toggle_flag($imap_stream, array($passed_id), '\\Answered', true, false); if (isset($aUpdatedMsgs[$passed_id]['FLAGS'])) { /** * Only update the cached headers if the header is * cached. */ if (isset($aMailbox['MSG_HEADERS'][$passed_id])) { $aMailbox['MSG_HEADERS'][$passed_id]['FLAGS'] = $aMsg['FLAGS']; } } } break; case 'forward': case 'forward_as_attachment': // check if we are allowed to set the $Forwarded flag (RFC 4550 paragraph 2.8) if (in_array('$forwarded',$aMailbox['PERMANENTFLAGS'], true) || in_array('\\*',$aMailbox['PERMANENTFLAGS'])) { $aUpdatedMsgs = sqimap_toggle_flag($imap_stream, array($passed_id), '$Forwarded', true, false); if (isset($aUpdatedMsgs[$passed_id]['FLAGS'])) { if (isset($aMailbox['MSG_HEADERS'][$passed_id])) { $aMailbox['MSG_HEADERS'][$passed_id]['FLAGS'] = $aMsg['FLAGS']; } } } break; } /** * Write mailbox with updated seen flag information back to cache. */ if(isset($aUpdatedMsgs[$passed_id])) { $mailbox_cache[$iAccount.'_'.$aMailbox['NAME']] = $aMailbox; sqsession_register($mailbox_cache,'mailbox_cache'); } } // move to sent folder // /// CHANGE FOR SPAM_BUTTONS PLUGIN (added next 2 lines) global $sb_keep_copy_in_sent; if ($sb_keep_copy_in_sent) { $move_to_sent = getPref($data_dir,$username,'move_to_sent'); if (isset($default_move_to_sent) && ($default_move_to_sent != 0)) { $svr_allow_sent = true; } else { $svr_allow_sent = false; } if (isset($sent_folder) && (($sent_folder != '') || ($sent_folder != 'none')) && sqimap_mailbox_exists( $imap_stream, $sent_folder)) { $fld_sent = true; } else { $fld_sent = false; } if ((isset($move_to_sent) && ($move_to_sent != 0)) || (!isset($move_to_sent))) { $lcl_allow_sent = true; } else { $lcl_allow_sent = false; } if (($fld_sent && $svr_allow_sent && !$lcl_allow_sent) || ($fld_sent && $lcl_allow_sent)) { if ($action == 'reply' || $action == 'reply_all') { $save_reply_with_orig=getPref($data_dir,$username,'save_reply_with_orig'); if ($save_reply_with_orig) { $sent_folder = $mailbox; } } require_once(SM_PATH . 'class/deliver/Deliver_IMAP.class.php'); $imap_deliver = new Deliver_IMAP(); $imap_deliver->mail($composeMessage, $imap_stream, $reply_id, $reply_ent_id, $imap_stream, $sent_folder); unset ($imap_deliver); } /// CHANGE FOR SPAM_BUTTONS PLUGIN (added next line) } // final cleanup // $composeMessage->purgeAttachments(); sqimap_logout($imap_stream); } return $success; } spam_buttons/bounce_send.php0000644000000000000000000002475711140721774015312 0ustar rootroot, * Licensed under the GNU GPL. For full terms see the file COPYING. * * @package plugins * @subpackage spam_buttons * * This file is originally based on the Bounce plugin by Seth E. * Randall, massively re-worked for Spam Buttons 2.0 by Paul * Lesniewski. * */ /* Notes: RFC 2822 - redirect specifications are in section 3.6.6 http://www.ietf.org/rfc/rfc2822.txt RFC 822 - some notes about message ID are in section 4.6.1 http://www.ietf.org/rfc/rfc0822.txt RFC 2076 - lists common Resent-X headers in section 3.14 http://www.ietf.org/rfc/rfc2076.txt Summary: All headers on the original message must be preserved as-is. Add at least the first four of these fields, prepending them as a group to the beginning of all the preserved/original headers: Resent-From: {Bouncer} Resent-To: {Recipient of the "bounce"} Resent-Date: {Time the message was redirected/bounced} Resent-Message-ID: {New message ID for the bounce message} Resent-User-Agent: {The user agent used to send the bounce message} Resent-Subject: {New subject if you changed it during the bounce} Note that the resent headers are supposed to preceed all other headers and that if resent again, another new set of them (keeping them grouped) should be added to the top of the headers again */ global $imapConnection, $key, $imapServerAddress, $username, $imapPort, $mailbox, $passed_id, $passed_ent_id, $useSendmail, $uid_support, $mbx_response, $domain, $encode_header_key, $version; if (check_sm_version(1, 5, 2)) { $key = FALSE; $uid_support = TRUE; $version = SM_VERSION; } $rn = "\r\n"; sqGetGlobalVar('passed_ent_id', $passed_ent_id, SQ_FORM); if (sqGetGlobalVar('passed_id', $passed_id, SQ_FORM)) // fix for Dovecot UIDs can be bigger than normal integers $passed_id = (preg_match('/^[0-9]+$/', $passed_id) ? $passed_id : '0'); // identities // include_once(SM_PATH . 'plugins/spam_buttons/bounce_identity.php'); $idents = get_identities(); if (!sqgetGlobalVar('bounce_send_to', $bounce_send_to, SQ_FORM)) { global $color; sq_change_text_domain('spam_buttons'); $msg = _("No resend destination specified"); sq_change_text_domain('squirrelmail'); $ret = plain_error_message($msg, $color); if (check_sm_version (1, 5, 2)) { echo $ret; global $oTemplate; $oTemplate->display('footer.tpl'); } exit; } // initiate IMAP server connection if none already exists // if (!is_resource($imapConnection)) { $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0); if (!$imapConnection) die('ERROR: Could not establish IMAP connection'); } if (empty($mbx_response)) { $mbx_response = sqimap_mailbox_select($imapConnection, $mailbox); } // get original message in parsed form, just so // we can initiate SMTP/Sendmail stream below // $fetch = ''; $composeMessage = sqimap_get_message($imapConnection, $passed_id, $mailbox); if (!empty($passed_ent_id)) { $fetch = $passed_ent_id . '.'; $composeMessage = $composeMessage->getEntity($passed_ent_id); } // try to guess what identity to send from, // based on original message sender/recipients // $orig_header = $composeMessage->rfc822_header; // ripped from src/compose.php from 1.4.11SVN on 2007/09/11 // (also matches 1.5.2 99%) // $from_o = $orig_header->from; if (is_array($from_o)) { if (isset($from_o[0])) { $from_o = $from_o[0]; } } if (is_object($from_o)) { $orig_from = $from_o->getAddress(); } else { $orig_from = ''; } $identities = array(); $identity = 0; if (count($idents) > 1) { foreach($idents as $nr=>$data) { $enc_from_name = '"'.$data['full_name'].'" <'. $data['email_address'].'>'; if(strtolower($enc_from_name) == strtolower($orig_from)) { $identity = $nr; break; } $identities[] = $enc_from_name; } $identity_match = $orig_header->findAddress($identities); if ($identity_match) { $identity = $identity_match; } } // however, only want to have the recipient for the bounce, remove all the // other recipients while the SMTP/Sendmail stream is being created (they // will be added back when actually sending the message headers/data) // $composeMessage->rfc822_header->to = array(); $composeMessage->rfc822_header->cc = array(); $composeMessage->rfc822_header->bcc = $composeMessage->rfc822_header->parseAddress($bounce_send_to, true); // ripped from src/compose.php (function deliverMessage() from 1.4.11SVN 2007/09/11 // (only change was the if and else conditions) // (also matches 1.5.2 90%) // if (!$useSendmail) { include_once(SM_PATH . 'class/deliver/Deliver_SMTP.class.php'); $deliver = new Deliver_SMTP(); global $smtpServerAddress, $smtpPort, $pop_before_smtp, $smtp_auth_mech; $authPop = (isset($pop_before_smtp) && $pop_before_smtp) ? true : false; $user = ''; $pass = ''; get_smtp_user($user, $pass); $stream = $deliver->initStream($composeMessage,$domain,0, $smtpServerAddress, $smtpPort, $user, $pass, $authPop); } else { include_once(SM_PATH . 'class/deliver/Deliver_SendMail.class.php'); global $sendmail_path, $sendmail_args; // Check for outdated configuration if (!isset($sendmail_args)) { if ($sendmail_path=='/var/qmail/bin/qmail-inject') { $sendmail_args = ''; } else { $sendmail_args = '-i -t'; } } $deliver = new Deliver_SendMail(array('sendmail_args'=>$sendmail_args)); $stream = $deliver->initStream($composeMessage,$sendmail_path); } if (!$stream) { global $color; sq_change_text_domain('spam_buttons'); $msg = _("Could not establish connection to outgoing mail server"); sq_change_text_domain('squirrelmail'); $ret = plain_error_message($msg, $color); if (check_sm_version (1, 5, 2)) { echo $ret; global $oTemplate; $oTemplate->display('footer.tpl'); } exit; } // first, build Resent-X headers and the needed BCC: to the bounce recipient // $new_headers = ''; $new_headers .= 'Resent-To: ' . $composeMessage->rfc822_header->getAddr_s('bcc', ",$rn ", true) . $rn; // build the new from header // // ripped from src/compose.php from 1.4.11SVN on 2007/09/11 // if (ereg("^([^@%/]+)[@%/](.+)$", $username, $usernamedata)) { $popuser = $usernamedata[1]; $domain = $usernamedata[2]; unset($usernamedata); } else { $popuser = $username; } $reply_to = ''; $from_mail = $idents[$identity]['email_address']; $full_name = $idents[$identity]['full_name']; $reply_to = $idents[$identity]['reply_to']; if (!$from_mail) { $from_mail = "$popuser@$domain"; } $composeMessage->rfc822_header->from = $composeMessage->rfc822_header->parseAddress($from_mail,true); if ($full_name) { $from = $composeMessage->rfc822_header->from[0]; if (!$from->host) $from->host = $domain; $full_name_encoded = encodeHeader($full_name); if ($full_name_encoded != $full_name) { $from_addr = $full_name_encoded .' <'.$from->mailbox.'@'.$from->host.'>'; } else { $from_addr = '"'.$full_name .'" <'.$from->mailbox.'@'.$from->host.'>'; } $composeMessage->rfc822_header->from = $composeMessage->rfc822_header->parseAddress($from_addr,true); } $new_headers .= 'Resent-From: ' . $composeMessage->rfc822_header->getAddr_s('from', ",$rn ", true) . $rn; // create a RFC 822 date // $date = date('D, j M Y H:i:s ', time()) . Deliver::timezone(); $new_headers .= 'Resent-Date: ' . $date . $rn; // create new message-id // // if server var SERVER_NAME is not available, use $domain // if (!sqGetGlobalVar('SERVER_NAME', $SERVER_NAME, SQ_SERVER)) $SERVER_NAME = $domain; if (!sqGetGlobalVar('REMOTE_PORT', $REMOTE_PORT, SQ_SERVER)) $REMOTE_PORT = 'unk'; if (!sqGetGlobalVar('REMOTE_ADDR', $REMOTE_ADDR, SQ_SERVER)) $REMOTE_ADDR = 'unk'; $message_id = '<' . $REMOTE_PORT . '.'; if (isset($encode_header_key) && trim($encode_header_key) != '') // use encrypted form of remote address $message_id .= OneTimePadEncrypt(Deliver::ip2hex($REMOTE_ADDR), base64_encode($encode_header_key)); else $message_id .= $REMOTE_ADDR; $message_id .= '.' . time() . '.squirrel.redirect@' . $SERVER_NAME .'>'; $new_headers .= 'Resent-Message-ID: ' . $message_id . $rn; // identify SquirrelMail as the user agent // $new_headers .= 'Resent-User-Agent: SquirrelMail/' . $version . $rn; // bcc to new recipient // $new_headers .= 'Bcc: ' . $composeMessage->rfc822_header->getAddr_s('bcc', ",$rn ", true) . $rn; // retrieve original message in raw format // $response = ''; $message = ''; if (empty($passed_ent_id)) $raw_message = sqimap_run_command($imapConnection, "FETCH $passed_id BODY.PEEK[]", true, $response, $message, $uid_support); else $raw_message = sqimap_run_command($imapConnection, "FETCH $passed_id BODY.PEEK[$passed_ent_id]", true, $response, $message, $uid_support); if ($response != 'OK') { global $color; sq_change_text_domain('spam_buttons'); $msg = sprintf(_("Could not find requested message: %s"), $message); sq_change_text_domain('squirrelmail'); $ret = plain_error_message($msg, $color); if (check_sm_version (1, 5, 2)) { echo $ret; global $oTemplate; $oTemplate->display('footer.tpl'); } exit; } // rebuild the message exactly as it comes from the IMAP server, with // Resent-X headers pre-pended (except first and last array entries // are command wrappers, so skip them) // array_shift($raw_message); array_pop($raw_message); $raw_message = $new_headers . implode('', $raw_message); $deliver->preWriteToStream($raw_message); $deliver->writeToStream($stream, $raw_message); $success = $deliver->finalizeStream($stream); if (!$success) { global $color; if (empty($deliver->dlv_msg)) $deliver->dlv_msg = ''; if (empty($deliver->dlv_server_msg)) $deliver->dlv_server_msg = ''; if (empty($deliver->dlv_ret_nr)) $deliver->dlv_ret_nr = ''; sq_change_text_domain('spam_buttons'); if (check_sm_version(1, 5, 2)) $msg = _("Could not send report: \n%1\n%2 %3"); else $msg = _("Could not send report:
%1
%2 %3
"); $msg = str_replace(array('%1', '%2', '%3'), array($deliver->dlv_msg, $deliver->dlv_ret_nr, $deliver->dlv_server_msg), $msg); sq_change_text_domain('squirrelmail'); $ret = plain_error_message($msg, $color); if (check_sm_version (1, 5, 2)) { echo $ret; global $oTemplate; $oTemplate->display('footer.tpl'); } exit; } else { unset($deliver); } spam_buttons/getpot0000744000000000000000000000072311203035526013517 0ustar rootroot#!/bin/sh XGETTEXT_OPTIONS="--keyword=_ -keyword=N_ --default-domain=spam_buttons --add-comments=i18n" # Allows controlling language option # (gettext v.0.10.40 = -C, gettext 0.11+ = -L php). if [ $SM_OLD_GETTEXT ] ; then XGETTEXT_OPTIONS="${XGETTEXT_OPTIONS} -C"; else XGETTEXT_OPTIONS="${XGETTEXT_OPTIONS} -L php"; fi xgettext ${XGETTEXT_OPTIONS} *.php --output=spam_buttons.pot xgettext ${XGETTEXT_OPTIONS} -j templates/default/*.tpl --output=spam_buttons.pot spam_buttons/contrib/0000755000000000000000000000000011203034263013724 5ustar rootrootspam_buttons/contrib/index.php0000644000000000000000000000074011203034263015545 0ustar rootrootspam_buttons/contrib/sa-wrapper.html0000644000000000000000000004006510675266745016730 0ustar rootroot publications:sa-wrapper [GTMP Foundation]

sa-wrapper.pl

#!/usr/bin/perl -w
# Time-stamp: <05 April 2004, 13:37 home>
#
# sa-wrapper.pl
#

# SpamAssassin sa-learn wrapper
# (c) Alexandre Jousset, 2004
# This script is GPL'd
#
# Thanks to: Chung-Kie Tung for the removal of the dir
#            Adam Gent for bug report
#
# v1.2
 

use strict;
use MIME::Tools;
use MIME::Parser;
 
my $DEBUG = 0;

my $UNPACK_DIR = '/var/spool/amavis/mime';
my $SA_LEARN = '/usr/bin/sa-learn';
my @DOMAINS = qw/example.com example.org/;

 
my ($spamham, $sender) = @ARGV;
 
sub recurs
{
    my $ent = shift;

 
    if ($ent->head->mime_type eq 'message/rfc822') {
        if ($DEBUG) {

            unlink "/tmp/spam.log.$$" if -e "/tmp/spam.log.$$";
            open(OUT, "|$SA_LEARN -D --$spamham --single >>/tmp/spam.log.$$ 2>&1") or die "Cannot pipe $SA_LEARN: $!";
        } else {

            open(OUT, "|$SA_LEARN --$spamham --single") or die "Cannot pipe $SA_LEARN: $!";
        }
 
        $ent->bodyhandle->print(\*OUT);

 
        close(OUT);
        return;
    }
 
    my @parts = $ent->parts;

 
    if (@parts) {
        map { recurs($_) } @parts;
    }

}
 
my ($domain) = $sender =~ /\@(.*)$/;
unless (grep { $_ eq $domain } @DOMAINS) {

    die "I don't recognize your domain !";
}
 
if ($DEBUG) {
    MIME::Tools->debugging(1);
    open(STDERR, ">/tmp/spam_err.log");

}
my $parser = new MIME::Parser;
$parser->extract_nested_messages(0);
$parser->output_under($UNPACK_DIR);

 
my $entity;
eval {
    $entity = $parser->parse(\*STDIN);

};
 
if ($@) {
    die $@;
} else {
    recurs($entity);

}
 
$parser->filer->purge;
rmdir $parser->output_dir;
 
publications/sa-wrapper.txt · Last modified: 18/09/2007 18:36 by mid
 
Recent changes RSS feed Creative Commons License Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki
spam_buttons/contrib/.htaccess0000644000000000000000000000001611203034257015522 0ustar rootrootDeny from All spam_buttons/contrib/sa-postfix-en.html0000644000000000000000000004025610675266455017344 0ustar rootroot publications:sa-postfix-en [GTMP Foundation]

SpamAssassin and Postfix

Note: This page has been resurrected from my old site (R.I.P.). As I still see hits in my logs from people looking at it, I managed to get its content and put it here.

SpamAssassin (SA) updates its bayesian filter with the command sa-learn. However, if one use a setup using for instance AMaViS to activate an antivirus and SA for all the mails going through the server, it can be useful to provide 2 mail aliases (eg spam@example.com and ham@example.com) to report false positives and false negatives that could have gone through SA. Theses aliases would allow, just by forwarding the offending mail, to transmit them to sa-learn.

To achieve this we will configure several parts of Postfix and use a wrapper script for sa-learn.

Beware: for this to work with the provided script, your forwarded message must be in the form of message/rfc822. Ths is possible for example with Thunderbird or Mozilla by choosing to forward messages as attachments in Options/Composition. A following version will accept Outlook forwarded messages. If you want to do this yourself, please tell me and I will include your patch. Thomas A. Luther tells me that if you compose a new message with Outlook, then drag and drop the spams/hams to it they will be sent as message/rfc822. So this can be a method.

Postfix configuration

/etc/postfix/aliases file

In this file, add the two first and optionally the third aliases like this:

spam:		spam@spam.spam
ham:		ham@ham.ham
notspam:	ham@ham.ham

You can now issue the command newaliases, it causes no harm. These aliases will redirect the mail towards the special domains that we will define later.

N.B. : The aliases spam and ham are examples. To avoid their spreading and thus being targetted by spammers, choose other aliases at your convenience.

/etc/postfix/main.cf file

Here we are going to define the transport file (if this is not already done) :

transport_maps = hash:/etc/postfix/transport

/etc/postfix/transport file

You must create this file with the following lines, or just add them is it already exists:

spam.spam	sa-spam:
ham.ham		sa-ham:

These lines define (fictitious) domains for which we will use a special transport defined in /etc/postfix/master.cf.

Don't forget to issue the command postmap /etc/postfix/transport.

/etc/postfix/master.cf file

Here we are going to setup the domain transports defined previously:

# Spam & Ham
sa-spam	unix	-	n	n	-	-	pipe user=amavis:amavis argv=/usr/local/bin/sa-wrapper.pl spam ${sender}
sa-ham	unix	-	n	n	-	-	pipe user=amavis:amavis argv=/usr/local/bin/sa-wrapper.pl ham  ${sender}

Replace the user=amavis:amavis parameter with the user:group that executes SA in your configuration.

Wrapper

The script is available here. Download it in /usr/local/bin and edit it to set variable $UNPACK_DIR on a directory that you create in the $HOME directory of the user that execute SA (for instance amavis) and the $SA_LEARN variable to the path of the sa-learn executable. the $DEBUG variable purpose is to verify the correct setup of this hack (see below). The @DOMAINS variable has been added to check the sender against predefined values to allow only some senders to use these aliases. Set it to the domains you want to allow. Don't forget to set the rights and / or owner of the script to allow executing by amavis user and / or group.

Note: The script use the MIME::Tools package that is either already available for your distribution (for instance perl-MIME-tools-5.411-6mdk for Mandrake 9.2 (wow, not really recent :-P)), or at CPAN.

Final setup

Issue a postfix reload.

To check the correct configuration, set the $DEBUG variable to 1 in the wrapper script and forward a spam to the address spam@example.com where example.com is your domain. Check any error in the logfiles and wait until a line like this:

Jan 10 05:12:49 moulin postfix/pipe[8288]: 72C167E0C: to=<spam@spam.spam>, orig_to=<spam@example.com>, relay=sa-spam, delay=15, status=sent (spam.spam)

appears in the mail logfile (or in /var/log/syslog). Then check the file(s) /tmp/spam.log.pid (where pid is the PID of the process) to see if the SA tokens match the text of the spam that you forwarded. Do this test again but with a normal mail that you forward to ham@example.com. Don't forget to set the $DEBUG variable back to 0 if everything seems OK. The $DEBUG variable also ask the script to output some MIME::Tools info to /tmp/spam_err.log.

In case of problem, suggestion or question, email me to mid@gtmp.org.

 
publications/sa-postfix-en.txt · Last modified: 20/09/2007 20:38 by mid
 
Recent changes RSS feed Creative Commons License Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki
spam_buttons/contrib/confirm_action.diff0000644000000000000000000001662211050150412017552 0ustar rootrootdiff -raudB ./buttons.php.orig ./buttons.php --- ./buttons.php.orig Mon Jan 21 22:18:18 2008 +++ ./buttons.php Mon Mar 3 14:01:29 2008 @@ -55,7 +55,7 @@ $sb_show_spam_button_folder_allow_override, $sb_show_not_spam_button_folder, $sb_show_not_spam_button_folder_allow_override, - $extra_buttons; + $extra_buttons, $confirm_spam_action, $confirm_ham_action; $passed_ent_id = 0; sqgetGlobalVar('passed_ent_id', $passed_ent_id, SQ_FORM); @@ -163,7 +163,26 @@ else if (check_sm_version(1, 5, 1)) $buttons[1]['isSpam'] = array(0 => _($spam_button_text), 1 => 'submit'); else - $ret .= '\n"; + if ( $confirm_spam_action ) + { + $ret .= '\n + \n"; + } + else + { + $ret .= '\n"; + } } @@ -194,7 +213,25 @@ else if (check_sm_version(1, 5, 1)) $buttons[1]['notSpam'] = array(0 => _($not_spam_button_text), 1 => 'submit'); else - $ret .= '\n"; + if ( $confirm_ham_action ) { + $ret .= '\n + \n"; + } + else + { + $ret .= '\n"; + } } @@ -247,7 +284,8 @@ $sb_show_spam_button_folder, $sb_show_spam_button_folder_allow_override, $sb_show_not_spam_button_folder, $extra_buttons, - $sb_show_not_spam_button_folder_allow_override; + $sb_show_not_spam_button_folder_allow_override, + $confirm_spam_action,$confirm_ham_action; spam_buttons_init(); @@ -348,39 +387,69 @@ && (in_array($mailbox, $sb_show_spam_button_folder) // 2Ba || (empty($sb_show_spam_button_folder) // 2Bb && !in_array($mailbox, $sb_suppress_spam_button_folder))))) - && !($sb_report_spam_by_move_to_folder && !empty($passed_ent_id))) // 3 - $spam_links[] = array('URL' => sqm_baseuri() - . 'src/read_body.php?isSpam=yslnk&mailbox=' - . urlencode($mailbox) . '&passed_id=' . $passed_id . '&view_as_html=' - . $view_as_html . '&startMessage=' . $startMessage . '&passed_ent_id=' - . $passed_ent_id . '&account=' . $account, - 'Text' => _($spam_button_text)); + && !($sb_report_spam_by_move_to_folder && !empty($passed_ent_id))) { // 3 + + if ( $confirm_spam_action ) { + $spam_links[] = array('URL' => sqm_baseuri() + . 'src/read_body.php?isSpam=yslnk&mailbox=' + . urlencode($mailbox) . '&passed_id=' . $passed_id . '&view_as_html=' + . $view_as_html . '&startMessage=' . $startMessage . '&passed_ent_id=' + . $passed_ent_id . '&account=' . $account .'" onclick="return confirm(\''. _("Are you sure?") .'\')', + 'Text' => _($spam_button_text)); + } + else + { + $spam_links[] = array('URL' => sqm_baseuri() + . 'src/read_body.php?isSpam=yslnk&mailbox=' + . urlencode($mailbox) . '&passed_id=' . $passed_id . '&view_as_html=' + . $view_as_html . '&startMessage=' . $startMessage . '&passed_ent_id=' + . $passed_ent_id . '&account=' . $account, + 'Text' => _($spam_button_text)); + } + + } + // 1) is button turned on in the first place? // 2) either A or B below: // A) if current message is tagged as ham, don't show ham button // B) if not using message tag settings, then: // a) if in (one of) the spam folder(s) ($sb_show_not_spam_button_folder // defines a list of spam folders to show the ham button in), // show ham button // b) otherwise, if not using the spam folder (list), then // if in (one of) the ham folder(s), don't show ham button // 3) can't show button if report method is move-to-folder and we're // looking at a message that is an attachment to another // if ($show_not_spam_button // 1 && (current_message_is_tagged(FALSE) === FALSE // 2A || (current_message_is_tagged(FALSE) === 0 // 2B && (in_array($mailbox, $sb_show_not_spam_button_folder) // 2Ba || (empty($sb_show_not_spam_button_folder) // 2Bb && !in_array($mailbox, $sb_suppress_not_spam_button_folder))))) && !($sb_report_not_spam_by_move_to_folder && !empty($passed_ent_id))) // 3 - $spam_links[] = array('URL' => sqm_baseuri() - . 'src/read_body.php?notSpam=yslnk&mailbox=' - . urlencode($mailbox) . '&passed_id=' . $passed_id . '&view_as_html=' - . $view_as_html . '&startMessage=' . $startMessage . '&passed_ent_id=' - . $passed_ent_id . '&account=' . $account, - 'Text' => _($not_spam_button_text)); + { + if ( $confirm_ham_action ) + { + $spam_links[] = array('URL' => sqm_baseuri() + . 'src/read_body.php?notSpam=yslnk&mailbox=' + . urlencode($mailbox) . '&passed_id=' . $passed_id . '&view_as_html=' + . $view_as_html . '&startMessage=' . $startMessage . '&passed_ent_id=' + . $passed_ent_id . '&account=' . $account .'" onclick="return confirm(\''. _("Are you sure?") .'\')', + 'Text' => _($not_spam_button_text)); + } + else + { + $spam_links[] = array('URL' => sqm_baseuri() + . 'src/read_body.php?notSpam=yslnk&mailbox=' + . urlencode($mailbox) . '&passed_id=' . $passed_id . '&view_as_html=' + . $view_as_html . '&startMessage=' . $startMessage . '&passed_ent_id=' + . $passed_ent_id . '&account=' . $account, + 'Text' => _($not_spam_button_text)); + + } + } if (check_sm_version(1, 5, 2)) $links = array_merge($links, $spam_links); diff -raudB ./config_example.php.orig ./config_example.php --- ./config_example.php.orig Mon Jan 7 02:24:31 2008 +++ ./config_example.php Tue Mar 4 09:54:08 2008 @@ -669,7 +669,8 @@ $is_spam_subject_prefix = 'SPAM'; $is_not_spam_subject_prefix = 'HAM'; - +$confirm_spam_action = 1; +$confirm_ham_action = 0; // You may also specify overrides for the SMTP server for the // email only (see SquirrelMail's main configuration file or diff -raudB ./spam_buttons.pot.orig ./spam_buttons.pot --- ./spam_buttons.pot.orig Wed Jan 23 16:25:29 2008 +++ ./spam_buttons.pot Tue Mar 4 09:49:19 2008 @@ -194,3 +194,6 @@ msgid "Senders have been whitelisted" msgstr "" + +msgid "Are you sure?" +msgstr "" spam_buttons/report.php0000644000000000000000000021130211201130304014276 0ustar rootroot, * Licensed under the GNU GPL. For full terms see the file COPYING. * * @package plugins * @subpackage spam_buttons * */ /** * Takes care of spam/ham button click * */ function sb_button_action_do($args) { include_once(SM_PATH . 'plugins/spam_buttons/functions.php'); global $is_spam_shell_command, $is_spam_resend_destination, $is_not_spam_shell_command, $is_not_spam_resend_destination, $is_spam_subject_prefix, $is_not_spam_subject_prefix, $sb_reselect_messages, $sb_delete_after_report, $sb_reselect_messages_allow_override, $username, $data_dir, $sb_delete_after_report_allow_override, $sb_move_after_report_spam, $sb_move_after_report_spam_allow_override, $sb_move_after_report_not_spam, $note, $sb_move_after_report_not_spam_allow_override, $sb_report_spam_by_move_to_folder, $sb_report_not_spam_by_move_to_folder, $sb_copy_after_report_spam_allow_override, $sb_copy_after_report_spam, $sb_copy_after_report_not_spam_allow_override, $sb_copy_after_report_not_spam, $sb_report_spam_by_copy_to_folder, $sb_report_not_spam_by_copy_to_folder, $reported_spam_text, $reported_not_spam_text, $sb_move_to_other_message_after_report, $location, $sb_move_to_other_message_after_report_allow_override, $abort_message_view, $extra_buttons, $is_spam_keep_copy_in_sent, $sb_report_spam_by_custom_function, $is_not_spam_keep_copy_in_sent, $sb_report_not_spam_by_custom_function; spam_buttons_init(); if ($sb_reselect_messages_allow_override) { $sb_reselect_messages = getPref($data_dir, $username, 'sb_reselect_messages', $sb_reselect_messages); } if ($sb_delete_after_report_allow_override) { $sb_delete_after_report = getPref($data_dir, $username, 'sb_delete_after_report', $sb_delete_after_report); } if ($sb_move_after_report_spam_allow_override) { $sb_move_after_report_spam = getPref($data_dir, $username, 'sb_move_after_report_spam', $sb_move_after_report_spam); } if ($sb_move_after_report_not_spam_allow_override) { $sb_move_after_report_not_spam = getPref($data_dir, $username, 'sb_move_after_report_not_spam', $sb_move_after_report_not_spam); } if ($sb_copy_after_report_spam_allow_override) { $sb_copy_after_report_spam = getPref($data_dir, $username, 'sb_copy_after_report_spam', $sb_copy_after_report_spam); } if ($sb_copy_after_report_not_spam_allow_override) { $sb_copy_after_report_not_spam = getPref($data_dir, $username, 'sb_copy_after_report_not_spam', $sb_copy_after_report_not_spam); } if ($sb_move_to_other_message_after_report_allow_override) { $sb_move_to_other_message_after_report = getPref($data_dir, $username, 'sb_move_to_other_message_after_report', $sb_move_to_other_message_after_report); } //sm_print_r($_GET, $_POST, $_SERVER); //sm_print_r($_SESSION); //exit; $passed_ent_id = 0; sqGetGlobalVar('passed_ent_id', $passed_ent_id, SQ_FORM); sqGetGlobalVar('REQUEST_METHOD', $method, SQ_SERVER); if (sqGetGlobalVar('location', $location, SQ_POST)) { /* $location = htmlspecialchars($location); */ } else $location = php_self(); if (sqGetGlobalVar('passed_id', $passed_id, SQ_FORM)) // fix for Dovecot UIDs can be bigger than normal integers $passed_id = (preg_match('/^[0-9]+$/', $passed_id) ? $passed_id : '0'); if (sqGetGlobalVar('msg', $msg, SQ_FORM)) // fix for Dovecot UIDs can be bigger than normal integers if (is_array($msg)) foreach ($msg as $i => $messageID) $msg[$i] = (preg_match('/^[0-9]+$/', $messageID) ? $messageID : '0'); else $msg = (preg_match('/^[0-9]+$/', $msg) ? $msg : '0'); // determine if the report was done from the message view screen // // the use of get_current_hook_name() means the Compatibility plugin is required // $hook_name = get_current_hook_name($args); $move_to_message_after_report = -1; if ($hook_name == 'read_body_header' || $hook_name == 'template_construct_read_headers.tpl') { $reporting_from_message_view = TRUE; // get previous/next message UIDs before we possibly move/delete the current one // if (strtolower($sb_move_to_other_message_after_report) == 'next') $move_to_message_after_report = spam_buttons_findNextMessage($passed_id); else if (strtolower($sb_move_to_other_message_after_report) == 'previous') $move_to_message_after_report = spam_buttons_findPreviousMessage($passed_id); } else { $reporting_from_message_view = FALSE; } // if in 1.4.x we need to print message // to user after report, do that here // if (!check_sm_version(1, 5, 0) && sqGetGlobalVar('sb_note', $sb_note, SQ_SESSION)) { echo html_tag('div', '' . $sb_note .'', 'center') . "
\n"; sqsession_unregister('sb_note'); } // pull button/link flags differently since during // POST submissions, the $_GET array sticks around // $isSpam = NULL; $notSpam = NULL; $extraButton = NULL; $callback = NULL; $custom_button_success_singular = ''; $custom_button_success_plural = ''; $button_name = NULL; if (strtoupper($method) == 'POST') { sqGetGlobalVar('isSpam', $isSpam, SQ_POST); sqGetGlobalVar('notSpam', $notSpam, SQ_POST); } else { sqGetGlobalVar('isSpam', $isSpam, SQ_GET); sqGetGlobalVar('notSpam', $notSpam, SQ_GET); } // detect if extra button was clicked // if (is_null($isSpam) && is_null($notSpam) && !empty($extra_buttons)) { foreach ($extra_buttons as $button => $button_info) { $button_name = preg_replace('/[^a-zA-Z0-9]/', '_', $button); if ((strtoupper($method) == 'POST' && sqGetGlobalVar($button_name, $extraButton, SQ_POST)) || (strtoupper($method) == 'GET' && sqGetGlobalVar($button_name, $extraButton, SQ_GET))) { if (!empty($button_info[3])) $callback = $button_info[3]; if (!empty($button_info[4])) $custom_button_success_singular = $button_info[4]; if (!empty($button_info[5])) $custom_button_success_plural = $button_info[5]; break; } } } // build message ID array if user came from one of the // links on the message view page // if ($isSpam == 'yslnk' || $notSpam == 'yslnk' || $extraButton == 'yslnk') $msg = array($passed_id); // build list of checkboxes to be pre-selected when // returning to message list // $prechecked = array(); if ($sb_reselect_messages) // could add the following, but not absolutely necessary // && (empty($sb_report_spam_by_move_to_folder) // || empty($sb_report_not_spam_by_move_to_folder))) { if (is_array($msg)) foreach ($msg as $messageID) $prechecked[$messageID] = TRUE; } // if no messages were selected or spam buttons were not clicked on // this request, just return and let SM handle the error, if any // if (empty($msg) || (empty($isSpam) && empty($notSpam) && empty($extraButton))) return; sq_change_text_domain('spam_buttons'); $note = ''; $success = FALSE; $abort_message_view = FALSE; //TODO: if we implement "dont_wait" functionality, we can fork a child process here; then the child uses the reporting code below and exits, but the parent needs to skip to the section a few hundred lines down where it redirects back to the message list or read-message page ("DONE, WHERE DO WE RETURN TO?"). See the TODO section of the README file for some issues regarding this kind of functioality // ----------------------------------------------------------------- // // HANDLE EXTRA BUTTON CLICK // if (!empty($extraButton)) { list($result, $note) = sb_custom_button_action($button_name, $callback, $msg, $passed_ent_id); // what note do we use? if we have success and there // is a note configured in the config file, use it // if ($result) { if (!empty($custom_button_success_singular) && !empty($custom_button_success_plural)) $note = ngettext($custom_button_success_singular, $custom_button_success_plural, count($msg)); else if (count($msg) < 2 && !empty($custom_button_success_singular)) $note = _($custom_button_success_singular); else if (count($msg) > 1 && !empty($custom_button_success_plural)) $note = _($custom_button_success_plural); else $note = _($note); } // this should never actually be needed, but to be safe, let's // make sure that none of the other action handlers below get // kicked off... // $isSpam = NULL; $notSpam = NULL; } // ----------------------------------------------------------------- // // SPAM // // mark as spam! // if (!empty($isSpam)) { // move-to-folder (only when target mailbox is not the same as source mailbox) // // note that we don't have to to check for $passed_ent_id because the report // links/buttons are not shown when $passed_ent_id is non-zero, so we can never // get here // global $mailbox; if (!empty($sb_report_spam_by_move_to_folder) && $mailbox != $sb_report_spam_by_move_to_folder && is_array($msg)) { global $auto_expunge, $imapConnection, $username, $key, $imapServerAddress, $imapPort; if (check_sm_version(1, 5, 2)) $key = FALSE; if (!is_resource($imapConnection)) $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0); if (check_sm_version(1, 5, 2)) { global $aMailbox; sqGetGlobalVar('lastTargetMailbox', $lastTargetMailbox, SQ_SESSION); spam_buttons_auto_create_folder($imapConnection, $sb_report_spam_by_move_to_folder); if ($sb_report_spam_by_copy_to_folder) $note = handleMessageListForm($imapConnection, $aMailbox, 'copy', $msg, $sb_report_spam_by_move_to_folder); else $note = handleMessageListForm($imapConnection, $aMailbox, 'move', $msg, $sb_report_spam_by_move_to_folder); sqsession_register($lastTargetMailbox,'lastTargetMailbox'); } else { //TODO -- how to populate $note if an error occurs? sqimap_msgs_list_copy() doesn't have a return value... if ($sb_report_spam_by_copy_to_folder) spam_buttons_sqimap_msgs_list_copy($imapConnection, $msg, $sb_report_spam_by_move_to_folder); else spam_buttons_sqimap_msgs_list_move($imapConnection, $msg, $sb_report_spam_by_move_to_folder); if ($auto_expunge) $cnt = sqimap_mailbox_expunge($imapConnection, $mailbox, true); else $cnt = 0; } // done reporting-by-move, now redirect user as needed // right away if javascript is available and reporting // from message view, or just prepare redirect location // otherwise // if (empty($note)) { $success = TRUE; $note = _($reported_spam_text); //TODO? include something that identifies the message(s) that were reported(have to add it up in the loop above)? might take too much screen real estate....? global $javascript_on, $username, $mbx_response, $mailbox, $startMessage, $show_num, $sort, $imapConnection, $key, $imapServerAddress, $imapPort, $account; $uri_args = 'mailbox=' . urlencode($mailbox) . (!empty($sort) ? "&sort=$sort" : '') . (!empty($account) ? "&account=$account" : '') . (!empty($startMessage) ? "&startMessage=$startMessage" : ''); if (check_sm_version(1, 5, 2)) $key = FALSE; if (empty($mbx_response)) { if (!is_resource($imapConnection)) $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0); $mbx_response = sqimap_mailbox_select($imapConnection, $mailbox); } // when reading message itself, redirect back to // message list after having moved it // if ($reporting_from_message_view && $javascript_on) { //TODO: this may cause problems in 1.4.x, where output is probably already started sqsession_register($note, 'sb_note'); // do we want to move to next message or return to message list? // global $redirect_location; if ($move_to_message_after_report < 0) $redirect_location = sqm_baseuri() . 'src/right_main.php?' . $uri_args; else $redirect_location = sqm_baseuri() . 'src/read_body.php?passed_id=' . $move_to_message_after_report . '&' . $uri_args; // when viewing a message in the preview pane, // need to clear pane (or go to next message) // after delete as well as refresh message list // global $data_dir, $PHP_SELF; if (is_plugin_enabled('preview_pane') && getPref($data_dir, $username, 'use_previewPane', 0) == 1) { global $request_refresh_message_list; $request_refresh_message_list = 1; // if not going to next message, go to empty preview pane // if ($move_to_message_after_report < 0) $redirect_location = sqm_baseuri() . 'plugins/preview_pane/empty_frame.php'; // refresh message list & close // if (check_sm_version(1, 5, 2)) { global $oTemplate; $oTemplate->assign('redirect_location', $redirect_location, FALSE); $oTemplate->assign('request_refresh_message_list', $request_refresh_message_list); $output = $oTemplate->fetch('plugins/spam_buttons/redirect_preview_pane.tpl'); return array('read_body_header' => $output); } else { global $t; $t = array(); // no need to put config vars herein, they are already globalized include(SM_PATH . 'plugins/spam_buttons/templates/default/redirect_preview_pane.tpl'); } } // otherwise, just redirect with javascript // else { if (check_sm_version(1, 5, 2)) { global $oTemplate; $oTemplate->assign('redirect_location', $redirect_location, FALSE); $output = $oTemplate->fetch('plugins/spam_buttons/redirect_standard.tpl'); return array('read_body_header' => $output); } else { global $t; $t = array(); // no need to put config vars herein, they are already globalized include(SM_PATH . 'plugins/spam_buttons/templates/default/redirect_standard.tpl'); } } } // otherwise (reporting from message list or no javascript support), // make sure we didn't move ourselves off the last page or anything // like that (code copied from 1.4.11 src/move_messages.php) // else if (!$reporting_from_message_view) { if (($startMessage + $cnt - 1) >= $mbx_response['EXISTS']) { if ($startMessage > $show_num) $location = set_url_var($location,'startMessage',$startMessage-$show_num, false); else $location = set_url_var($location,'startMessage',1, false); } } // finally, if we don't have JavaScript and we moved the message // out from under the message view, so we need to indicate that // the current message view needs to be aborted // else if ($reporting_from_message_view && !$javascript_on) { $abort_message_view = TRUE; } } } // shell command // else if (!empty($is_spam_shell_command)) { $note = report_by_shell_command($is_spam_shell_command, $msg, $passed_ent_id); if (empty($note)) { $success = TRUE; $note = _($reported_spam_text); //TODO? include something that identifies the message(s) that were reported(have to add it up in the loop above)? might take too much screen real estate....? } } // re-send elsewhere via email // else if (!empty($is_spam_resend_destination)) { $note = report_by_email($is_spam_resend_destination, $msg, $passed_ent_id, $is_spam_keep_copy_in_sent, $is_spam_subject_prefix); if (empty($note)) { $success = TRUE; $note = _($reported_spam_text); //TODO? include something that identifies the message(s) that were reported(have to add it up in the loop above)? might take too much screen real estate....? } } // custom function callout // else if (!empty($sb_report_spam_by_custom_function)) { $note = $sb_report_spam_by_custom_function($msg, $passed_ent_id); if (empty($note)) { $success = TRUE; $note = _($reported_spam_text); //TODO? include something that identifies the message(s) that were reported(have to add it up in the loop above)? might take too much screen real estate....? } } else //TODO: we could put a warning here for the sysadmin... (but note that it is possible to get here when report-by-move-to-folder is correctly configured but no messages were selected by the user before pressing the report button) $note = ''; } // ----------------------------------------------------------------- // // HAM // // mark as ham! // else if (!empty($notSpam)) { // move-to-folder (only when target mailbox is not the same as source mailbox) // // note that we don't have to to check for $passed_ent_id because the report // links/buttons are not shown when $passed_ent_id is non-zero, so we can never // get here // global $mailbox; if (!empty($sb_report_not_spam_by_move_to_folder) && $mailbox != $sb_report_not_spam_by_move_to_folder && is_array($msg)) { global $auto_expunge, $imapConnection, $username, $key, $imapServerAddress, $imapPort; if (check_sm_version(1, 5, 2)) $key = FALSE; if (!is_resource($imapConnection)) $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0); if (check_sm_version(1, 5, 2)) { global $aMailbox; sqGetGlobalVar('lastTargetMailbox', $lastTargetMailbox, SQ_SESSION); spam_buttons_auto_create_folder($imapConnection, $sb_report_not_spam_by_move_to_folder); if ($sb_report_not_spam_by_copy_to_folder) $note = handleMessageListForm($imapConnection, $aMailbox, 'copy', $msg, $sb_report_not_spam_by_move_to_folder); else $note = handleMessageListForm($imapConnection, $aMailbox, 'move', $msg, $sb_report_not_spam_by_move_to_folder); sqsession_register($lastTargetMailbox,'lastTargetMailbox'); } else { //TODO -- how to populate $note if an error occurs? sqimap_msgs_list_copy() doesn't have a return value... if ($sb_report_not_spam_by_copy_to_folder) spam_buttons_sqimap_msgs_list_copy($imapConnection, $msg, $sb_report_not_spam_by_move_to_folder); else spam_buttons_sqimap_msgs_list_move($imapConnection, $msg, $sb_report_not_spam_by_move_to_folder); if ($auto_expunge) $cnt = sqimap_mailbox_expunge($imapConnection, $mailbox, true); else $cnt = 0; } // done reporting-by-move, now redirect user as needed // right away if javascript is available and reporting // from message view, or just prepare redirect location // otherwise // if (empty($note)) { $success = TRUE; $note = _($reported_not_spam_text); //TODO? include something that identifies the message(s) that were reported(have to add it up in the loop above)? might take too much screen real estate....? global $javascript_on, $username, $mbx_response, $mailbox, $startMessage, $show_num, $sort, $imapConnection, $key, $imapServerAddress, $imapPort, $account; $uri_args = 'mailbox=' . urlencode($mailbox) . (!empty($sort) ? "&sort=$sort" : '') . (!empty($account) ? "&account=$account" : '') . (!empty($startMessage) ? "&startMessage=$startMessage" : ''); if (check_sm_version(1, 5, 2)) $key = FALSE; if (empty($mbx_response)) { if (!is_resource($imapConnection)) $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0); $mbx_response = sqimap_mailbox_select($imapConnection, $mailbox); } // when reading message itself, redirect back to // message list after having moved it // if ($reporting_from_message_view && $javascript_on) { //TODO: this may cause problems in 1.4.x, where output is probably already started sqsession_register($note, 'sb_note'); // do we want to move to next message or return to message list? // global $redirect_location; if ($move_to_message_after_report < 0) $redirect_location = sqm_baseuri() . 'src/right_main.php?' . $uri_args; else $redirect_location = sqm_baseuri() . 'src/read_body.php?passed_id=' . $move_to_message_after_report . '&' . $uri_args; // when viewing a message in the preview pane, // need to clear pane (or go to next message) // after delete as well as refresh message list // global $data_dir, $PHP_SELF; if (is_plugin_enabled('preview_pane') && getPref($data_dir, $username, 'use_previewPane', 0) == 1) { global $request_refresh_message_list; $request_refresh_message_list = 1; // if not going to next message, go to empty preview pane // if ($move_to_message_after_report < 0) $redirect_location = sqm_baseuri() . 'plugins/preview_pane/empty_frame.php'; // refresh message list & close // if (check_sm_version(1, 5, 2)) { global $oTemplate; $oTemplate->assign('redirect_location', $redirect_location, FALSE); $oTemplate->assign('request_refresh_message_list', $request_refresh_message_list); $output = $oTemplate->fetch('plugins/spam_buttons/redirect_preview_pane.tpl'); return array('read_body_header' => $output); } else { global $t; $t = array(); // no need to put config vars herein, they are already globalized include(SM_PATH . 'plugins/spam_buttons/templates/default/redirect_preview_pane.tpl'); } } // otherwise, just redirect with javascript // else { if (check_sm_version(1, 5, 2)) { global $oTemplate; $oTemplate->assign('redirect_location', $redirect_location, FALSE); $output = $oTemplate->fetch('plugins/spam_buttons/redirect_standard.tpl'); return array('read_body_header' => $output); } else { global $t; $t = array(); // no need to put config vars herein, they are already globalized include(SM_PATH . 'plugins/spam_buttons/templates/default/redirect_standard.tpl'); } } } // otherwise (reporting from message list or no javascript support), // make sure we didn't move ourselves off the last page or anything // like that (code copied from 1.4.11 src/move_messages.php) // else if (!$reporting_from_message_view) { if (($startMessage + $cnt - 1) >= $mbx_response['EXISTS']) { if ($startMessage > $show_num) $location = set_url_var($location,'startMessage',$startMessage-$show_num, false); else $location = set_url_var($location,'startMessage',1, false); } } // finally, if we don't have JavaScript and we moved the message // out from under the message view, so we need to indicate that // the current message view needs to be aborted // else if ($reporting_from_message_view && !$javascript_on) { $abort_message_view = TRUE; } } } // shell command // else if (!empty($is_not_spam_shell_command)) { $note = report_by_shell_command($is_not_spam_shell_command, $msg, $passed_ent_id); if (empty($note)) { $success = TRUE; $note = _($reported_not_spam_text); //TODO? include something that identifies the message(s) that were reported(have to add it up in the loop above)? might take too much screen real estate....? } } // re-send elsewhere via email // else if (!empty($is_not_spam_resend_destination)) { $note = report_by_email($is_not_spam_resend_destination, $msg, $passed_ent_id, $is_not_spam_keep_copy_in_sent, $is_not_spam_subject_prefix); if (empty($note)) { $success = TRUE; $note = _($reported_not_spam_text); //TODO? include something that identifies the message(s) that were reported(have to add it up in the loop above)? might take too much screen real estate....? } } // custom function callout // else if (!empty($sb_report_not_spam_by_custom_function)) { $note = $sb_report_not_spam_by_custom_function($msg, $passed_ent_id); if (empty($note)) { $success = TRUE; $note = _($reported_not_spam_text); //TODO? include something that identifies the message(s) that were reported(have to add it up in the loop above)? might take too much screen real estate....? } } else //TODO: we could put a warning here for the sysadmin... (but note that it is possible to get here when report-by-move-to-folder is correctly configured but no messages were selected by the user before pressing the report button) $note = ''; } sq_change_text_domain('squirrelmail'); // ----------------------------------------------------------------- // // REPORTED... NOW MOVE? // // move spam // if ($success && !empty($isSpam) && $sb_move_after_report_spam && (empty($sb_report_spam_by_move_to_folder) // not if already moved! || $sb_report_spam_by_copy_to_folder) && empty($passed_ent_id) // not if reporting an attachment! && is_array($msg)) { global $auto_expunge, $imapConnection, $username, $key, $show_num, $mbx_response, $imapServerAddress, $imapPort, $mailbox, $startMessage, $sort, $account, $javascript_on; $uri_args = 'mailbox=' . urlencode($mailbox) . (!empty($sort) ? "&sort=$sort" : '') . (!empty($account) ? "&account=$account" : '') . (!empty($startMessage) ? "&startMessage=$startMessage" : ''); if (check_sm_version(1, 5, 2)) $key = FALSE; if (!is_resource($imapConnection)) $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0); if (empty($mbx_response)) $mbx_response = sqimap_mailbox_select($imapConnection, $mailbox); // move messages only when target mailbox is not the same as source mailbox // if ($mailbox != $sb_move_after_report_spam) { if (check_sm_version(1, 5, 2)) { global $aMailbox; sqGetGlobalVar('lastTargetMailbox', $lastTargetMailbox, SQ_SESSION); spam_buttons_auto_create_folder($imapConnection, $sb_move_after_report_spam); if ($sb_copy_after_report_spam) $move_result = handleMessageListForm($imapConnection, $aMailbox, 'copy', $msg, $sb_move_after_report_spam); else $move_result = handleMessageListForm($imapConnection, $aMailbox, 'move', $msg, $sb_move_after_report_spam); sqsession_register($lastTargetMailbox,'lastTargetMailbox'); } else { if ($sb_copy_after_report_spam) spam_buttons_sqimap_msgs_list_copy($imapConnection, $msg, $sb_move_after_report_spam); else spam_buttons_sqimap_msgs_list_move($imapConnection, $msg, $sb_move_after_report_spam); if ($auto_expunge) $cnt = sqimap_mailbox_expunge($imapConnection, $mailbox, true); else $cnt = 0; } // when reading message itself, redirect back to // message list after having moved it // if ($reporting_from_message_view && $javascript_on) { //TODO: this may cause problems in 1.4.x, where output is probably already started sqsession_register($note, 'sb_note'); // do we want to move to next message or return to message list? // global $redirect_location; if ($move_to_message_after_report < 0) $redirect_location = sqm_baseuri() . 'src/right_main.php?' . $uri_args; else $redirect_location = sqm_baseuri() . 'src/read_body.php?passed_id=' . $move_to_message_after_report . '&' . $uri_args; // when viewing a message in the preview pane, // need to clear pane (or go to next message) // after delete as well as refresh message list // global $data_dir, $PHP_SELF; if (is_plugin_enabled('preview_pane') && getPref($data_dir, $username, 'use_previewPane', 0) == 1) { global $request_refresh_message_list; $request_refresh_message_list = 1; // if not going to next message, go to empty preview pane // if ($move_to_message_after_report < 0) $redirect_location = sqm_baseuri() . 'plugins/preview_pane/empty_frame.php'; // refresh message list & close // if (check_sm_version(1, 5, 2)) { global $oTemplate; $oTemplate->assign('redirect_location', $redirect_location, FALSE); $oTemplate->assign('request_refresh_message_list', $request_refresh_message_list); $output = $oTemplate->fetch('plugins/spam_buttons/redirect_preview_pane.tpl'); return array('read_body_header' => $output); } else { global $t; $t = array(); // no need to put config vars herein, they are already globalized include(SM_PATH . 'plugins/spam_buttons/templates/default/redirect_preview_pane.tpl'); } } // otherwise, just redirect with javascript // else { if (check_sm_version(1, 5, 2)) { global $oTemplate; $oTemplate->assign('redirect_location', $redirect_location, FALSE); $output = $oTemplate->fetch('plugins/spam_buttons/redirect_standard.tpl'); return array('read_body_header' => $output); } else { global $t; $t = array(); // no need to put config vars herein, they are already globalized include(SM_PATH . 'plugins/spam_buttons/templates/default/redirect_standard.tpl'); } } } // otherwise (reporting from message list or no javascript support), // make sure we didn't move ourselves off the last page or anything // like that (code copied from 1.4.11 src/move_messages.php) // else if (!$reporting_from_message_view) { if (($startMessage + $cnt - 1) >= $mbx_response['EXISTS']) { if ($startMessage > $show_num) $location = set_url_var($location,'startMessage',$startMessage-$show_num, false); else $location = set_url_var($location,'startMessage',1, false); } } // finally, if we don't have JavaScript and we moved the message // out from under the message view, so we need to indicate that // the current message view needs to be aborted // else if ($reporting_from_message_view && !$javascript_on) { $abort_message_view = TRUE; } } } // move ham // if ($success && !empty($notSpam) && $sb_move_after_report_not_spam && (empty($sb_report_not_spam_by_move_to_folder) // not if already moved! || $sb_report_not_spam_by_copy_to_folder) && empty($passed_ent_id) // not if reporting an attachment! && is_array($msg)) { global $auto_expunge, $imapConnection, $username, $key, $show_num, $mbx_response, $imapServerAddress, $imapPort, $mailbox, $startMessage, $sort, $account, $javascript_on; $uri_args = 'mailbox=' . urlencode($mailbox) . (!empty($sort) ? "&sort=$sort" : '') . (!empty($account) ? "&account=$account" : '') . (!empty($startMessage) ? "&startMessage=$startMessage" : ''); if (check_sm_version(1, 5, 2)) $key = FALSE; if (!is_resource($imapConnection)) $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0); if (empty($mbx_response)) $mbx_response = sqimap_mailbox_select($imapConnection, $mailbox); // move messages only when target mailbox is not the same as source mailbox // if ($mailbox != $sb_move_after_report_not_spam) { if (check_sm_version(1, 5, 2)) { global $aMailbox; sqGetGlobalVar('lastTargetMailbox', $lastTargetMailbox, SQ_SESSION); spam_buttons_auto_create_folder($imapConnection, $sb_move_after_report_not_spam); if ($sb_copy_after_report_not_spam) $move_result = handleMessageListForm($imapConnection, $aMailbox, 'copy', $msg, $sb_move_after_report_not_spam); else $move_result = handleMessageListForm($imapConnection, $aMailbox, 'move', $msg, $sb_move_after_report_not_spam); sqsession_register($lastTargetMailbox,'lastTargetMailbox'); } else { if ($sb_copy_after_report_not_spam) spam_buttons_sqimap_msgs_list_copy($imapConnection, $msg, $sb_move_after_report_not_spam); else spam_buttons_sqimap_msgs_list_move($imapConnection, $msg, $sb_move_after_report_not_spam); if ($auto_expunge) $cnt = sqimap_mailbox_expunge($imapConnection, $mailbox, true); else $cnt = 0; } // when reading message itself, redirect back to // message list after having moved it // if ($reporting_from_message_view && $javascript_on) { //TODO: this may cause problems in 1.4.x, where output is probably already started sqsession_register($note, 'sb_note'); // do we want to move to next message or return to message list? // global $redirect_location; if ($move_to_message_after_report < 0) $redirect_location = sqm_baseuri() . 'src/right_main.php?' . $uri_args; else $redirect_location = sqm_baseuri() . 'src/read_body.php?passed_id=' . $move_to_message_after_report . '&' . $uri_args; // when viewing a message in the preview pane, // need to clear pane (or go to next message) // after delete as well as refresh message list // global $data_dir, $PHP_SELF; if (is_plugin_enabled('preview_pane') && getPref($data_dir, $username, 'use_previewPane', 0) == 1) { global $request_refresh_message_list; $request_refresh_message_list = 1; // if not going to next message, go to empty preview pane // if ($move_to_message_after_report < 0) $redirect_location = sqm_baseuri() . 'plugins/preview_pane/empty_frame.php'; // refresh message list & close // if (check_sm_version(1, 5, 2)) { global $oTemplate; $oTemplate->assign('redirect_location', $redirect_location, FALSE); $oTemplate->assign('request_refresh_message_list', $request_refresh_message_list); $output = $oTemplate->fetch('plugins/spam_buttons/redirect_preview_pane.tpl'); return array('read_body_header' => $output); } else { global $t; $t = array(); // no need to put config vars herein, they are already globalized include(SM_PATH . 'plugins/spam_buttons/templates/default/redirect_preview_pane.tpl'); } } // otherwise, just redirect with javascript // else { if (check_sm_version(1, 5, 2)) { global $oTemplate; $oTemplate->assign('redirect_location', $redirect_location, FALSE); $output = $oTemplate->fetch('plugins/spam_buttons/redirect_standard.tpl'); return array('read_body_header' => $output); } else { global $t; $t = array(); // no need to put config vars herein, they are already globalized include(SM_PATH . 'plugins/spam_buttons/templates/default/redirect_standard.tpl'); } } } // otherwise (reporting from message list or no javascript support), // make sure we didn't move ourselves off the last page or anything // like that (code copied from 1.4.11 src/move_messages.php) // else if (!$reporting_from_message_view) { if (($startMessage + $cnt - 1) >= $mbx_response['EXISTS']) { if ($startMessage > $show_num) $location = set_url_var($location,'startMessage',$startMessage-$show_num, false); else $location = set_url_var($location,'startMessage',1, false); } } // finally, if we don't have JavaScript and we moved the message // out from under the message view, so we need to indicate that // the current message view needs to be aborted // else if ($reporting_from_message_view && !$javascript_on) { $abort_message_view = TRUE; } } } // ----------------------------------------------------------------- // // OR DELETE? // // delete spam if needed (but not if already moved) // if ($success && $sb_delete_after_report && !empty($isSpam) && !$sb_move_after_report_spam // not if already moved! && empty($passed_ent_id) // not if reporting an attachment! && empty($sb_report_spam_by_move_to_folder)) // not if already moved! { if (is_array($msg)) { global $auto_expunge, $imapConnection, $username, $key, $show_num, $mbx_response, $imapServerAddress, $imapPort, $mailbox, $startMessage, $sort, $account, $javascript_on; $uri_args = 'mailbox=' . urlencode($mailbox) . (!empty($sort) ? "&sort=$sort" : '') . (!empty($account) ? "&account=$account" : '') . (!empty($startMessage) ? "&startMessage=$startMessage" : ''); if (check_sm_version(1, 5, 2)) $key = FALSE; //LEFT OFF HERE -- debugging UW //sm_print_r('$imapConnection contains:', $imapConnection); //sqimap_logout($imapConnection); if (!is_resource($imapConnection)) $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0); //echo '$mbx_response now contains:
'; //sm_print_r($mbx_response); if (empty($mbx_response)) //{ $mbx_response = sqimap_mailbox_select($imapConnection, $mailbox); //echo 'And now $mbx_response contains:
'; //sm_print_r($mbx_response); //} if (check_sm_version(1, 5, 2)) { global $aMailbox; handleMessageListForm($imapConnection, $aMailbox, 'setDeleted', $msg); } else { sqimap_msgs_list_delete($imapConnection, $mailbox, $msg); //echo "Finished deleting; now expunge if necessary...
"; if ($auto_expunge) { //echo "Expunging...
"; $cnt = sqimap_mailbox_expunge($imapConnection, $mailbox, true); } //echo "Finished
"; //exit; } // when reading message itself, redirect back to // message list after deletion // if ($reporting_from_message_view && $javascript_on) { //TODO: this may cause problems in 1.4.x, where output is probably already started sqsession_register($note, 'sb_note'); // do we want to move to next message or return to message list? // global $redirect_location; if ($move_to_message_after_report < 0) $redirect_location = sqm_baseuri() . 'src/right_main.php?' . $uri_args; else $redirect_location = sqm_baseuri() . 'src/read_body.php?passed_id=' . $move_to_message_after_report . '&' . $uri_args; // when viewing a message in the preview pane, // need to clear pane (or go to next message) // after delete as well as refresh message list // global $data_dir, $PHP_SELF; if (is_plugin_enabled('preview_pane') && getPref($data_dir, $username, 'use_previewPane', 0) == 1) { global $request_refresh_message_list; $request_refresh_message_list = 1; // if not going to next message, go to empty preview pane // if ($move_to_message_after_report < 0) $redirect_location = sqm_baseuri() . 'plugins/preview_pane/empty_frame.php'; // refresh message list & close // if (check_sm_version(1, 5, 2)) { global $oTemplate; $oTemplate->assign('redirect_location', $redirect_location, FALSE); $oTemplate->assign('request_refresh_message_list', $request_refresh_message_list); $output = $oTemplate->fetch('plugins/spam_buttons/redirect_preview_pane.tpl'); return array('read_body_header' => $output); } else { global $t; $t = array(); // no need to put config vars herein, they are already globalized include(SM_PATH . 'plugins/spam_buttons/templates/default/redirect_preview_pane.tpl'); } } // otherwise, just redirect with javascript // else { if (check_sm_version(1, 5, 2)) { global $oTemplate; $oTemplate->assign('redirect_location', $redirect_location, FALSE); $output = $oTemplate->fetch('plugins/spam_buttons/redirect_standard.tpl'); return array('read_body_header' => $output); } else { global $t; $t = array(); // no need to put config vars herein, they are already globalized include(SM_PATH . 'plugins/spam_buttons/templates/default/redirect_standard.tpl'); } } } // otherwise (reporting from message list or no javascript support), // make sure we didn't move ourselves off the last page or anything // like that (code copied from 1.4.11 src/move_messages.php) // else if (!$reporting_from_message_view) { if (($startMessage + $cnt - 1) >= $mbx_response['EXISTS']) { if ($startMessage > $show_num) $location = set_url_var($location,'startMessage',$startMessage-$show_num, false); else $location = set_url_var($location,'startMessage',1, false); } } // finally, if we don't have JavaScript and we moved the message // out from under the message view, so we need to indicate that // the current message view needs to be aborted // else if ($reporting_from_message_view && !$javascript_on) { $abort_message_view = TRUE; } } } // ----------------------------------------------------------------- // // DONE, WHERE DO WE RETURN TO? // // if no note, then we shouldn't do anything at all // if (empty($note)) { if (check_sm_version(1, 5, 0)) return; else { header('Location: ' . $location); exit; } } // when reading message itself, print message // in header and continue (unless message has been deleted) // if ($reporting_from_message_view) { if (check_sm_version(1, 5, 2)) global $br; else $br = '
'; if ($abort_message_view) $note .= $br . _("The reported message is no longer available in this folder"); if (check_sm_version(1, 5, 2)) { global $oTemplate; $oTemplate->assign('note', $note, FALSE); // FALSE because of use of $br $output = $oTemplate->fetch('plugins/spam_buttons/confirmation_note.tpl'); return array('read_body_header' => $output); // note that message view will be aborted in next executed // template hook: template_construct_read_message_body.tpl // using the global $abort_message_view variable } else { echo html_tag('tr', html_tag('td', "$note", 'center', '', ' colspan="2"')); // if we need to abort, do that now // if ($abort_message_view) { echo ''; exit; } return; } } // // behavior is different when button on message list was clicked // // SM 1.5.2+: $note will be displayed automatically, so // all we need to do is return // if (check_sm_version(1, 5, 2)) { global $preselected; $preselected = array_keys($prechecked); return; } // SM 1.5: just display note and let go // else if (check_sm_version(1, 5, 0)) { global $preselected; $preselected = array_keys($prechecked); echo html_tag('div', '' . $note .'', 'center') . "
\n"; return; } // For SM 1.4.x, redirect to message list so SM // doesn't try to do something else funny (1.4.x // assumes it has to delete messages... yikes) // else { // put note in session so we can display it when back in // message list, without putting $note in the location, since // it is hard to remove from there, even on subsequent requests // sqsession_register($note, 'sb_note'); // compress prechecked array and pass it along // $query = ''; foreach ($prechecked as $msgid => $ignore) $query .= '&preselected[' . $msgid . ']=1'; if (strpos($location, '?') === FALSE) $query{0} = '?'; //header('Location: ' . $location . $query . '¬e=' . urlencode($note)); header('Location: ' . $location . $query); exit; } } /** * Reports one or more spam/non-spam using email redirection. * * @param string $destination The email address to which the * message should be redirected. * @param array $msg An array of message IDs to be reported. * @param string $passed_ent_id The message entity being reported * (zero if the message itself is being * reported (only applicable when there * is just one element in the $msg array)) * @param boolean $keep_copy_in_sent When sending as an attachment, * should a copy of the spam report * being sent out get stored in the * user's sent folder? * @param string $subjectPrefix Any extra subject info for * redirected mail's subject. * (optional; default is empty * string, nothing is done to subject) * * @return string An error message if an error occurred, * empty string otherwise * */ function report_by_email($destination, $msg, $passed_ent_id, $keep_copy_in_sent, $subjectPrefix='') { global $spam_report_email_method, $spam_report_smtpServerAddress, $spam_report_smtpPort, $spam_report_useSendmail, $spam_report_smtp_auth_mech, $spam_report_use_smtp_tls, $smtpServerAddress, $smtpPort, $useSendmail, $smtp_auth_mech, $use_smtp_tls, $sb_debug, $data_dir, $username, $domain; $at_sign = '@'; spam_buttons_init(); // do replacements on destination // if (strpos($username, $at_sign) !== FALSE) list($user, $dom) = explode($at_sign, $username); else { $user = $username; $dom = $domain; } $email_address = getPref($data_dir, $username, 'email_address'); $destination = str_replace(array('###EMAIL_PREF###', '###EMAIL_ADDRESS###', '###USERNAME###', '###DOMAIN###'), array($email_address, $user . $at_sign . $dom, $user, $dom), $destination); // take care of overrides for SMTP server // if (!empty($spam_report_smtpServerAddress)) $smtpServerAddress = $spam_report_smtpServerAddress; if (!empty($spam_report_smtpPort)) $smtpPort = $spam_report_smtpPort; if ($spam_report_useSendmail !== '') if (strtolower($spam_report_useSendmail) === 'false') $useSendmail = FALSE; else $useSendmail = $spam_report_useSendmail; if (!empty($spam_report_smtp_auth_mech)) $smtp_auth_mech = $spam_report_smtp_auth_mech; if (!empty($spam_report_use_smtp_tls)) $use_smtp_tls = $spam_report_use_smtp_tls; $note = ''; // redirect by bouncing message and preserving headers // if ($spam_report_email_method == 'bounce') { global $imapServerAddress, $imapPort, $useSendmail; // we will be manually manipulating $_GET, so... // global $_GET; if (!check_php_version(4,1)) { global $HTTP_GET_VARS; $_GET = $HTTP_GET_VARS; } if (is_array($msg)) foreach ($msg as $messageID) { $_GET['bounce_send_to'] = $destination; $_GET['passed_id'] = $messageID; $_GET['passed_ent_id'] = $passed_ent_id; require(SM_PATH . 'plugins/spam_buttons/bounce_send.php'); } } // redirect by including message as an attachment // else { // some versions of SM need this when using some compose functions // if (!function_exists('addressbook_init')) include_once(SM_PATH . 'functions/addressbook.php'); sqGetGlobalVar('mailbox', $mailbox); if (check_sm_version(1, 5, 2)) include_once(SM_PATH . 'plugins/spam_buttons/compose_functions-1.5.2.php'); else if (check_sm_version(1, 4, 14)) include_once(SM_PATH . 'plugins/spam_buttons/compose_functions-1.4.14.php'); else if (check_sm_version(1, 4, 11)) include_once(SM_PATH . 'plugins/spam_buttons/compose_functions-1.4.11.php'); else include_once(SM_PATH . 'plugins/spam_buttons/compose_functions-1.4.10.php'); if (is_array($msg)) foreach ($msg as $messageID) { global $composeMessage, $send_to, $subject, $sb_keep_copy_in_sent; $sb_keep_copy_in_sent = $keep_copy_in_sent; $composeMessage = new Message(); $rfc822_header = new Rfc822Header(); $composeMessage->rfc822_header = $rfc822_header; $composeMessage->reply_rfc822_header = ''; $message = newMail($mailbox, $messageID, $passed_ent_id, 'forward_as_attachment', ''); $subject = $message['subject']; if (!empty($subjectPrefix)) $subject = preg_replace('/fwd/i', $subjectPrefix, $subject); $send_to = $destination; $Result = deliverMessage($composeMessage); if (! $Result) { sq_change_text_domain('spam_buttons'); $note = _("ERROR: Report could not be delivered"); sq_change_text_domain('squirrelmail'); break; } // dump stuff out if debugging // if ($sb_debug) { echo '
EMAIL ADDRESS USED TO REPORT: ' . $destination . '

'; echo '
MESSAGE BODY AS REPORTED: (note that this is a parsed representation thereof)'; sm_print_r($composeMessage); echo '

'; exit; } } } return $note; } /** * Reports one or more spam/non-spam using the shell * command provided. * * @param string $command The shell command to be used. * @param array $msg An array of message IDs to be reported. * @param string $passed_ent_id The message entity being reported * (zero if the message itself is being * reported (only applicable when there * is just one element in the $msg array)) * * @return string An error message if an error occurred, * empty string otherwise * */ function report_by_shell_command($command, $msg, $passed_ent_id) { global $attachment_dir, $data_dir, $username, $domain, $sb_debug; $at_sign = '@'; spam_buttons_init(); $passed_ent_id = 0; sqGetGlobalVar('passed_ent_id', $passed_ent_id, SQ_FORM); sqGetGlobalVar('mailbox', $mailbox); // do replacements on command // if (strpos($username, $at_sign) !== FALSE) list($user, $dom) = explode($at_sign, $username); else { $user = $username; $dom = $domain; } $email_address = getPref($data_dir, $username, 'email_address'); $command = str_replace(array('###EMAIL_PREF###', '###EMAIL_ADDRESS###', '###USERNAME###', '###DOMAIN###'), array($email_address, $user . $at_sign . $dom, $user, $dom), $command); $note = ''; $timestamp = time(); if (is_array($msg)) foreach ($msg as $messageID) { // get message body, correctly formatted // global $uid_support, $imapConnection, $username, $key, $mbx_response, $imapServerAddress, $imapPort, $mailbox; if (check_sm_version(1, 5, 2)) { $key = FALSE; $uid_support = TRUE; } if (!is_resource($imapConnection)) $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0); if (empty($mbx_response)) $mbx_response = sqimap_mailbox_select($imapConnection, $mailbox); $response = ''; $message = ''; if (empty($passed_ent_id)) $raw_message = sqimap_run_command($imapConnection, "FETCH $messageID BODY.PEEK[]", true, $response, $message, $uid_support); else $raw_message = sqimap_run_command($imapConnection, "FETCH $messageID BODY.PEEK[$passed_ent_id]", true, $response, $message, $uid_support); if ($response != 'OK') { global $color; sq_change_text_domain('spam_buttons'); $msg = sprintf(_("Could not find requested message: %s"), $message); sq_change_text_domain('squirrelmail'); $ret = plain_error_message($msg, $color); if (check_sm_version (1, 5, 2)) { echo $ret; global $oTemplate; $oTemplate->display('footer.tpl'); } exit; } // rebuild the message exactly as it comes from the IMAP server // (except first and last array entries are command wrappers, so skip them) // array_shift($raw_message); array_pop($raw_message); $raw_message = implode('', $raw_message); // store message in attachments directory in temp file // $tempFile = $attachment_dir . '/sb_tmp_' . $messageID . '_' . $timestamp; $tempFileOK = FALSE; if ($FILE = @fopen($tempFile, 'w')) { fwrite($FILE, $raw_message); fclose($FILE); $tempFileOK = TRUE; // run command // $cmd = $command . ' < ' . $tempFile; //sm_print_r($cmd, $raw_message);exit; $lastLineOfOutput = exec($cmd, $allOutput, $retValue); //sm_print_r($allOutput);exit; // remove temp file // unlink($tempFile); // dump stuff out if debugging // if ($sb_debug) { echo '
COMMAND USED TO REPORT: ' . $cmd . '

'; echo '
MESSAGE BODY AS REPORTED: '; sm_print_r($raw_message); echo '

'; echo '
RESULTS FROM REPORT: (' . $retValue . ')'; sm_print_r($allOutput); echo '

'; exit; } } // couldn't open temp file // if (!$tempFileOK) { $note = _("ERROR: Could not open temp file; check attachments directory permissions"); break; } // oops, command failed // else if ($retValue !== 0) { if (empty($passed_ent_id)) $note = str_replace(array('%1', '%2', '%3'), array($retValue, $messageID, $lastLineOfOutput), _("ERROR %1: Problem reporting message ID %2: %3")); else $note = str_replace(array('%1', '%2', '%3', '%4'), array($retValue, $messageID, $lastLineOfOutput, $passed_ent_id), _("ERROR %1: Problem reporting message ID %2 (entity %4): %3")); break; } } return $note; } /** * Abort message view when message is moved/deleted * out from under current message view (SM 1.5.2+ only) * */ function sb_abort_message_view_do() { global $abort_message_view; if ($abort_message_view) { global $oTemplate; $oTemplate->display('footer.tpl'); exit; } } // // ripped from functions/auth.php (merged both STABLE and DEVEL; // the only difference being how the hook is handled) // /** * Fillin user and password based on SMTP auth settings. * * @param string $user Reference to SMTP username * @param string $pass Reference to SMTP password (unencrypted) */ if (!function_exists('get_smtp_user')) { function get_smtp_user(&$user, &$pass) { global $username, $smtp_auth_mech, $smtp_sitewide_user, $smtp_sitewide_pass; if ($smtp_auth_mech == 'none') { $user = ''; $pass = ''; } elseif ( isset($smtp_sitewide_user) && isset($smtp_sitewide_pass) && !empty($smtp_sitewide_user)) { $user = $smtp_sitewide_user; $pass = $smtp_sitewide_pass; } else { $user = $username; $pass = sqauth_read_password(); } if (check_sm_version(1, 5, 2)) { $temp = array(&$user, &$pass); do_hook('smtp_auth', $temp); } else { $ret = do_hook_function('smtp_auth', array($user, $pass)); if (!empty($ret[0])) $user = $ret[0]; if (!empty($ret[1])) $pass = $ret[1]; } } } // findPreviousMessage()'s prototype changed as of 1.5.1 // function spam_buttons_findPreviousMessage($passed_id) { if (check_sm_version(1, 5, 1)) { if (!sqGetGlobalVar('what', $what, SQ_GET)) $what = 0; global $aMailbox; return findPreviousMessage($aMailbox['UIDSET'][$what], $passed_id); } else { global $mbx_response; if (empty($mbx_response)) { global $imapConnection, $mailbox, $key, $username, $imapServerAddress, $imapPort; if (!is_resource($imapConnection)) $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0); $mbx_response = sqimap_mailbox_select($imapConnection, $mailbox); } return findPreviousMessage($mbx_response['EXISTS'], $passed_id); } } // findNextMessage()'s prototype changed as of 1.5.1 // function spam_buttons_findNextMessage($passed_id) { if (check_sm_version(1, 5, 1)) { if (!sqGetGlobalVar('what', $what, SQ_GET)) $what = 0; global $aMailbox; return findNextMessage($aMailbox['UIDSET'][$what], $passed_id); } else return findNextMessage($passed_id); } // The move and copy function names change as of 1.4.18 to be what // they say they are, so use those if we are at the right version. // // For versions less than 1.4.18, there is no copy function, so we // use a modified version of the move function from 1.4.11 (which, // ironically is mis-labelled "copy") // // Also, if configured to do so, the target folder will be created // first if it does not exist. // function spam_buttons_sqimap_msgs_list_copy($imap_stream, $id, $mailbox) { spam_buttons_auto_create_folder($imap_stream, $mailbox); if (check_sm_version(1, 4, 18)) return sqimap_msgs_list_copy($imap_stream, $id, $mailbox); // here is our own modified version of 1.4.11's move ("copy") function... // global $uid_support; $msgs_id = sqimap_message_list_squisher($id); $read = sqimap_run_command ($imap_stream, "COPY $msgs_id \"$mailbox\"", true, $response, $message, $uid_support); if ($response == 'OK') return true; else return false; } // the move and copy function names change as of 1.4.18 to be what they say they are // // Also, if configured to do so, the target folder will be created // first if it does not exist. // function spam_buttons_sqimap_msgs_list_move($imap_stream, $id, $mailbox) { spam_buttons_auto_create_folder($imap_stream, $mailbox); if (check_sm_version(1, 4, 18)) return sqimap_msgs_list_move($imap_stream, $id, $mailbox); // mis-labelled function name in versions less than 1.4.18 // return sqimap_msgs_list_copy($imap_stream, $id, $mailbox); } // create a folder if it does not exist if necessary // function spam_buttons_auto_create_folder($imap_stream, $mailbox) { // auto-create non-existing folder? // global $sb_auto_create_destination_folder; // assume config file already globally included if ($sb_auto_create_destination_folder && !sqimap_mailbox_exists($imap_stream, $mailbox)) sqimap_mailbox_create($imap_stream, $mailbox, ''); } /** * Execute action for custom button click. * * @param string $button_name The name of the button or link * (with non-alphanumerics having * been replaced with underscores). * @param string $callback The name of the function that * will handle the button action. * @param array $messages A list of message IDs. * @param string $passed_ent_id Entity ID when message is an * attachment (might be empty). * * @return array A two-element array, the first element being * a boolean value that is TRUE if all message(s) * were processed normally and FALSE if some error * occured. The second element is a string containing * a note (untranslated) that will be displayed to * the user upon completion (may be blank, in which * case, any message from the user configuration will * be used if available). * */ function sb_custom_button_action($button_name, $callback, $messages, $passed_ent_id) { global $username; $result = array(FALSE, 'ERROR: Unknown error'); // first, make sure the callback is correctly configured // if (empty($callback) || !function_exists($callback)) { global $color; // if users complain of seeing a message "Function not found in // Spam Buttons plugin", it means they don't have a action callback // defined at all // sq_change_text_domain('spam_buttons'); $msg = sprintf(_("Function %s not found in Spam Buttons plugin"), $callback); sq_change_text_domain('squirrelmail'); $ret = plain_error_message($msg, $color); if (check_sm_version (1, 5, 2)) { echo $ret; global $oTemplate; $oTemplate->display('footer.tpl'); } exit; } // loop through each message (even if there is just one) // foreach ($messages as $message_id) { // this retrieves the message's From header in the format // array(0 => 'From:', 1 => '"Jose" ') // $from = sb_get_message_header($message_id, $passed_ent_id, 'From'); // this parses out just the email address portion of the From header // if (function_exists('parseRFC822Address')) { $from = parseRFC822Address($from[1], 1); $from = $from[0][2] . '@' . $from[0][3]; } else { $from = parseAddress($from[1], 1); $from = $from[0][0]; } // execute the callback // $result = $callback($button_name, $username, $from, $message_id, $passed_ent_id); if (!is_array($result)) $result = array($result, ''); if (!$result[0]) return array(FALSE, 'ERROR: ' . $result[1]); } // finished, just return success (which will be the last known // value of $result... any note therein will also be used) // return $result; } spam_buttons/compose_functions-1.4.14.php0000644000000000000000000006646311127347173017310 0ustar rootroot, * Licensed under the GNU GPL. For full terms see the file COPYING. * * @package plugins * @subpackage spam_buttons * */ // // ripped from src/compose.php // /* This function is used when not sending or adding attachments */ function newMail ($mailbox='', $passed_id='', $passed_ent_id='', $action='', $session='') { global $editor_size, $default_use_priority, $body, $idents, $use_signature, $composesession, $data_dir, $username, $username, $key, $imapServerAddress, $imapPort, $composeMessage, $body_quote; global $languages, $squirrelmail_language, $default_charset; /* * Set $default_charset to correspond with the user's selection * of language interface. $default_charset global is not correct, * if message is composed in new window. */ set_my_charset(); $send_to = $send_to_cc = $send_to_bcc = $subject = $identity = ''; $mailprio = 3; if ($passed_id) { $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0); sqimap_mailbox_select($imapConnection, $mailbox); $message = sqimap_get_message($imapConnection, $passed_id, $mailbox); $body = ''; if ($passed_ent_id) { /* redefine the messsage in case of message/rfc822 */ $message = $message->getEntity($passed_ent_id); /* message is an entity which contains the envelope and type0=message * and type1=rfc822. The actual entities are childs from * $message->entities[0]. That's where the encoding and is located */ $entities = $message->entities[0]->findDisplayEntity (array(), $alt_order = array('text/plain')); if (!count($entities)) { $entities = $message->entities[0]->findDisplayEntity (array(), $alt_order = array('text/plain','text/html')); } $orig_header = $message->rfc822_header; /* here is the envelope located */ /* redefine the message for picking up the attachments */ $message = $message->entities[0]; } else { $entities = $message->findDisplayEntity (array(), $alt_order = array('text/plain')); if (!count($entities)) { $entities = $message->findDisplayEntity (array(), $alt_order = array('text/plain','text/html')); } $orig_header = $message->rfc822_header; } $encoding = $message->header->encoding; $type0 = $message->type0; $type1 = $message->type1; foreach ($entities as $ent) { $unencoded_bodypart = mime_fetch_body($imapConnection, $passed_id, $ent); $body_part_entity = $message->getEntity($ent); $bodypart = decodeBody($unencoded_bodypart, $body_part_entity->header->encoding); if ($type1 == 'html') { $bodypart = str_replace("\n", ' ', $bodypart); $bodypart = preg_replace(array('/

/i','//i'), "\n", $bodypart); $bodypart = str_replace(array(' ','>','<'),array(' ','>','<'),$bodypart); $bodypart = strip_tags($bodypart); } if (isset($languages[$squirrelmail_language]['XTRA_CODE']) && function_exists($languages[$squirrelmail_language]['XTRA_CODE'])) { if (mb_detect_encoding($bodypart) != 'ASCII') { $bodypart = $languages[$squirrelmail_language]['XTRA_CODE']('decode', $bodypart); } } // charset encoding in compose form stuff if (isset($body_part_entity->header->parameters['charset'])) { $actual = $body_part_entity->header->parameters['charset']; } else { $actual = 'us-ascii'; } if ( $actual && is_conversion_safe($actual) && $actual != $default_charset){ $bodypart = charset_convert($actual,$bodypart,$default_charset,false); } // end of charset encoding in compose $body .= $bodypart; } if ($default_use_priority) { $mailprio = substr($orig_header->priority,0,1); if (!$mailprio) { $mailprio = 3; } } else { $mailprio = ''; } $identity = ''; $from_o = $orig_header->from; if (is_array($from_o)) { if (isset($from_o[0])) { $from_o = $from_o[0]; } } if (is_object($from_o)) { $orig_from = $from_o->getAddress(); } else { $orig_from = ''; } $identities = array(); if (count($idents) > 1) { foreach($idents as $nr=>$data) { $enc_from_name = '"'.$data['full_name'].'" <'. $data['email_address'].'>'; if(strtolower($enc_from_name) == strtolower($orig_from)) { $identity = $nr; break; } $identities[] = $enc_from_name; } $identity_match = $orig_header->findAddress($identities); if ($identity_match) { $identity = $identity_match; } } switch ($action) { case ('draft'): $use_signature = FALSE; $composeMessage->rfc822_header = $orig_header; $send_to = decodeHeader($orig_header->getAddr_s('to'),false,false,true); $send_to_cc = decodeHeader($orig_header->getAddr_s('cc'),false,false,true); $send_to_bcc = decodeHeader($orig_header->getAddr_s('bcc'),false,false,true); // FIXME: ident support? $subject = decodeHeader($orig_header->subject,false,false,true); /* remember the references and in-reply-to headers in case of an reply */ $composeMessage->rfc822_header->more_headers['References'] = $orig_header->references; $composeMessage->rfc822_header->more_headers['In-Reply-To'] = $orig_header->in_reply_to; $body_ary = explode("\n", $body); $cnt = count($body_ary) ; $body = ''; for ($i=0; $i < $cnt; $i++) { if (!ereg("^[>\\s]*$", $body_ary[$i]) || !$body_ary[$i]) { sqWordWrap($body_ary[$i], $editor_size, $default_charset ); $body .= $body_ary[$i] . "\n"; } unset($body_ary[$i]); } sqUnWordWrap($body); $composeMessage = getAttachments($message, $composeMessage, $passed_id, $entities, $imapConnection); break; case ('edit_as_new'): $send_to = decodeHeader($orig_header->getAddr_s('to'),false,false,true); $send_to_cc = decodeHeader($orig_header->getAddr_s('cc'),false,false,true); $send_to_bcc = decodeHeader($orig_header->getAddr_s('bcc'),false,false,true); $subject = decodeHeader($orig_header->subject,false,false,true); $mailprio = $orig_header->priority; $orig_from = ''; $composeMessage = getAttachments($message, $composeMessage, $passed_id, $entities, $imapConnection); sqUnWordWrap($body); break; case ('forward'): $send_to = ''; $subject = decodeHeader($orig_header->subject,false,false,true); if ((substr(strtolower($subject), 0, 4) != 'fwd:') && (substr(strtolower($subject), 0, 5) != '[fwd:') && (substr(strtolower($subject), 0, 6) != '[ fwd:')) { $subject = '[Fwd: ' . $subject . ']'; } $body = getforwardHeader($orig_header) . $body; $composeMessage = getAttachments($message, $composeMessage, $passed_id, $entities, $imapConnection); $body = "\n" . $body; break; case ('forward_as_attachment'): $composeMessage = getMessage_RFC822_Attachment($message, $composeMessage, $passed_id, $passed_ent_id, $imapConnection); $body = ''; /// CHANGE FOR SPAM_BUTTONS PLUGIN (added next 6 lines) $subject = decodeHeader($orig_header->subject,false,false,true); if ((substr(strtolower($subject), 0, 4) != 'fwd:') && (substr(strtolower($subject), 0, 5) != '[fwd:') && (substr(strtolower($subject), 0, 6) != '[ fwd:')) { $subject = '[Fwd: ' . $subject . ']'; } break; case ('reply_all'): if(isset($orig_header->mail_followup_to) && $orig_header->mail_followup_to) { $send_to = $orig_header->getAddr_s('mail_followup_to'); } else { $send_to_cc = replyAllString($orig_header); $send_to_cc = decodeHeader($send_to_cc,false,false,true); } case ('reply'): if (!$send_to) { $send_to = $orig_header->reply_to; if (is_array($send_to) && count($send_to)) { $send_to = $orig_header->getAddr_s('reply_to'); } else if (is_object($send_to)) { /* unneccesarry, just for failsafe purpose */ $send_to = $orig_header->getAddr_s('reply_to'); } else { $send_to = $orig_header->getAddr_s('from'); } } $send_to = decodeHeader($send_to,false,false,true); $subject = decodeHeader($orig_header->subject,false,false,true); $subject = trim($subject); if (substr(strtolower($subject), 0, 3) != 're:') { $subject = 'Re: ' . $subject; } /* this corrects some wrapping/quoting problems on replies */ $rewrap_body = explode("\n", $body); $from = (is_array($orig_header->from) && !empty($orig_header->from)) ? $orig_header->from[0] : $orig_header->from; sqUnWordWrap($body); $body = ''; $cnt = count($rewrap_body); for ($i=0;$i<$cnt;$i++) { sqWordWrap($rewrap_body[$i], $editor_size, $default_charset); if (preg_match("/^(>+)/", $rewrap_body[$i], $matches)) { $gt = $matches[1]; $body .= $body_quote . str_replace("\n", "\n" . $body_quote . "$gt ", rtrim($rewrap_body[$i])) ."\n"; } else { $body .= $body_quote . (!empty($body_quote) ? ' ' : '') . str_replace("\n", "\n" . $body_quote . (!empty($body_quote) ? ' ' : ''), rtrim($rewrap_body[$i])) . "\n"; } unset($rewrap_body[$i]); } $body = getReplyCitation($from , $orig_header->date) . $body; $composeMessage->reply_rfc822_header = $orig_header; break; default: break; } /// CHANGE FOR SPAM_BUTTONS PLUGIN -- comment out next two lines /// session_write_close(); /// sqimap_logout($imapConnection); } $ret = array( 'send_to' => $send_to, 'send_to_cc' => $send_to_cc, 'send_to_bcc' => $send_to_bcc, 'subject' => $subject, 'mailprio' => $mailprio, 'body' => $body, 'identity' => $identity ); return ($ret); } /* function newMail() */ function getforwardHeader($orig_header) { global $editor_size; $display = array( _("Subject") => strlen(_("Subject")), _("From") => strlen(_("From")), _("Date") => strlen(_("Date")), _("To") => strlen(_("To")), _("Cc") => strlen(_("Cc")) ); $maxsize = max($display); $indent = str_pad('',$maxsize+2); foreach($display as $key => $val) { $display[$key] = $key .': '. str_pad('', $maxsize - $val); } $from = decodeHeader($orig_header->getAddr_s('from',"\n$indent"),false,false,true); $from = str_replace(' ',' ',$from); $to = decodeHeader($orig_header->getAddr_s('to',"\n$indent"),false,false,true); $to = str_replace(' ',' ',$to); $subject = decodeHeader($orig_header->subject,false,false,true); $subject = str_replace(' ',' ',$subject); $bodyTop = str_pad(' '._("Original Message").' ',$editor_size -2,'-',STR_PAD_BOTH) . "\n". $display[_("Subject")] . $subject . "\n" . $display[_("From")] . $from . "\n" . $display[_("Date")] . getLongDateString( $orig_header->date, $orig_header->date_unparsed ). "\n" . $display[_("To")] . $to . "\n"; if ($orig_header->cc != array() && $orig_header->cc !='') { $cc = decodeHeader($orig_header->getAddr_s('cc',"\n$indent"),false,false,true); $cc = str_replace(' ',' ',$cc); $bodyTop .= $display[_("Cc")] .$cc . "\n"; } $bodyTop .= str_pad('', $editor_size -2 , '-') . "\n\n"; return $bodyTop; } function getMessage_RFC822_Attachment($message, $composeMessage, $passed_id, $passed_ent_id='', $imapConnection) { global $attachment_dir, $username, $data_dir, $uid_support; $hashed_attachment_dir = getHashedDir($username, $attachment_dir); if (!$passed_ent_id) { $body_a = sqimap_run_command($imapConnection, 'FETCH '.$passed_id.' BODY.PEEK[]', TRUE, $response, $readmessage, $uid_support); } else { $body_a = sqimap_run_command($imapConnection, 'FETCH '.$passed_id.' BODY.PEEK['.$passed_ent_id.']', TRUE, $response, $readmessage, $uid_support); $message = $message->parent; } if ($response == 'OK') { $subject = encodeHeader($message->rfc822_header->subject); array_shift($body_a); array_pop($body_a); $body = implode('', $body_a) . "\r\n"; $localfilename = GenerateRandomString(32, 'FILE', 7); $full_localfilename = "$hashed_attachment_dir/$localfilename"; $fp = fopen($full_localfilename, 'w'); fwrite ($fp, $body); fclose($fp); $composeMessage->initAttachment('message/rfc822',$subject.'.msg', $localfilename); } return $composeMessage; } /** * temporary function to make use of the deliver class. * In the future the responsible backend should be automaticly loaded * and conf.pl should show a list of available backends. * The message also should be constructed by the message class. * * @param object $composeMessage The message being sent. Please note * that it is passed by reference and * will be returned modified, with additional * headers, such as Message-ID, Date, In-Reply-To, * References, and so forth. * * @return boolean FALSE if delivery failed, or some non-FALSE value * upon success. * */ function deliverMessage(&$composeMessage, $draft=false) { global $send_to, $send_to_cc, $send_to_bcc, $mailprio, $subject, $body, $username, $popuser, $usernamedata, $identity, $idents, $data_dir, $request_mdn, $request_dr, $default_charset, $color, $useSendmail, $domain, $action, $default_move_to_sent, $move_to_sent; global $imapServerAddress, $imapPort, $sent_folder, $key; /// CHANGE FOR SPAM_BUTTONS PLUGIN /* --- do we need to do overrides again here? should not need to, but // someone reported problems with the default not being overriden // when using this reporting method --- global $spam_report_email_method, $spam_report_smtpServerAddress, $spam_report_smtpPort, $spam_report_useSendmail, $spam_report_smtp_auth_mech, $spam_report_use_smtp_tls, $smtpServerAddress, $smtpPort, $useSendmail, $smtp_auth_mech, $use_smtp_tls, $sb_debug; spam_buttons_init(); // take care of overrides for SMTP server // if (!empty($spam_report_smtpServerAddress)) $smtpServerAddress = $spam_report_smtpServerAddress; if (!empty($spam_report_smtpPort)) $smtpPort = $spam_report_smtpPort; if ($spam_report_useSendmail !== '') $useSendmail = $spam_report_useSendmail; if (!empty($spam_report_smtp_auth_mech)) $smtp_auth_mech = $spam_report_smtp_auth_mech; if (!empty($spam_report_use_smtp_tls)) $use_smtp_tls = $spam_report_use_smtp_tls; --- */ $rfc822_header = $composeMessage->rfc822_header; $abook = addressbook_init(false, true); $rfc822_header->to = $rfc822_header->parseAddress($send_to,true, array(), '', $domain, array(&$abook,'lookup')); $rfc822_header->cc = $rfc822_header->parseAddress($send_to_cc,true,array(), '',$domain, array(&$abook,'lookup')); $rfc822_header->bcc = $rfc822_header->parseAddress($send_to_bcc,true, array(), '',$domain, array(&$abook,'lookup')); $rfc822_header->priority = $mailprio; $rfc822_header->subject = $subject; $special_encoding=''; if (strtolower($default_charset) == 'iso-2022-jp') { if (mb_detect_encoding($body) == 'ASCII') { $special_encoding = '8bit'; } else { $body = mb_convert_encoding($body, 'JIS'); $special_encoding = '7bit'; } } $composeMessage->setBody($body); if (ereg("^([^@%/]+)[@%/](.+)$", $username, $usernamedata)) { $popuser = $usernamedata[1]; $domain = $usernamedata[2]; unset($usernamedata); } else { $popuser = $username; } $reply_to = ''; $from_mail = $idents[$identity]['email_address']; $full_name = $idents[$identity]['full_name']; $reply_to = $idents[$identity]['reply_to']; if (!$from_mail) { $from_mail = "$popuser@$domain"; } $rfc822_header->from = $rfc822_header->parseAddress($from_mail,true); if ($full_name) { $from = $rfc822_header->from[0]; if (!$from->host) $from->host = $domain; $full_name_encoded = encodeHeader($full_name); if ($full_name_encoded != $full_name) { $from_addr = $full_name_encoded .' <'.$from->mailbox.'@'.$from->host.'>'; } else { $from_addr = '"'.$full_name .'" <'.$from->mailbox.'@'.$from->host.'>'; } $rfc822_header->from = $rfc822_header->parseAddress($from_addr,true); } if ($reply_to) { $rfc822_header->reply_to = $rfc822_header->parseAddress($reply_to,true); } /* Receipt: On Read */ if (isset($request_mdn) && $request_mdn) { $rfc822_header->dnt = $rfc822_header->parseAddress($from_mail,true); } /* Receipt: On Delivery */ if (isset($request_dr) && $request_dr) { $rfc822_header->more_headers['Return-Receipt-To'] = $from_mail; } /* multipart messages */ if (count($composeMessage->entities)) { $message_body = new Message(); $message_body->body_part = $composeMessage->body_part; $composeMessage->body_part = ''; $mime_header = new MessageHeader; $mime_header->type0 = 'text'; $mime_header->type1 = 'plain'; if ($special_encoding) { $mime_header->encoding = $special_encoding; } else { $mime_header->encoding = '8bit'; } if ($default_charset) { $mime_header->parameters['charset'] = $default_charset; } $message_body->mime_header = $mime_header; array_unshift($composeMessage->entities, $message_body); $content_type = new ContentType('multipart/mixed'); } else { $content_type = new ContentType('text/plain'); if ($special_encoding) { $rfc822_header->encoding = $special_encoding; } else { $rfc822_header->encoding = '8bit'; } if ($default_charset) { $content_type->properties['charset']=$default_charset; } } $rfc822_header->content_type = $content_type; $composeMessage->rfc822_header = $rfc822_header; if ($action == 'reply' || $action == 'reply_all') { global $passed_id, $passed_ent_id; $reply_id = $passed_id; $reply_ent_id = $passed_ent_id; } else { $reply_id = ''; $reply_ent_id = ''; } /* Here you can modify the message structure just before we hand it over to deliver */ /// CHANGE FOR SPAM_BUTTONS PLUGIN - comment out next 5 lines /// $hookReturn = do_hook('compose_send', $composeMessage); /// /* Get any changes made by plugins to $composeMessage. */ /// if ( is_object($hookReturn[1]) ) { /// $composeMessage = $hookReturn[1]; /// } if (!$useSendmail && !$draft) { require_once(SM_PATH . 'class/deliver/Deliver_SMTP.class.php'); $deliver = new Deliver_SMTP(); global $smtpServerAddress, $smtpPort, $pop_before_smtp; $authPop = (isset($pop_before_smtp) && $pop_before_smtp) ? true : false; $user = ''; $pass = ''; get_smtp_user($user, $pass); $stream = $deliver->initStream($composeMessage,$domain,0, $smtpServerAddress, $smtpPort, $user, $pass, $authPop); } elseif (!$draft) { require_once(SM_PATH . 'class/deliver/Deliver_SendMail.class.php'); global $sendmail_path, $sendmail_args; // Check for outdated configuration if (!isset($sendmail_args)) { if ($sendmail_path=='/var/qmail/bin/qmail-inject') { $sendmail_args = ''; } else { $sendmail_args = '-i -t'; } } $deliver = new Deliver_SendMail(array('sendmail_args'=>$sendmail_args)); $stream = $deliver->initStream($composeMessage,$sendmail_path); } elseif ($draft) { global $draft_folder; $imap_stream = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0); if (sqimap_mailbox_exists ($imap_stream, $draft_folder)) { require_once(SM_PATH . 'class/deliver/Deliver_IMAP.class.php'); $imap_deliver = new Deliver_IMAP(); $succes = $imap_deliver->mail($composeMessage, $imap_stream, $reply_id, $reply_ent_id, $imap_stream, $draft_folder); sqimap_logout($imap_stream); unset ($imap_deliver); $composeMessage->purgeAttachments(); return $succes; } else { $msg = '
'.sprintf(_("Error: Draft folder %s does not exist."), htmlspecialchars($draft_folder)); plain_error_message($msg, $color); return false; } } $succes = false; if ($stream) { $deliver->mail($composeMessage, $stream, $reply_id, $reply_ent_id); $succes = $deliver->finalizeStream($stream); } if (!$succes) { $msg = _("Message not sent.") .' '. _("Server replied:") . "\n

\n" . $deliver->dlv_msg . '
' . $deliver->dlv_ret_nr . ' ' . $deliver->dlv_server_msg . "
\n\n"; plain_error_message($msg, $color); } else { unset ($deliver); $imap_stream = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0); // mark original message as having been replied to if applicable global $passed_id, $mailbox, $action; if ($action == 'reply' || $action == 'reply_all') { sqimap_mailbox_select ($imap_stream, $mailbox); sqimap_messages_flag ($imap_stream, $passed_id, $passed_id, 'Answered', false); } // copy message to sent folder /// CHANGE FOR SPAM_BUTTONS PLUGIN (added next 2 lines) global $sb_keep_copy_in_sent; if ($sb_keep_copy_in_sent) { $move_to_sent = getPref($data_dir,$username,'move_to_sent'); if (isset($default_move_to_sent) && ($default_move_to_sent != 0)) { $svr_allow_sent = true; } else { $svr_allow_sent = false; } if (isset($sent_folder) && (($sent_folder != '') || ($sent_folder != 'none')) && sqimap_mailbox_exists( $imap_stream, $sent_folder)) { $fld_sent = true; } else { $fld_sent = false; } if ((isset($move_to_sent) && ($move_to_sent != 0)) || (!isset($move_to_sent))) { $lcl_allow_sent = true; } else { $lcl_allow_sent = false; } if (($fld_sent && $svr_allow_sent && !$lcl_allow_sent) || ($fld_sent && $lcl_allow_sent)) { require_once(SM_PATH . 'class/deliver/Deliver_IMAP.class.php'); $imap_deliver = new Deliver_IMAP(); $imap_deliver->mail($composeMessage, $imap_stream, $reply_id, $reply_ent_id, $imap_stream, $sent_folder); unset ($imap_deliver); } /// CHANGE FOR SPAM_BUTTONS PLUGIN (added next line) } $composeMessage->purgeAttachments(); sqimap_logout($imap_stream); } return $succes; } if (!function_exists('is_conversion_safe')) { /** * Function informs if it is safe to convert given charset to the one that is used by user. * * It is safe to use conversion only if user uses utf-8 encoding and when * converted charset is similar to the one that is used by user. * * @param string $input_charset Charset of text that needs to be converted * @return bool is it possible to convert to user's charset */ function is_conversion_safe($input_charset) { global $languages, $sm_notAlias, $default_charset, $lossy_encoding; if (isset($lossy_encoding) && $lossy_encoding ) return true; // convert to lower case $input_charset = strtolower($input_charset); // Is user's locale Unicode based ? if ( $default_charset == "utf-8" ) { return true; } // Charsets that are similar switch ($default_charset) { case "windows-1251": if ( $input_charset == "iso-8859-5" || $input_charset == "koi8-r" || $input_charset == "koi8-u" ) { return true; } else { return false; } case "windows-1257": if ( $input_charset == "iso-8859-13" || $input_charset == "iso-8859-4" ) { return true; } else { return false; } case "iso-8859-4": if ( $input_charset == "iso-8859-13" || $input_charset == "windows-1257" ) { return true; } else { return false; } case "iso-8859-5": if ( $input_charset == "windows-1251" || $input_charset == "koi8-r" || $input_charset == "koi8-u" ) { return true; } else { return false; } case "iso-8859-13": if ( $input_charset == "iso-8859-4" || $input_charset == "windows-1257" ) { return true; } else { return false; } case "koi8-r": if ( $input_charset == "windows-1251" || $input_charset == "iso-8859-5" || $input_charset == "koi8-u" ) { return true; } else { return false; } case "koi8-u": if ( $input_charset == "windows-1251" || $input_charset == "iso-8859-5" || $input_charset == "koi8-r" ) { return true; } else { return false; } default: return false; } } } spam_buttons/configtest.php0000644000000000000000000001603111127347241015153 0ustar rootroot, * Licensed under the GNU GPL. For full terms see the file COPYING. * * @package plugins * @subpackage spam_buttons * */ /** * Validate that this plugin is configured correctly * * @return boolean Whether or not there was a * configuration error for this plugin. * */ function spam_buttons_check_configuration_do() { include_once(SM_PATH . 'plugins/spam_buttons/functions.php'); global $is_spam_resend_destination, $is_not_spam_resend_destination, $is_spam_shell_command, $is_not_spam_shell_command, $show_not_spam_button, $show_is_spam_button, $sb_report_spam_by_move_to_folder, $sb_report_not_spam_by_move_to_folder, $sb_report_spam_by_custom_function, $sb_report_not_spam_by_custom_function; // make sure compatibility plugin is there at all (have to do this // because the spam_buttons_init() function uses load_config() // if (!function_exists('check_file_contents')) { do_err('Spam Buttons plugin requires the Compatibility plugin version 2.0.12+', FALSE); return TRUE; } // make sure base config is available // if (!spam_buttons_init()) { do_err('Spam Buttons plugin is missing its main configuration file', FALSE); return TRUE; } // check that the needed patch is in place for SM versions < 1.4.11 // if (!check_sm_version(1, 4, 11)) { if (!check_file_contents(SM_PATH . 'functions/mailbox_display.php', 'do_hook\(\'mailbox_display_buttons\'\);')) { do_err('Spam Buttons plugin requires a patch with your version of SquirrelMail, but it has not been applied', FALSE); return TRUE; } } $spam_methods = 0; if (!empty($sb_report_spam_by_move_to_folder)) $spam_methods++; if (!empty($is_spam_shell_command)) $spam_methods++; if (!empty($is_spam_resend_destination)) $spam_methods++; if (!empty($sb_report_spam_by_custom_function)) $spam_methods++; $ham_methods = 0; if (!empty($sb_report_not_spam_by_move_to_folder)) $ham_methods++; if (!empty($is_not_spam_shell_command)) $ham_methods++; if (!empty($is_not_spam_resend_destination)) $ham_methods++; if (!empty($sb_report_not_spam_by_custom_function)) $ham_methods++; // make sure "Is Spam" reporting method is properly configured // if ($show_is_spam_button && $spam_methods == 0) { do_err('Spam Buttons plugin is configured to show the "Is Spam" button, but there is no reporting method configured. Please specify either $sb_report_spam_by_move_to_folder, $is_spam_shell_command, $is_spam_resend_destination or $sb_report_spam_by_custom_function', FALSE); return TRUE; } // make sure "Is Not Spam" reporting method is properly configured // if ($show_not_spam_button && $ham_methods == 0) { do_err('Spam Buttons plugin is configured to show the "Is Not Spam" button, but there is no reporting method configured. Please specify either $sb_report_not_spam_by_move_to_folder, $is_not_spam_shell_command, $is_not_spam_resend_destination or $sb_report_not_spam_by_custom_function', FALSE); return TRUE; } //TODO: the statement below does not seem to be correct...?? /* we now allow more than one reporting type --- // make sure "Is Spam" reporting method is not "overly" configured // if ($show_is_spam_button && $spam_methods > 1) { do_err('Spam Buttons plugin is configured to show the "Is Spam" button, but more than one reporting method has been specified. Please choose $sb_report_spam_by_move_to_folder, $is_spam_shell_command, $is_spam_resend_destination or $sb_report_spam_by_custom_function, but not more than one', FALSE); return TRUE; } // make sure "Is Not Spam" reporting method is not "overly" configured // if ($show_not_spam_button && $ham_methods > 1) { do_err('Spam Buttons plugin is configured to show the "Is Not Spam" button, but more than one reporting method has been specified. Please choose $sb_report_not_spam_by_move_to_folder, $is_not_spam_shell_command, $is_not_spam_resend_destination or $sb_report_not_spam_by_custom_function, but not more than one', FALSE); return TRUE; } //TODO: the statement below does not seem to be correct...?? --- we now allow more than one reporting type */ //TODO: I think we could also verify similar things as below for any extra buttons too? // check that custom reporting functions have been implemented // if (!empty($sb_report_spam_by_custom_function) && !function_exists($sb_report_spam_by_custom_function)) { do_err('Spam Buttons plugin is configured to report spam by the use of a custom PHP function, but that function was not found. Please check $sb_report_spam_by_custom_function and that it points to a valid PHP function that is defined or loaded in the Spam Buttons configuration file', FALSE); return TRUE; } if (!empty($sb_report_not_spam_by_custom_function) && !function_exists($sb_report_not_spam_by_custom_function)) { do_err('Spam Buttons plugin is configured to report ham (non-spam) by the use of a custom PHP function, but that function was not found. Please check $sb_report_not_spam_by_custom_function and that it points to a valid PHP function that is defined or loaded in the Spam Buttons configuration file', FALSE); return TRUE; } // only need to do this pre-1.5.2, as 1.5.2 will make this // check for us automatically // if (!check_sm_version(1, 5, 2)) { // try to find Compatibility, and then that it is v2.0.12+ // if (function_exists('check_plugin_version') && check_plugin_version('compatibility', 2, 0, 12, TRUE)) { /* no-op */ } // something went wrong // else { do_err('Spam Buttons plugin requires the Compatibility plugin version 2.0.12+', FALSE); return TRUE; } } // check for exec being disabled // $disable_functions = explode(',', ini_get('disable_functions')); if (in_array('exec', $disable_functions) && (!empty($is_spam_shell_command) || !empty($is_not_spam_shell_command))) { do_err('You have disabled the "exec" command in your PHP configuration and are using the report-by-shell-command method for the Spam Buttons plugin. Spam and/or Ham reports will not work until you fix one or the other.', FALSE); return TRUE; } // check for problems when in safe_mode // if (ini_get('safe_mode') && (!empty($is_spam_shell_command) || !empty($is_not_spam_shell_command))) { $safe_mode_exec_dir = ini_get('safe_mode_exec_dir'); do_err('You have safe_mode enabled in your PHP configuration and are using the report-by-shell-command method for the Spam Buttons plugin. Please double check that your reporting command is in an allowable directory and has ownership that allows access by the web server. (Your safe_mode_exec_dir is "' . $safe_mode_exec_dir . '".)', FALSE); return FALSE; } return FALSE; } spam_buttons/setup.php0000644000000000000000000001665311201130721014142 0ustar rootroot, * Licensed under the GNU GPL. For full terms see the file COPYING. * * @package plugins * @subpackage spam_buttons * */ /** * Register this plugin with SquirrelMail * */ function squirrelmail_plugin_init_spam_buttons() { global $squirrelmail_plugin_hooks; // SM 1.4.x - display buttons on message list // $squirrelmail_plugin_hooks['mailbox_display_buttons']['spam_buttons'] = 'sb_mailbox_list_buttons'; // SM 1.5.x - display buttons on message list // $squirrelmail_plugin_hooks['message_list_controls']['spam_buttons'] = 'sb_mailbox_list_buttons'; // SM 1.5.0/1.5.1 - display buttons on button bar (on read message screen) // $squirrelmail_plugin_hooks['read_body_menu_top']['spam_buttons'] = 'sb_read_message_buttons'; // SM 1.5.2+ - display buttons on button bar (on read message screen) //TODO: 1.5.2 should change the API for the buttons on the read message screen, then this code will have to change to suit // $squirrelmail_plugin_hooks['template_construct_read_menubar_buttons.tpl']['spam_buttons'] = 'sb_read_message_buttons'; // display links in "Options" section on single message read screen // $squirrelmail_plugin_hooks['read_body_header_right']['spam_buttons'] = 'sb_read_message_links'; // SM 1.4.x - handle button click from message list page // $squirrelmail_plugin_hooks['move_before_move']['spam_buttons'] = 'sb_button_action'; // SM 1.5.x - handle button click from message list page (although // it is more proper to use "mailbox_display_button_action") // SM 1.4.x - print status message at top of message list // $squirrelmail_plugin_hooks['right_main_after_header']['spam_buttons'] = 'sb_button_action'; // SM 1.4.x - handle button click from read message page // $squirrelmail_plugin_hooks['read_body_header']['spam_buttons'] = 'sb_button_action'; // SM 1.5.x - handle button click from read message page // $squirrelmail_plugin_hooks['template_construct_read_headers.tpl']['spam_buttons'] = 'sb_button_action'; // SM 1.5.x - abort message view when message is moved/deleted // $squirrelmail_plugin_hooks['template_construct_read_message_body.tpl']['spam_buttons'] = 'sb_abort_message_view'; // show options on display preferences page // $squirrelmail_plugin_hooks['optpage_loadhook_display']['spam_buttons'] = 'spam_buttons_display_options'; // configuration check // $squirrelmail_plugin_hooks['configtest']['spam_buttons'] = 'spam_buttons_check_configuration'; } /** * Force the getpot script to pick up these translations * (which are in the config file in non-translated form) * * @ignore * */ function sb_no_op() { $ignore = _("Spam"); $ignore = _("Report Spam"); $ignore = _("Not Spam"); $ignore = _("Successfully reported as spam"); $ignore = _("Successfully reported as non-spam"); $ignore = _("Whitelist"); $ignore = _("Whitelist Sender"); $ignore = _("Blacklist"); $ignore = _("Blacklist Sender"); $ignore = _("Blacklist Sender"); $ignore = ngettext("Sender has been blacklisted", "Senders have been blacklisted", 1); $ignore = _("Sender has been blacklisted"); $ignore = _("Senders have been blacklisted"); $ignore = ngettext("Sender has been whitelisted", "Senders have been whitelisted", 1); $ignore = _("Sender has been whitelisted"); $ignore = _("Senders have been whitelisted"); } /** * Returns info about this plugin * */ function spam_buttons_info() { return array( 'english_name' => 'Spam Buttons', 'authors' => array( 'Paul Lesniewski' => array( 'email' => 'paul@squirrelmail.org', 'sm_site_username' => 'pdontthink', ), ), 'version' => '2.3.1', 'required_sm_version' => '1.4.0', 'requires_configuration' => 1, 'summary' => 'Puts Spam/Not Spam buttons on mailbox list and message view pages.', 'details' => 'This plugin will place "Spam" and/or "Not Spam" buttons on the mailbox message list page as well as on a single message view page. The action associated with the buttons (as well as the button text) can be configured to suit most any spam reporting system. Reporting by email, reporting by executing a command on the server, reporting by moving (or copying) the message to a designated folder and reporting by calling a custom-defined PHP function are all supported. Any number of custom buttons may also be added, where the associated action is completely customizable (for instance, adding the message sender to a whitelist or blacklist).', 'per_version_requirements' => array( '1.5.2' => array( // we are using get_current_hook_name() and load_config() in functions.php so we always need Compatibility // 'required_plugins' => array() ), '1.4.11' => array( 'requires_source_patch' => 0, ), '1.4.0' => array( 'requires_source_patch' => 1, 'required_plugins' => array( 'compatibility' => array( 'version' => '2.0.12', 'activate' => FALSE, ) ) ), ), ); } /** * Returns version info about this plugin * */ function spam_buttons_version() { $info = spam_buttons_info(); return $info['version']; } /** * Takes care of spam/ham button click from mailbox list * */ function sb_button_action($args) { include_once(SM_PATH . 'plugins/spam_buttons/report.php'); return sb_button_action_do($args); } /** * Adds spam/ham buttons to mailbox listing * */ function sb_mailbox_list_buttons(&$args) { include_once(SM_PATH . 'plugins/spam_buttons/buttons.php'); sb_mailbox_list_buttons_do($args); } /** * Adds spam/ham buttons to message display * */ function sb_read_message_buttons($args) { include_once(SM_PATH . 'plugins/spam_buttons/buttons.php'); return sb_read_message_buttons_do($args); } /** * Adds spam/ham links to message options list on read body page * */ function sb_read_message_links(&$links) { include_once(SM_PATH . 'plugins/spam_buttons/buttons.php'); sb_read_message_links_do($links); } /** * Display user configuration options on display preferences page * */ function spam_buttons_display_options() { include_once(SM_PATH . 'plugins/spam_buttons/options.php'); spam_buttons_display_options_do(); } /** * Validate that this plugin is configured correctly * * @return boolean Whether or not there was a * configuration error for this plugin. * */ function spam_buttons_check_configuration() { include_once(SM_PATH . 'plugins/spam_buttons/configtest.php'); return spam_buttons_check_configuration_do(); } /** * Abort message view when message is moved/deleted * out from under current message view * */ function sb_abort_message_view() { include_once(SM_PATH . 'plugins/spam_buttons/report.php'); sb_abort_message_view_do(); } spam_buttons/compose_functions-1.4.11.php0000644000000000000000000006567411127347164017310 0ustar rootroot, * Licensed under the GNU GPL. For full terms see the file COPYING. * * @package plugins * @subpackage spam_buttons * */ // // ripped from src/compose.php // /* This function is used when not sending or adding attachments */ function newMail ($mailbox='', $passed_id='', $passed_ent_id='', $action='', $session='') { global $editor_size, $default_use_priority, $body, $idents, $use_signature, $composesession, $data_dir, $username, $username, $key, $imapServerAddress, $imapPort, $compose_messages, $composeMessage, $body_quote; global $languages, $squirrelmail_language, $default_charset; /* * Set $default_charset to correspond with the user's selection * of language interface. $default_charset global is not correct, * if message is composed in new window. */ set_my_charset(); $send_to = $send_to_cc = $send_to_bcc = $subject = $identity = ''; $mailprio = 3; if ($passed_id) { $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0); sqimap_mailbox_select($imapConnection, $mailbox); $message = sqimap_get_message($imapConnection, $passed_id, $mailbox); $body = ''; if ($passed_ent_id) { /* redefine the messsage in case of message/rfc822 */ $message = $message->getEntity($passed_ent_id); /* message is an entity which contains the envelope and type0=message * and type1=rfc822. The actual entities are childs from * $message->entities[0]. That's where the encoding and is located */ $entities = $message->entities[0]->findDisplayEntity (array(), $alt_order = array('text/plain')); if (!count($entities)) { $entities = $message->entities[0]->findDisplayEntity (array(), $alt_order = array('text/plain','text/html')); } $orig_header = $message->rfc822_header; /* here is the envelope located */ /* redefine the message for picking up the attachments */ $message = $message->entities[0]; } else { $entities = $message->findDisplayEntity (array(), $alt_order = array('text/plain')); if (!count($entities)) { $entities = $message->findDisplayEntity (array(), $alt_order = array('text/plain','text/html')); } $orig_header = $message->rfc822_header; } $encoding = $message->header->encoding; $type0 = $message->type0; $type1 = $message->type1; foreach ($entities as $ent) { $unencoded_bodypart = mime_fetch_body($imapConnection, $passed_id, $ent); $body_part_entity = $message->getEntity($ent); $bodypart = decodeBody($unencoded_bodypart, $body_part_entity->header->encoding); if ($type1 == 'html') { $bodypart = str_replace("\n", ' ', $bodypart); $bodypart = preg_replace(array('/

/i','//i'), "\n", $bodypart); $bodypart = str_replace(array(' ','>','<'),array(' ','>','<'),$bodypart); $bodypart = strip_tags($bodypart); } if (isset($languages[$squirrelmail_language]['XTRA_CODE']) && function_exists($languages[$squirrelmail_language]['XTRA_CODE'])) { if (mb_detect_encoding($bodypart) != 'ASCII') { $bodypart = $languages[$squirrelmail_language]['XTRA_CODE']('decode', $bodypart); } } // charset encoding in compose form stuff if (isset($body_part_entity->header->parameters['charset'])) { $actual = $body_part_entity->header->parameters['charset']; } else { $actual = 'us-ascii'; } if ( $actual && is_conversion_safe($actual) && $actual != $default_charset){ $bodypart = charset_convert($actual,$bodypart,$default_charset,false); } // end of charset encoding in compose $body .= $bodypart; } if ($default_use_priority) { $mailprio = substr($orig_header->priority,0,1); if (!$mailprio) { $mailprio = 3; } } else { $mailprio = ''; } $identity = ''; $from_o = $orig_header->from; if (is_array($from_o)) { if (isset($from_o[0])) { $from_o = $from_o[0]; } } if (is_object($from_o)) { $orig_from = $from_o->getAddress(); } else { $orig_from = ''; } $identities = array(); if (count($idents) > 1) { foreach($idents as $nr=>$data) { $enc_from_name = '"'.$data['full_name'].'" <'. $data['email_address'].'>'; if(strtolower($enc_from_name) == strtolower($orig_from)) { $identity = $nr; break; } $identities[] = $enc_from_name; } $identity_match = $orig_header->findAddress($identities); if ($identity_match) { $identity = $identity_match; } } switch ($action) { case ('draft'): $use_signature = FALSE; $composeMessage->rfc822_header = $orig_header; $send_to = decodeHeader($orig_header->getAddr_s('to'),false,false,true); $send_to_cc = decodeHeader($orig_header->getAddr_s('cc'),false,false,true); $send_to_bcc = decodeHeader($orig_header->getAddr_s('bcc'),false,false,true); // FIXME: ident support? $subject = decodeHeader($orig_header->subject,false,false,true); /* remember the references and in-reply-to headers in case of an reply */ $composeMessage->rfc822_header->more_headers['References'] = $orig_header->references; $composeMessage->rfc822_header->more_headers['In-Reply-To'] = $orig_header->in_reply_to; $body_ary = explode("\n", $body); $cnt = count($body_ary) ; $body = ''; for ($i=0; $i < $cnt; $i++) { if (!ereg("^[>\\s]*$", $body_ary[$i]) || !$body_ary[$i]) { sqWordWrap($body_ary[$i], $editor_size, $default_charset ); $body .= $body_ary[$i] . "\n"; } unset($body_ary[$i]); } sqUnWordWrap($body); $composeMessage = getAttachments($message, $composeMessage, $passed_id, $entities, $imapConnection); break; case ('edit_as_new'): $send_to = decodeHeader($orig_header->getAddr_s('to'),false,false,true); $send_to_cc = decodeHeader($orig_header->getAddr_s('cc'),false,false,true); $send_to_bcc = decodeHeader($orig_header->getAddr_s('bcc'),false,false,true); $subject = decodeHeader($orig_header->subject,false,false,true); $mailprio = $orig_header->priority; $orig_from = ''; $composeMessage = getAttachments($message, $composeMessage, $passed_id, $entities, $imapConnection); sqUnWordWrap($body); break; case ('forward'): $send_to = ''; $subject = decodeHeader($orig_header->subject,false,false,true); if ((substr(strtolower($subject), 0, 4) != 'fwd:') && (substr(strtolower($subject), 0, 5) != '[fwd:') && (substr(strtolower($subject), 0, 6) != '[ fwd:')) { $subject = '[Fwd: ' . $subject . ']'; } $body = getforwardHeader($orig_header) . $body; $composeMessage = getAttachments($message, $composeMessage, $passed_id, $entities, $imapConnection); $body = "\n" . $body; break; case ('forward_as_attachment'): $composeMessage = getMessage_RFC822_Attachment($message, $composeMessage, $passed_id, $passed_ent_id, $imapConnection); $body = ''; /// CHANGE FOR SPAM_BUTTONS PLUGIN (added next 6 lines) $subject = decodeHeader($orig_header->subject,false,false,true); if ((substr(strtolower($subject), 0, 4) != 'fwd:') && (substr(strtolower($subject), 0, 5) != '[fwd:') && (substr(strtolower($subject), 0, 6) != '[ fwd:')) { $subject = '[Fwd: ' . $subject . ']'; } break; case ('reply_all'): if(isset($orig_header->mail_followup_to) && $orig_header->mail_followup_to) { $send_to = $orig_header->getAddr_s('mail_followup_to'); } else { $send_to_cc = replyAllString($orig_header); $send_to_cc = decodeHeader($send_to_cc,false,false,true); } case ('reply'): if (!$send_to) { $send_to = $orig_header->reply_to; if (is_array($send_to) && count($send_to)) { $send_to = $orig_header->getAddr_s('reply_to'); } else if (is_object($send_to)) { /* unneccesarry, just for failsafe purpose */ $send_to = $orig_header->getAddr_s('reply_to'); } else { $send_to = $orig_header->getAddr_s('from'); } } $send_to = decodeHeader($send_to,false,false,true); $subject = decodeHeader($orig_header->subject,false,false,true); $subject = trim($subject); if (substr(strtolower($subject), 0, 3) != 're:') { $subject = 'Re: ' . $subject; } /* this corrects some wrapping/quoting problems on replies */ $rewrap_body = explode("\n", $body); $from = (is_array($orig_header->from) && !empty($orig_header->from)) ? $orig_header->from[0] : $orig_header->from; sqUnWordWrap($body); $body = ''; $cnt = count($rewrap_body); for ($i=0;$i<$cnt;$i++) { sqWordWrap($rewrap_body[$i], $editor_size, $default_charset); if (preg_match("/^(>+)/", $rewrap_body[$i], $matches)) { $gt = $matches[1]; $body .= $body_quote . str_replace("\n", "\n" . $body_quote . "$gt ", rtrim($rewrap_body[$i])) ."\n"; } else { $body .= $body_quote . (!empty($body_quote) ? ' ' : '') . str_replace("\n", "\n" . $body_quote . (!empty($body_quote) ? ' ' : ''), rtrim($rewrap_body[$i])) . "\n"; } unset($rewrap_body[$i]); } $body = getReplyCitation($from , $orig_header->date) . $body; $composeMessage->reply_rfc822_header = $orig_header; break; default: break; } /// CHANGE FOR SPAM_BUTTONS PLUGIN /// $compose_messages[$session] = $composeMessage; /// // Not used any more, but left for posterity /// //sqsession_register($compose_messages, 'compose_messages'); /// session_write_close(); /// sqimap_logout($imapConnection); } $ret = array( 'send_to' => $send_to, 'send_to_cc' => $send_to_cc, 'send_to_bcc' => $send_to_bcc, 'subject' => $subject, 'mailprio' => $mailprio, 'body' => $body, 'identity' => $identity ); return ($ret); } /* function newMail() */ function getforwardHeader($orig_header) { global $editor_size; $display = array( _("Subject") => strlen(_("Subject")), _("From") => strlen(_("From")), _("Date") => strlen(_("Date")), _("To") => strlen(_("To")), _("Cc") => strlen(_("Cc")) ); $maxsize = max($display); $indent = str_pad('',$maxsize+2); foreach($display as $key => $val) { $display[$key] = $key .': '. str_pad('', $maxsize - $val); } $from = decodeHeader($orig_header->getAddr_s('from',"\n$indent"),false,false,true); $from = str_replace(' ',' ',$from); $to = decodeHeader($orig_header->getAddr_s('to',"\n$indent"),false,false,true); $to = str_replace(' ',' ',$to); $subject = decodeHeader($orig_header->subject,false,false,true); $subject = str_replace(' ',' ',$subject); $bodyTop = str_pad(' '._("Original Message").' ',$editor_size -2,'-',STR_PAD_BOTH) . "\n". $display[_("Subject")] . $subject . "\n" . $display[_("From")] . $from . "\n" . $display[_("Date")] . getLongDateString( $orig_header->date, $orig_header->date_unparsed ). "\n" . $display[_("To")] . $to . "\n"; if ($orig_header->cc != array() && $orig_header->cc !='') { $cc = decodeHeader($orig_header->getAddr_s('cc',"\n$indent"),false,false,true); $cc = str_replace(' ',' ',$cc); $bodyTop .= $display[_("Cc")] .$cc . "\n"; } $bodyTop .= str_pad('', $editor_size -2 , '-') . "\n\n"; return $bodyTop; } function getMessage_RFC822_Attachment($message, $composeMessage, $passed_id, $passed_ent_id='', $imapConnection) { global $attachment_dir, $username, $data_dir, $uid_support; $hashed_attachment_dir = getHashedDir($username, $attachment_dir); if (!$passed_ent_id) { $body_a = sqimap_run_command($imapConnection, 'FETCH '.$passed_id.' BODY.PEEK[]', TRUE, $response, $readmessage, $uid_support); } else { $body_a = sqimap_run_command($imapConnection, 'FETCH '.$passed_id.' BODY.PEEK['.$passed_ent_id.']', TRUE, $response, $readmessage, $uid_support); $message = $message->parent; } if ($response == 'OK') { $subject = encodeHeader($message->rfc822_header->subject); array_shift($body_a); array_pop($body_a); $body = implode('', $body_a) . "\r\n"; $localfilename = GenerateRandomString(32, 'FILE', 7); $full_localfilename = "$hashed_attachment_dir/$localfilename"; $fp = fopen($full_localfilename, 'w'); fwrite ($fp, $body); fclose($fp); $composeMessage->initAttachment('message/rfc822',$subject.'.msg', $localfilename); } return $composeMessage; } /** * temporary function to make use of the deliver class. * In the future the responsible backend should be automaticly loaded * and conf.pl should show a list of available backends. * The message also should be constructed by the message class. */ function deliverMessage($composeMessage, $draft=false) { global $send_to, $send_to_cc, $send_to_bcc, $mailprio, $subject, $body, $username, $popuser, $usernamedata, $identity, $idents, $data_dir, $request_mdn, $request_dr, $default_charset, $color, $useSendmail, $domain, $action, $default_move_to_sent, $move_to_sent; global $imapServerAddress, $imapPort, $sent_folder, $key; /// CHANGE FOR SPAM_BUTTONS PLUGIN /* --- do we need to do overrides again here? should not need to, but // someone reported problems with the default not being overriden // when using this reporting method --- global $spam_report_email_method, $spam_report_smtpServerAddress, $spam_report_smtpPort, $spam_report_useSendmail, $spam_report_smtp_auth_mech, $spam_report_use_smtp_tls, $smtpServerAddress, $smtpPort, $useSendmail, $smtp_auth_mech, $use_smtp_tls, $sb_debug; spam_buttons_init(); // take care of overrides for SMTP server // if (!empty($spam_report_smtpServerAddress)) $smtpServerAddress = $spam_report_smtpServerAddress; if (!empty($spam_report_smtpPort)) $smtpPort = $spam_report_smtpPort; if ($spam_report_useSendmail !== '') $useSendmail = $spam_report_useSendmail; if (!empty($spam_report_smtp_auth_mech)) $smtp_auth_mech = $spam_report_smtp_auth_mech; if (!empty($spam_report_use_smtp_tls)) $use_smtp_tls = $spam_report_use_smtp_tls; --- */ $rfc822_header = $composeMessage->rfc822_header; $abook = addressbook_init(false, true); $rfc822_header->to = $rfc822_header->parseAddress($send_to,true, array(), '', $domain, array(&$abook,'lookup')); $rfc822_header->cc = $rfc822_header->parseAddress($send_to_cc,true,array(), '',$domain, array(&$abook,'lookup')); $rfc822_header->bcc = $rfc822_header->parseAddress($send_to_bcc,true, array(), '',$domain, array(&$abook,'lookup')); $rfc822_header->priority = $mailprio; $rfc822_header->subject = $subject; $special_encoding=''; if (strtolower($default_charset) == 'iso-2022-jp') { if (mb_detect_encoding($body) == 'ASCII') { $special_encoding = '8bit'; } else { $body = mb_convert_encoding($body, 'JIS'); $special_encoding = '7bit'; } } $composeMessage->setBody($body); if (ereg("^([^@%/]+)[@%/](.+)$", $username, $usernamedata)) { $popuser = $usernamedata[1]; $domain = $usernamedata[2]; unset($usernamedata); } else { $popuser = $username; } $reply_to = ''; $from_mail = $idents[$identity]['email_address']; $full_name = $idents[$identity]['full_name']; $reply_to = $idents[$identity]['reply_to']; if (!$from_mail) { $from_mail = "$popuser@$domain"; } $rfc822_header->from = $rfc822_header->parseAddress($from_mail,true); if ($full_name) { $from = $rfc822_header->from[0]; if (!$from->host) $from->host = $domain; $full_name_encoded = encodeHeader($full_name); if ($full_name_encoded != $full_name) { $from_addr = $full_name_encoded .' <'.$from->mailbox.'@'.$from->host.'>'; } else { $from_addr = '"'.$full_name .'" <'.$from->mailbox.'@'.$from->host.'>'; } $rfc822_header->from = $rfc822_header->parseAddress($from_addr,true); } if ($reply_to) { $rfc822_header->reply_to = $rfc822_header->parseAddress($reply_to,true); } /* Receipt: On Read */ if (isset($request_mdn) && $request_mdn) { $rfc822_header->dnt = $rfc822_header->parseAddress($from_mail,true); } /* Receipt: On Delivery */ if (isset($request_dr) && $request_dr) { $rfc822_header->more_headers['Return-Receipt-To'] = $from_mail; } /* multipart messages */ if (count($composeMessage->entities)) { $message_body = new Message(); $message_body->body_part = $composeMessage->body_part; $composeMessage->body_part = ''; $mime_header = new MessageHeader; $mime_header->type0 = 'text'; $mime_header->type1 = 'plain'; if ($special_encoding) { $mime_header->encoding = $special_encoding; } else { $mime_header->encoding = '8bit'; } if ($default_charset) { $mime_header->parameters['charset'] = $default_charset; } $message_body->mime_header = $mime_header; array_unshift($composeMessage->entities, $message_body); $content_type = new ContentType('multipart/mixed'); } else { $content_type = new ContentType('text/plain'); if ($special_encoding) { $rfc822_header->encoding = $special_encoding; } else { $rfc822_header->encoding = '8bit'; } if ($default_charset) { $content_type->properties['charset']=$default_charset; } } $rfc822_header->content_type = $content_type; $composeMessage->rfc822_header = $rfc822_header; /* Here you can modify the message structure just before we hand it over to deliver */ /// CHANGE FOR SPAM_BUTTONS PLUGIN /// $hookReturn = do_hook('compose_send', $composeMessage); /// /* Get any changes made by plugins to $composeMessage. */ /// if ( is_object($hookReturn[1]) ) { /// $composeMessage = $hookReturn[1]; /// } if (!$useSendmail && !$draft) { require_once(SM_PATH . 'class/deliver/Deliver_SMTP.class.php'); $deliver = new Deliver_SMTP(); global $smtpServerAddress, $smtpPort, $pop_before_smtp, $smtp_auth_mech; $authPop = (isset($pop_before_smtp) && $pop_before_smtp) ? true : false; $user = ''; $pass = ''; get_smtp_user($user, $pass); $stream = $deliver->initStream($composeMessage,$domain,0, $smtpServerAddress, $smtpPort, $user, $pass, $authPop); } elseif (!$draft) { require_once(SM_PATH . 'class/deliver/Deliver_SendMail.class.php'); global $sendmail_path, $sendmail_args; // Check for outdated configuration if (!isset($sendmail_args)) { if ($sendmail_path=='/var/qmail/bin/qmail-inject') { $sendmail_args = ''; } else { $sendmail_args = '-i -t'; } } $deliver = new Deliver_SendMail(array('sendmail_args'=>$sendmail_args)); $stream = $deliver->initStream($composeMessage,$sendmail_path); } elseif ($draft) { global $draft_folder; require_once(SM_PATH . 'class/deliver/Deliver_IMAP.class.php'); $imap_stream = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0); if (sqimap_mailbox_exists ($imap_stream, $draft_folder)) { require_once(SM_PATH . 'class/deliver/Deliver_IMAP.class.php'); $imap_deliver = new Deliver_IMAP(); $length = $imap_deliver->mail($composeMessage); sqimap_append ($imap_stream, $draft_folder, $length); $imap_deliver->mail($composeMessage, $imap_stream); sqimap_append_done ($imap_stream, $draft_folder); sqimap_logout($imap_stream); unset ($imap_deliver); $composeMessage->purgeAttachments(); return $length; } else { $msg = '
'.sprintf(_("Error: Draft folder %s does not exist."), htmlspecialchars($draft_folder)); plain_error_message($msg, $color); return false; } } $succes = false; if ($stream) { $length = $deliver->mail($composeMessage, $stream); $succes = $deliver->finalizeStream($stream); } if (!$succes) { $msg = _("Message not sent.") .' '. _("Server replied:") . "\n

\n" . $deliver->dlv_msg . '
' . $deliver->dlv_ret_nr . ' ' . $deliver->dlv_server_msg . "
\n\n"; plain_error_message($msg, $color); } else { unset ($deliver); $move_to_sent = getPref($data_dir,$username,'move_to_sent'); $imap_stream = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0); /* Move to sent code */ /// CHANGE FOR SPAM_BUTTONS PLUGIN (added next 2 lines) global $sb_keep_copy_in_sent; if ($sb_keep_copy_in_sent) { if (isset($default_move_to_sent) && ($default_move_to_sent != 0)) { $svr_allow_sent = true; } else { $svr_allow_sent = false; } if (isset($sent_folder) && (($sent_folder != '') || ($sent_folder != 'none')) && sqimap_mailbox_exists( $imap_stream, $sent_folder)) { $fld_sent = true; } else { $fld_sent = false; } if ((isset($move_to_sent) && ($move_to_sent != 0)) || (!isset($move_to_sent))) { $lcl_allow_sent = true; } else { $lcl_allow_sent = false; } if (($fld_sent && $svr_allow_sent && !$lcl_allow_sent) || ($fld_sent && $lcl_allow_sent)) { sqimap_append ($imap_stream, $sent_folder, $length); require_once(SM_PATH . 'class/deliver/Deliver_IMAP.class.php'); $imap_deliver = new Deliver_IMAP(); $imap_deliver->mail($composeMessage, $imap_stream); sqimap_append_done ($imap_stream, $sent_folder); unset ($imap_deliver); } /// CHANGE FOR SPAM_BUTTONS PLUGIN (added next line) } global $passed_id, $mailbox, $action; $composeMessage->purgeAttachments(); if ($action == 'reply' || $action == 'reply_all') { sqimap_mailbox_select ($imap_stream, $mailbox); sqimap_messages_flag ($imap_stream, $passed_id, $passed_id, 'Answered', false); } sqimap_logout($imap_stream); } return $succes; } if (!function_exists('is_conversion_safe')) { /** * Function informs if it is safe to convert given charset to the one that is used by user. * * It is safe to use conversion only if user uses utf-8 encoding and when * converted charset is similar to the one that is used by user. * * @param string $input_charset Charset of text that needs to be converted * @return bool is it possible to convert to user's charset */ function is_conversion_safe($input_charset) { global $languages, $sm_notAlias, $default_charset, $lossy_encoding; if (isset($lossy_encoding) && $lossy_encoding ) return true; // convert to lower case $input_charset = strtolower($input_charset); // Is user's locale Unicode based ? if ( $default_charset == "utf-8" ) { return true; } // Charsets that are similar switch ($default_charset) { case "windows-1251": if ( $input_charset == "iso-8859-5" || $input_charset == "koi8-r" || $input_charset == "koi8-u" ) { return true; } else { return false; } case "windows-1257": if ( $input_charset == "iso-8859-13" || $input_charset == "iso-8859-4" ) { return true; } else { return false; } case "iso-8859-4": if ( $input_charset == "iso-8859-13" || $input_charset == "windows-1257" ) { return true; } else { return false; } case "iso-8859-5": if ( $input_charset == "windows-1251" || $input_charset == "koi8-r" || $input_charset == "koi8-u" ) { return true; } else { return false; } case "iso-8859-13": if ( $input_charset == "iso-8859-4" || $input_charset == "windows-1257" ) { return true; } else { return false; } case "koi8-r": if ( $input_charset == "windows-1251" || $input_charset == "iso-8859-5" || $input_charset == "koi8-u" ) { return true; } else { return false; } case "koi8-u": if ( $input_charset == "windows-1251" || $input_charset == "iso-8859-5" || $input_charset == "koi8-r" ) { return true; } else { return false; } default: return false; } } } spam_buttons/README0000644000000000000000000000006511203033700013140 0ustar rootrootPlease see all documentation in the docs/ directory. spam_buttons/buttons.php0000644000000000000000000007622711140715733014521 0ustar rootroot, * Licensed under the GNU GPL. For full terms see the file COPYING. * * @package plugins * @subpackage spam_buttons * */ /** * Constructs spam button text * * @param array $buttons The list of buttons being added to under 1.5.2+ * NOTE that this parameter is passed by reference * and is potentially modified herein. Because it * is passed by reference, PHP 4 doesn't like a default * value being specified, so callers should pass an * empty string when it is not needed (usually only * needed under 1.5.2 during the relevant hooks, such * as "message_list_controls"). * @param boolean $dont_show_if_report_by_move_to_folder When true, and the * report-by-move-to- * folder method is * configured, don't * show the corresponding * button if the message * in question is an * attachment to another * message, otherwise all * buttons are shown no * matter what (OPTIONAL; * default = FALSE). * * @return string HTML for the buttons to be displayed (for use in 1.4.x) * */ function get_spam_buttons(&$buttons, $dont_show_if_report_by_move_to_folder=FALSE) { global $show_not_spam_button, $spam_button_text, $not_spam_button_text, $show_is_spam_button, $username, $data_dir, $sb_report_spam_by_move_to_folder, $sb_report_not_spam_by_move_to_folder, $sb_suppress_spam_button_folder, $sb_suppress_spam_button_folder_allow_override, $sb_suppress_not_spam_button_folder, $sb_suppress_not_spam_button_folder_allow_override, $sb_show_spam_button_folder, $sb_show_spam_button_folder_allow_override, $sb_show_not_spam_button_folder, $sb_show_not_spam_button_folder_allow_override, $extra_buttons; $passed_ent_id = 0; sqgetGlobalVar('passed_ent_id', $passed_ent_id, SQ_FORM); sqgetGlobalVar('mailbox', $mailbox, SQ_FORM); if (empty($mailbox)) $mailbox = 'INBOX'; spam_buttons_init(); if ($sb_suppress_spam_button_folder_allow_override) { $sb_suppress_spam_button_folder = getPref($data_dir, $username, 'sb_suppress_spam_button_folder', $sb_suppress_spam_button_folder); } if ($sb_suppress_not_spam_button_folder_allow_override) { $sb_suppress_not_spam_button_folder = getPref($data_dir, $username, 'sb_suppress_not_spam_button_folder', $sb_suppress_not_spam_button_folder); } if ($sb_show_spam_button_folder_allow_override) { $sb_show_spam_button_folder = getPref($data_dir, $username, 'sb_show_spam_button_folder', $sb_show_spam_button_folder); } if ($sb_show_not_spam_button_folder_allow_override) { $sb_show_not_spam_button_folder = getPref($data_dir, $username, 'sb_show_not_spam_button_folder', $sb_show_not_spam_button_folder); } // these options used to be a strings; these lines convert // values that may have already been stored in user prefs // as strings into proper array format (also unpacks // serialized arrays for SM v1.4.14+)... perhaps this // code should be removed a year (or more?) after 1.4.x // supports multiple select folder lists on the options page // (but not the unserialize() calls) // if (empty($sb_suppress_spam_button_folder)) $sb_suppress_spam_button_folder = array(); else if (check_sm_version(1, 4, 14) && !is_array($sb_suppress_spam_button_folder)) $sb_suppress_spam_button_folder = @unserialize($sb_suppress_spam_button_folder); if (!is_array($sb_suppress_spam_button_folder)) $sb_suppress_spam_button_folder = array($sb_suppress_spam_button_folder); if (empty($sb_suppress_not_spam_button_folder)) $sb_suppress_not_spam_button_folder = array(); else if (check_sm_version(1, 4, 14) && !is_array($sb_suppress_not_spam_button_folder)) $sb_suppress_not_spam_button_folder = @unserialize($sb_suppress_not_spam_button_folder); if (!is_array($sb_suppress_not_spam_button_folder)) $sb_suppress_not_spam_button_folder = array($sb_suppress_not_spam_button_folder); if (empty($sb_show_spam_button_folder)) $sb_show_spam_button_folder = array(); else if (check_sm_version(1, 4, 14) && !is_array($sb_show_spam_button_folder)) $sb_show_spam_button_folder = @unserialize($sb_show_spam_button_folder); if (!is_array($sb_show_spam_button_folder)) $sb_show_spam_button_folder = array($sb_show_spam_button_folder); if (empty($sb_show_not_spam_button_folder)) $sb_show_not_spam_button_folder = array(); else if (check_sm_version(1, 4, 14) && !is_array($sb_show_not_spam_button_folder)) $sb_show_not_spam_button_folder = @unserialize($sb_show_not_spam_button_folder); if (!is_array($sb_show_not_spam_button_folder)) $sb_show_not_spam_button_folder = array($sb_show_not_spam_button_folder); //TODO: create tooltip with more verbose explanation $ret = ''; if ($show_is_spam_button || $show_not_spam_button) $ret .= ' '; sq_change_text_domain('spam_buttons'); // 1) is button turned on in the first place? // 2) either A or B below: // A) if current message is tagged as spam, don't show spam button // B) if not using message tag settings or not in message view, then: // a) if in (one of) the ham folder(s) ($sb_show_spam_button_folder // defines a list of ham folders to show the spam button in), // show spam button // b) otherwise, if not using the ham folder (list), then // if in (one of) the spam folder(s), don't show spam button // 3) can't show button if caller doesn't want it shown // when report method is move-to-folder and we're // looking at a message that is an attachment to another // if ($show_is_spam_button // 1 && (current_message_is_tagged(TRUE) === FALSE // 2A || (current_message_is_tagged(TRUE) === 0 // 2B && (in_array($mailbox, $sb_show_spam_button_folder) // 2Ba || (empty($sb_show_spam_button_folder) // 2Bb && !in_array($mailbox, $sb_suppress_spam_button_folder))))) && (!$dont_show_if_report_by_move_to_folder // 3 || !($sb_report_spam_by_move_to_folder && !empty($passed_ent_id)))) { if (check_sm_version(1, 5, 2)) $buttons['isSpam'] = array('value' => _($spam_button_text), 'type' => 'submit'); else if (check_sm_version(1, 5, 1)) $buttons[1]['isSpam'] = array(0 => _($spam_button_text), 1 => 'submit'); else $ret .= '\n"; } // 1) is button turned on in the first place? // 2) either A or B below: // A) if current message is tagged as ham, don't show ham button // B) if not using message tag settings or not in message view, then: // a) if in (one of) the spam folder(s) ($sb_show_not_spam_button_folder // defines a list of spam folders to show the ham button in), // show ham button // b) otherwise, if not using the spam folder (list), then // if in (one of) the ham folder(s), don't show ham button // 3) can't show button if caller doesn't want it shown // when report method is move-to-folder and we're // looking at a message that is an attachment to another // if ($show_not_spam_button // 1 && (current_message_is_tagged(FALSE) === FALSE // 2A || (current_message_is_tagged(FALSE) === 0 // 2B && (in_array($mailbox, $sb_show_not_spam_button_folder) // 2Ba || (empty($sb_show_not_spam_button_folder) // 2Bb && !in_array($mailbox, $sb_suppress_not_spam_button_folder))))) && (!$dont_show_if_report_by_move_to_folder // 3 || !($sb_report_not_spam_by_move_to_folder && !empty($passed_ent_id)))) { if (check_sm_version(1, 5, 2)) $buttons['notSpam'] = array('value' => _($not_spam_button_text), 'type' => 'submit'); else if (check_sm_version(1, 5, 1)) $buttons[1]['notSpam'] = array(0 => _($not_spam_button_text), 1 => 'submit'); else $ret .= '\n"; } // add any extra buttons // foreach ($extra_buttons as $button => $button_info) { // build button // if (sb_show_custom_button_or_link($button, $button_info)) { $button_name = preg_replace('/[^a-zA-Z0-9]/', '_', $button); if (check_sm_version(1, 5, 2)) $buttons[$button_name] = array('value' => _($button), 'type' => 'submit'); else if (check_sm_version(1, 5, 1)) $buttons[1][$button_name] = array(0 => _($button), 1 => 'submit'); else $ret .= '\n"; } } sq_change_text_domain('squirrelmail'); return $ret; } /** * Adds spam/ham links to message options list on read body page * */ function sb_read_message_links_do(&$links) { include_once(SM_PATH . 'plugins/spam_buttons/functions.php'); global $show_spam_link_on_read_body, $show_not_spam_button, $spam_button_text, $not_spam_button_text, $show_is_spam_button, $sb_report_spam_by_move_to_folder, $username, $sb_report_not_spam_by_move_to_folder, $sb_suppress_spam_button_folder, $data_dir, $sb_suppress_spam_button_folder_allow_override, $sb_suppress_not_spam_button_folder, $sb_suppress_not_spam_button_folder_allow_override, $sb_show_spam_button_folder, $sb_show_spam_button_folder_allow_override, $sb_show_not_spam_button_folder, $extra_buttons, $sb_show_not_spam_button_folder_allow_override; spam_buttons_init(); if (!$show_spam_link_on_read_body) return; if ($sb_suppress_spam_button_folder_allow_override) { $sb_suppress_spam_button_folder = getPref($data_dir, $username, 'sb_suppress_spam_button_folder', $sb_suppress_spam_button_folder); } if ($sb_suppress_not_spam_button_folder_allow_override) { $sb_suppress_not_spam_button_folder = getPref($data_dir, $username, 'sb_suppress_not_spam_button_folder', $sb_suppress_not_spam_button_folder); } if ($sb_show_spam_button_folder_allow_override) { $sb_show_spam_button_folder = getPref($data_dir, $username, 'sb_show_spam_button_folder', $sb_show_spam_button_folder); } if ($sb_show_not_spam_button_folder_allow_override) { $sb_show_not_spam_button_folder = getPref($data_dir, $username, 'sb_show_not_spam_button_folder', $sb_show_not_spam_button_folder); } // these options used to be a strings; these lines convert // values that may have already been stored in user prefs // as strings into proper array format (also unpacks // serialized arrays for SM v1.4.14+)... perhaps this // code should be removed a year (or more?) after 1.4.x // supports multiple select folder lists on the options page // (but not the unserialize() calls) // if (empty($sb_suppress_spam_button_folder)) $sb_suppress_spam_button_folder = array(); else if (check_sm_version(1, 4, 14) && !is_array($sb_suppress_spam_button_folder)) $sb_suppress_spam_button_folder = @unserialize($sb_suppress_spam_button_folder); if (!is_array($sb_suppress_spam_button_folder)) $sb_suppress_spam_button_folder = array($sb_suppress_spam_button_folder); if (empty($sb_suppress_not_spam_button_folder)) $sb_suppress_not_spam_button_folder = array(); else if (check_sm_version(1, 4, 14) && !is_array($sb_suppress_not_spam_button_folder)) $sb_suppress_not_spam_button_folder = @unserialize($sb_suppress_not_spam_button_folder); if (!is_array($sb_suppress_not_spam_button_folder)) $sb_suppress_not_spam_button_folder = array($sb_suppress_not_spam_button_folder); if (empty($sb_show_spam_button_folder)) $sb_show_spam_button_folder = array(); else if (check_sm_version(1, 4, 14) && !is_array($sb_show_spam_button_folder)) $sb_show_spam_button_folder = @unserialize($sb_show_spam_button_folder); if (!is_array($sb_show_spam_button_folder)) $sb_show_spam_button_folder = array($sb_show_spam_button_folder); if (empty($sb_show_not_spam_button_folder)) $sb_show_not_spam_button_folder = array(); else if (check_sm_version(1, 4, 14) && !is_array($sb_show_not_spam_button_folder)) $sb_show_not_spam_button_folder = @unserialize($sb_show_not_spam_button_folder); if (!is_array($sb_show_not_spam_button_folder)) $sb_show_not_spam_button_folder = array($sb_show_not_spam_button_folder); $spam_links = array(); $passed_ent_id = 0; sqgetGlobalVar('mailbox', $mailbox, SQ_FORM); sqgetGlobalVar('passed_ent_id', $passed_ent_id, SQ_FORM); sqgetGlobalVar('startMessage', $startMessage, SQ_FORM); sqgetGlobalVar('view_as_html', $view_as_html, SQ_FORM); sqgetGlobalVar('account', $account, SQ_FORM); if (sqGetGlobalVar('passed_id', $passed_id, SQ_FORM)) // fix for Dovecot UIDs can be bigger than normal integers $passed_id = (preg_match('/^[0-9]+$/', $passed_id) ? $passed_id : '0'); sq_change_text_domain('spam_buttons'); //TODO: create tooltip with more verbose explanation // 1) is button turned on in the first place? // 2) either A or B below: // A) if current message is tagged as spam, don't show spam button // B) if not using message tag settings, then: // a) if in (one of) the ham folder(s) ($sb_show_spam_button_folder // defines a list of ham folders to show the spam button in), // show spam button // b) otherwise, if not using the ham folder (list), then // if in (one of) the spam folder(s), don't show spam button // 3) can't show button if report method is move-to-folder and we're // looking at a message that is an attachment to another // if ($show_is_spam_button // 1 && (current_message_is_tagged(TRUE) === FALSE // 2A || (current_message_is_tagged(TRUE) === 0 // 2B && (in_array($mailbox, $sb_show_spam_button_folder) // 2Ba || (empty($sb_show_spam_button_folder) // 2Bb && !in_array($mailbox, $sb_suppress_spam_button_folder))))) && !($sb_report_spam_by_move_to_folder && !empty($passed_ent_id))) // 3 $spam_links[] = array('URL' => sqm_baseuri() . 'src/read_body.php?isSpam=yslnk&mailbox=' . urlencode($mailbox) . '&passed_id=' . $passed_id . '&view_as_html=' . $view_as_html . '&startMessage=' . $startMessage . '&passed_ent_id=' . $passed_ent_id . '&account=' . $account, 'Text' => _($spam_button_text)); // 1) is button turned on in the first place? // 2) either A or B below: // A) if current message is tagged as ham, don't show ham button // B) if not using message tag settings, then: // a) if in (one of) the spam folder(s) ($sb_show_not_spam_button_folder // defines a list of spam folders to show the ham button in), // show ham button // b) otherwise, if not using the spam folder (list), then // if in (one of) the ham folder(s), don't show ham button // 3) can't show button if report method is move-to-folder and we're // looking at a message that is an attachment to another // if ($show_not_spam_button // 1 && (current_message_is_tagged(FALSE) === FALSE // 2A || (current_message_is_tagged(FALSE) === 0 // 2B && (in_array($mailbox, $sb_show_not_spam_button_folder) // 2Ba || (empty($sb_show_not_spam_button_folder) // 2Bb && !in_array($mailbox, $sb_suppress_not_spam_button_folder))))) && !($sb_report_not_spam_by_move_to_folder && !empty($passed_ent_id))) // 3 $spam_links[] = array('URL' => sqm_baseuri() . 'src/read_body.php?notSpam=yslnk&mailbox=' . urlencode($mailbox) . '&passed_id=' . $passed_id . '&view_as_html=' . $view_as_html . '&startMessage=' . $startMessage . '&passed_ent_id=' . $passed_ent_id . '&account=' . $account, 'Text' => _($not_spam_button_text)); if (check_sm_version(1, 5, 2)) $links = array_merge($links, $spam_links); else { foreach ($spam_links as $link) echo ' | ' . $link['Text'] . ''; } // add any extra links // foreach ($extra_buttons as $button => $button_info) { // build button // if (sb_show_custom_button_or_link($button, $button_info)) { $button_name = preg_replace('/[^a-zA-Z0-9]/', '_', $button); $button_link = sqm_baseuri() . 'src/read_body.php?' . $button_name . '=yslnk&mailbox=' . urlencode($mailbox) . '&passed_id=' . $passed_id . '&view_as_html=' . $view_as_html . '&startMessage=' . $startMessage . '&passed_ent_id=' . $passed_ent_id . '&account=' . $account; if (check_sm_version(1, 5, 2)) $links[] = array('URL' => $button_link, 'Text' => $button); else echo ' | ' . $button . ''; } } sq_change_text_domain('squirrelmail'); } /** * Adds spam/ham buttons to mailbox listing * */ function sb_mailbox_list_buttons_do(&$buttons) { include_once(SM_PATH . 'plugins/spam_buttons/functions.php'); global $show_spam_buttons_on_message_list; spam_buttons_init(); if (!$show_spam_buttons_on_message_list) return; if (check_sm_version(1, 5, 1)) { get_spam_buttons($buttons); } else { $temp = ''; echo get_spam_buttons($temp); } } /** * Adds spam/ham buttons to message display * (currently only useful in 1.5.x) * */ function sb_read_message_buttons_do($args) { include_once(SM_PATH . 'plugins/spam_buttons/functions.php'); global $show_spam_buttons_on_read_body; spam_buttons_init(); if (!$show_spam_buttons_on_read_body) return; if (check_sm_version(1, 5, 2)) { //TODO: 1.5.2 should change the API for the buttons on the read message screen, then this code will have to change to suit global $oTemplate; sqgetGlobalVar('mailbox', $mailbox, SQ_FORM); sqgetGlobalVar('passed_ent_id', $passed_ent_id, SQ_FORM); sqgetGlobalVar('startMessage', $startMessage, SQ_FORM); sqgetGlobalVar('view_as_html', $view_as_html, SQ_FORM); sqgetGlobalVar('account', $account, SQ_FORM); if (sqGetGlobalVar('passed_id', $passed_id, SQ_FORM)) // fix for Dovecot UIDs can be bigger than normal integers $passed_id = (preg_match('/^[0-9]+$/', $passed_id) ? $passed_id : '0'); $buttons = array(); get_spam_buttons($buttons, TRUE); $oTemplate->assign('buttons', $buttons); $oTemplate->assign('mailbox', $mailbox); $oTemplate->assign('passed_id', $passed_id); $oTemplate->assign('passed_ent_id', $passed_ent_id); $oTemplate->assign('startMessage', $startMessage); $oTemplate->assign('view_as_html', $view_as_html); $oTemplate->assign('account', $account); $output = $oTemplate->fetch('plugins/spam_buttons/read_menubar_buttons.tpl'); return array('read_body_menu_buttons_bottom' => $output, 'read_body_menu_buttons_top' => $output); } // as of SM version 1.5.0, this works a little differently // else if (check_sm_version(1, 5, 0)) { sqgetGlobalVar('mailbox', $mailbox, SQ_FORM); sqgetGlobalVar('passed_ent_id', $passed_ent_id, SQ_FORM); sqgetGlobalVar('startMessage', $startMessage, SQ_FORM); sqgetGlobalVar('view_as_html', $view_as_html, SQ_FORM); if (sqGetGlobalVar('passed_id', $passed_id, SQ_FORM)) // fix for Dovecot UIDs can be bigger than normal integers $passed_id = (preg_match('/^[0-9]+$/', $passed_id) ? $passed_id : '0'); // add spam buttons after delete stuff // $temp = ''; $args[1] = preg_replace('/<\/td>/', '
' . get_spam_buttons($temp, TRUE) . '' . '' . '' . '' . '' . '
', $args[1], 1); return $args; } // all older versions... way too much trouble, especially if // preview pane is in use; read_body_header_right will be // sufficient // else { return; } } /** * Determine if the current message being viewed is spam or ham * * If the configuration items related to this functionality are * not set, or we are not on a message view screen, this always * returns 0 (see WARNING below). * * @param boolean $spam When TRUE, check if the message is spam, * when FALSE, check if the message is ham. * * @return mixed TRUE if the message has been tagged as inquired * FALSE if the message has not been tagged as such * 0 if the needed configuration settings are not * set up in the configuration file or the current * page request is not the message view page. * WARNING: callers need to carefully check for * either 0 or FALSE (using === or !==). * */ function current_message_is_tagged($spam) { if (defined('PAGE_NAME')) { if (PAGE_NAME != 'read_body') return 0; } else { global $PHP_SELF; if (strpos($PHP_SELF, '/src/read_body') === FALSE) return 0; } global $sb_spam_header_name, $sb_not_spam_header_name, $sb_spam_header_value, $sb_not_spam_header_value; spam_buttons_init(); sqgetGlobalVar('passed_ent_id', $passed_ent_id, SQ_FORM); if (sqGetGlobalVar('passed_id', $passed_id, SQ_FORM)) // fix for Dovecot UIDs can be bigger than normal integers $passed_id = (preg_match('/^[0-9]+$/', $passed_id) ? $passed_id : '0'); if ($spam) { if (empty($sb_spam_header_name) || empty($sb_spam_header_value)) return 0; $header = sb_get_message_header($passed_id, $passed_ent_id, $sb_spam_header_name); if (preg_match($sb_spam_header_value, trim($header[1]))) return TRUE; /* ......old code, less efficient; left for posterity............................ $headers = sb_get_message_headers($passed_id, $passed_ent_id); foreach ($headers as $header) if (strtolower($header[0]) == strtolower($sb_spam_header_name . ':') && preg_match($sb_spam_header_value, trim($header[1]))) return TRUE; ............................................................................. */ return FALSE; } else { if (empty($sb_not_spam_header_name) || empty($sb_not_spam_header_value)) return 0; $header = sb_get_message_header($passed_id, $passed_ent_id, $sb_not_spam_header_name); if (preg_match($sb_not_spam_header_value, trim($header[1]))) return TRUE; /* ......old code, less efficient; left for posterity............................ $headers = sb_get_message_headers($passed_id, $passed_ent_id); foreach ($headers as $header) if (strtolower($header[0]) == strtolower($sb_not_spam_header_name . ':') && preg_match($sb_not_spam_header_value, trim($header[1]))) return TRUE; ............................................................................. */ return FALSE; } } /** * Determines if a custom/extra button or link should be shown. * * @param string $button_name The name of the button or link * @param array $button_info The array of button callbacks and * associated information from the * configuration file * * @return boolean TRUE if the button should be shown, or FALSE * if it should not. * */ function sb_show_custom_button_or_link($button_name, $button_info) { global $username; $callback = ''; $action = ''; $passed_id = ''; $passed_ent_id = ''; $from = ''; $error = ''; $show_it = FALSE; // this function is found in the Compatibility plugin v2.0.5+ // $hook_name = get_current_hook_name(); sq_change_text_domain('spam_buttons'); // in this case, SquirrelMail is building the buttons at the // top of the message list screen // if ($hook_name == 'mailbox_display_buttons' // SM 1.4.x || $hook_name == 'message_list_controls') // SM 1.5.x { $action = 'MESSAGE_LIST_BUTTON'; if (!isset($button_info[0])) $error = sprintf(_("Spam Buttons plugin is not configured correctly! Check custom button configuration array for \"%s\""), $button_name); else $callback = $button_info[0]; } // in this case, SquirrelMail is building the "Options" links // on the message view screen // else if ($hook_name == 'read_body_header_right') { $action = 'MESSAGE_VIEW_LINK'; if (!isset($button_info[1])) $error = sprintf(_("Spam Buttons plugin is not configured correctly! Check custom button configuration array for \"%s\""), $button_name); else $callback = $button_info[1]; // identify the message being viewed in case they are needed // sqgetGlobalVar('passed_ent_id', $passed_ent_id, SQ_FORM); if (sqGetGlobalVar('passed_id', $passed_id, SQ_FORM)) // fix for Dovecot UIDs can be bigger than normal integers $passed_id = (preg_match('/^[0-9]+$/', $passed_id) ? $passed_id : '0'); // this retrieves the message's From header in the format // array(0 => 'From:', 1 => '"Jose" ') // $from = sb_get_message_header($passed_id, $passed_ent_id, 'From'); // this parses out just the email address portion of the From header // if (function_exists('parseRFC822Address')) { $from = parseRFC822Address($from[1], 1); $from = $from[0][2] . '@' . $from[0][3]; } else { $from = parseAddress($from[1], 1); $from = $from[0][0]; } } // in this case, SquirrelMail is building the buttons in the // message view screen's button row (SquirrelMail 1.5.2+ only) // else if ($hook_name == 'template_construct_read_menubar_buttons.tpl') { // NOTE: at some point, 1.5.x is likely to change the API for the buttons on the read message screen, then this code will have to change to suit $action = 'MESSAGE_VIEW_BUTTON'; if (!isset($button_info[2])) $error = sprintf(_("Spam Buttons plugin is not configured correctly! Check custom button configuration array for \"%s\""), $button_name); else $callback = $button_info[2]; // these values identify the message being viewed // in case you need them // sqgetGlobalVar('passed_ent_id', $passed_ent_id, SQ_FORM); if (sqGetGlobalVar('passed_id', $passed_id, SQ_FORM)) // fix for Dovecot UIDs can be bigger than normal integers $passed_id = (preg_match('/^[0-9]+$/', $passed_id) ? $passed_id : '0'); // this retrieves the message's From header in the format // array(0 => 'From:', 1 => '"Jose" ') // $from = sb_get_message_header($passed_id, $passed_ent_id, 'From'); // this parses out just the email address portion of the From header // if (function_exists('parseRFC822Address')) { $from = parseRFC822Address($from[1], 1); $from = $from[0][2] . '@' . $from[0][3]; } else { $from = parseAddress($from[1], 1); $from = $from[0][0]; } } // is the button always to be shown, or never to be shown? // if (empty($error)) { if ($callback === 1 || $callback === '1') { sq_change_text_domain('squirrelmail'); return TRUE; } if ($callback === 0 || $callback === '0') { sq_change_text_domain('squirrelmail'); return FALSE; } } // otherwise, execute callback to figure it out... // if (empty($callback)) $error = sprintf(_("Spam Buttons plugin is not configured correctly! Check custom button configuration array for \"%s\""), $button_name); else if (!function_exists($callback)) $error = sprintf(_("Function \"%s\" not found in Spam Buttons plugin"), $callback); else $show_it = $callback($action, $username, $from, $passed_id, $passed_ent_id); // error? // if (!empty($error)) { global $color; sq_change_text_domain('squirrelmail'); $ret = plain_error_message($error, $color); if (check_sm_version (1, 5, 2)) { echo $ret; global $oTemplate; $oTemplate->display('footer.tpl'); } exit; } // return value from the callback // sq_change_text_domain('squirrelmail'); return $show_it; } spam_buttons/make_release.sh0000744000000000000000000001274511203037126015250 0ustar rootroot#!/bin/sh # Generic shell script for building SquirrelMail plugin release # # Copyright (c) 2004-2009 Paul Lesniewski # Licensed under the GNU GPL. For full terms see the file COPYING. # ####################################################### # # CONFIGURATION # # Relative paths to any and all configuration files # for this plugin: these files will NOT be included # in the release package built by this script; they # should be given as relative paths and filenames from # the plugin's own directory - for example, if you # have a config.php file in the main plugin directory # and a special_config.php file in a "data" subdirectory, # this should be set as follows: # # CONFIG_FILES=( config.php data/special_config.php ) # # Note that you can also use this setting to exclude # entire subdirectories while creating the release # package. Here is an example that skips any files # inside a subdirectory called "cache_files" and # completely removes a subdirectory called "tmp", as # well as the standard config.php file: # # CONFIG_FILES=( config.php tmp cache_files/* ) # # CONFIG_FILES=( config.php ) # # END CONFIGURATION # ####################################################### # avoid all kinds of potential problems; only allow # this to be run from directory where it resides # if [ "$0" != "./make_release.sh" ]; then echo echo "Please do not run from remote directory" echo exit 1 fi # grab name of package being built from directory name # # PACKAGE=`echo "$PWD" | sed s/.*\\\///` # get "pretty name" from version file # if [ ! -e version ]; then echo echo "No version file found. Please create before making release" echo exit 2 fi PRETTY_NAME=`head -1 version` # announce ourselves # echo echo "Creating Release Package for $PRETTY_NAME" echo # grab old version number straight from the php code # OLD_VERSION=`echo "" | php -q` REQ_SM_VERSION=`echo "" | php -q` # check for the standard files... # if [ ! -e README ]; then echo echo "No README file found. Please create before making release" echo exit 3 fi if [ ! -e docs/README ]; then echo echo "No docs/README file found. Please create before making release" echo exit 3 fi if [ ! -e docs/INSTALL ]; then echo echo "No docs/INSTALL file found. Please create before making release" echo exit 4 fi if [ ! -e getpot ]; then echo echo "No getpot file found. Please create before making release" echo exit 5 fi if [ ! -e $PACKAGE.pot ]; then echo echo "No $PACKAGE.pot file found. Please create before making release" echo exit 5 fi # just copy index.php and COPYING automatically if not found # if [ ! -e docs/COPYING ]; then echo "No docs/COPYING file found. Grabbing one from ../../" cp ../../COPYING ./docs/ fi if [ ! -e index.php ]; then echo "No index.php file found. Grabbing one from ../" cp ../index.php . fi if [ ! -e docs/index.php ]; then echo "No docs/index.php file found. Grabbing one from ../" cp ../index.php ./docs/ fi # Make our own docs/.htaccess if needed # if [ ! -e docs/.htaccess ]; then echo "No docs/.htaccess file found. Creating..." echo "Deny from All" > ./docs/.htaccess fi # remove any previous tarballs # while test 1; do echo echo -n "Remove all .tar.gz files? (y/[n]): " read REPLY if test -z $REPLY; then REPLY="n" break fi if test $REPLY = "y"; then break fi if test $REPLY = "n"; then break fi done if [ "$REPLY" = "y" ]; then rm -f *.tar.gz fi # get new version number if needed # if [ ! -z "$REQ_SM_VERSION" ] ; then OLD_FULL_VERSION=$OLD_VERSION-$REQ_SM_VERSION else OLD_FULL_VERSION=$OLD_VERSION fi echo read -p "Enter Version Number [$OLD_VERSION]: " VERSION if [ -z "$VERSION" ] ; then VERSION=$OLD_VERSION; # VERSION=$OLD_FULL_VERSION; fi PURE_VERSION=`echo "$VERSION" | sed 's/-.*//'` if [ ! -z "$REQ_SM_VERSION" ] ; then FINAL_VERSION="$PURE_VERSION-$REQ_SM_VERSION" else FINAL_VERSION="$PURE_VERSION" fi # remove tarball we are building if present # echo echo "Removing $PACKAGE-$FINAL_VERSION.tar.gz" rm -f $PACKAGE-$FINAL_VERSION.tar.gz # replace version number in info function in setup.php # NOTE that this requires specific syntax in setup.php # for the _info() function which should be # a line that looks like: # 'version' => '', # if test -e setup.php; then echo "Replacing version in setup.php (info function)" sed -e "s/'version' => '$OLD_VERSION',/'version' => '$PURE_VERSION',/" setup.php > setup.php.tmp mv setup.php.tmp setup.php fi # update version number in version file too # echo "Replacing version in version file" echo "$PRETTY_NAME" > version echo $PURE_VERSION >> version # Build tar command; exclude config and other irrelevant files # TAR_COMMAND="tar -c -z -v --exclude CVS" J=0 while [ "$J" -lt ${#CONFIG_FILES[@]} ]; do echo "Excluding ${CONFIG_FILES[$J]}" TAR_COMMAND="$TAR_COMMAND --exclude ${CONFIG_FILES[$J]}" J=`expr $J + 1` done TAR_COMMAND="$TAR_COMMAND -f $PACKAGE-$FINAL_VERSION.tar.gz $PACKAGE" # make tarball # echo "Creating $PACKAGE-$FINAL_VERSION.tar.gz" cd ../ $TAR_COMMAND mv $PACKAGE-$FINAL_VERSION.tar.gz $PACKAGE cd $PACKAGE echo echo "Finished" echo spam_buttons/bounce_identity.php0000644000000000000000000000402211127347127016172 0ustar rootroot, * Licensed under the GNU GPL. For full terms see the file COPYING. * * @package plugins * @subpackage spam_buttons * * This file is originally based on the Bounce plugin by Seth E. * Randall, updated by Paul Lesniewski for the Spam Buttons plugin. * */ // identity.php was added in SquirrelMail 1.4.2 // if (!file_exists(SM_PATH . 'functions/identity.php')) { include_once(SM_PATH . 'include/load_prefs.php'); // ripped from functions/identity.php from 1.4.11SVN on 2007/09/11 // function get_identities() { global $username, $data_dir, $domain; $em = getPref($data_dir,$username,'email_address'); if ( ! $em ) { if (strpos($username , '@') == false) { $em = $username.'@'.$domain; } else { $em = $username; } } $identities = array(); /* We always have this one, even if the user doesn't use multiple identities */ $identities[] = array('full_name' => getPref($data_dir,$username,'full_name'), 'email_address' => $em, 'reply_to' => getPref($data_dir,$username,'reply_to'), 'signature' => getSig($data_dir,$username,'g'), 'index' => 0 ); $num_ids = getPref($data_dir,$username,'identities'); /* If there are any others, add them to the array */ if (!empty($num_ids) && $num_ids > 1) { for ($i=1;$i<$num_ids;$i++) { $identities[] = array('full_name' => getPref($data_dir,$username,'full_name' . $i), 'email_address' => getPref($data_dir,$username,'email_address' . $i), 'reply_to' => getPref($data_dir,$username,'reply_to' . $i), 'signature' => getSig($data_dir,$username,$i), 'index' => $i ); } } return $identities; } } else { include_once(SM_PATH . 'functions/identity.php'); }