1<?php 2 3/** 4 * SquirrelMail Spam Buttons Plugin 5 * Copyright (c) 2005-2009 Paul Lesniewski <paul@squirrelmail.org>, 6 * Licensed under the GNU GPL. For full terms see the file COPYING. 7 * 8 * @package plugins 9 * @subpackage spam_buttons 10 * 11 * See below, starting with "GENERAL OPTIONS" for the beginning 12 * of the configuration section. 13 * 14 */ 15 16global $show_spam_buttons_on_read_body, $show_spam_buttons_on_message_list, 17 $show_spam_link_on_read_body, $is_spam_shell_command, $is_spam_resend_destination, 18 $is_not_spam_shell_command, $is_not_spam_resend_destination, 19 $show_not_spam_button, $spam_button_text, $not_spam_button_text, 20 $spam_report_email_method, $is_spam_subject_prefix, $is_not_spam_subject_prefix, 21 $show_is_spam_button, $spam_report_smtpServerAddress, $spam_report_smtpPort, 22 $spam_report_useSendmail, $spam_report_smtp_auth_mech, $spam_report_use_smtp_tls, 23 $sb_debug, $sb_reselect_messages, $sb_reselect_messages_allow_override, 24 $sb_delete_after_report, $sb_delete_after_report_allow_override, 25 $sb_move_after_report_spam, $sb_move_after_report_spam_allow_override, 26 $sb_move_after_report_not_spam, $sb_move_after_report_not_spam_allow_override, 27 $sb_report_spam_by_move_to_folder, $sb_report_not_spam_by_move_to_folder, 28 $sb_copy_after_report_spam_allow_override, $sb_copy_after_report_spam, 29 $sb_copy_after_report_not_spam_allow_override, $sb_copy_after_report_not_spam, 30 $sb_report_spam_by_copy_to_folder, $sb_report_not_spam_by_copy_to_folder, 31 $sb_suppress_spam_button_folder, $sb_suppress_not_spam_button_folder, 32 $sb_suppress_spam_button_folder_allow_override, $is_spam_keep_copy_in_sent, 33 $sb_suppress_not_spam_button_folder_allow_override, 34 $sb_spam_header_name, $sb_not_spam_header_name, $extra_buttons, 35 $sb_spam_header_value, $sb_not_spam_header_value, $is_not_spam_keep_copy_in_sent, 36 $sb_show_spam_button_folder, $sb_show_spam_button_folder_allow_override, 37 $sb_show_not_spam_button_folder, $sb_show_not_spam_button_folder_allow_override, 38 $reported_spam_text, $reported_not_spam_text, 39 $sb_move_to_other_message_after_report, $sb_auto_create_destination_folder, 40 $sb_move_to_other_message_after_report_allow_override, 41 $sb_report_spam_by_custom_function, $sb_report_not_spam_by_custom_function; 42 43 44 45// ------------------------------------------------------------------- 46// 47// GENERAL OPTIONS 48// 49 50 51// You may change the button text, but if you do, there is a good 52// chance that those buttons will ONLY be displayed in one language 53// (unless you add your own translations to your locale files) 54// (however, the text "Report Spam" will be translated if you use 55// that) 56// 57// $spam_button_text = 'Report Spam'; 58$spam_button_text = 'Spam'; 59$not_spam_button_text = 'Not Spam'; 60 61 62 63// You may change the report confirmation text, but if you do, there 64// is a good chance that those buttons will ONLY be displayed in one 65// language (unless you add your own translations to your locale files) 66// 67$reported_spam_text = 'Successfully reported as spam'; 68$reported_not_spam_text = 'Successfully reported as non-spam'; 69 70 71 72// You can turn either of the buttons on/off as needed 73// 74// 0 = don't display button, 1 = display button 75// 76$show_not_spam_button = 1; 77$show_is_spam_button = 1; 78 79 80 81// Show spam buttons on message list page? 82// 83// 0 = no, 1 = yes 84// 85$show_spam_buttons_on_message_list = 1; 86 87 88 89// Show spam link when reading a message? 90// 91// 0 = no, 1 = yes 92// 93$show_spam_link_on_read_body = 1; 94 95 96 97// Show spam buttons when reading a message? 98// 99// NOTE: This is only functional as of 100// SquirrelMail 1.5.0 101// 102// 0 = no, 1 = yes 103// 104$show_spam_buttons_on_read_body = 1; 105 106 107 108// When viewing an individual message, this plugin can determine if 109// it was tagged as spam or ham by your anti-spam scanner if a certain 110// header ($sb_spam_header_name) is added to the message. By comparing 111// the value of that header to what is configured here 112// ($sb_spam_header_value), this plugin can display only the HAM (not 113// spam) button on messages marked as spam, or the SPAM button on messages 114// marked as ham (not spam), or both buttons otherwise. 115// 116// When in use, this functionality will override 117// $sb_suppress_spam_button_folder, $sb_suppress_not_spam_button_folder 118// $sb_show_spam_button_folder and $sb_show_not_spam_button_folder 119// (buttons/links displayed in the read-message screen will be based on 120// the message headers and NOT what folder the message is in). 121// 122// Note that $sb_spam_header_name and $sb_not_spam_header_name are usually 123// the same thing in most spam scanner systems. 124// 125// The values for $sb_spam_header_value and $sb_not_spam_header_value 126// are regular expressions that will be used to compare the actual 127// message header values. 128// 129// $sb_spam_header_name = 'X-Spam-Status'; 130// $sb_spam_header_value = '/^Yes/i'; 131// $sb_not_spam_header_name = 'X-Spam-Status'; 132// $sb_not_spam_header_value = '/^No/i'; 133// 134$sb_spam_header_name = ''; 135$sb_spam_header_value = ''; 136$sb_not_spam_header_name = ''; 137$sb_not_spam_header_value = ''; 138 139 140 141// When any one of the report-by-move/copy or move/copy-after-report 142// options is set to a folder that does not exist for any one user, 143// should it be created automatically? If not, an error will occur 144// when the user reports spam/ham. 145// 146// 0 = don't create folders automatically 147// 1 = create folders if they do not exist upon spam/ham report 148// 149$sb_auto_create_destination_folder = 0; 150 151 152 153// Debugging: Turning this on will dump out the command text, the 154// message body and the results of the spam report if 155// done using a shell command. 156// If reported via email (attachment method only), you 157// currently only get the destination address and a 158// parsed version of the message body being reported. 159// 160// Note that you will get more verbose output from a sa-learn 161// command if you add the -D flag to the commands below (make sure 162// to remove it when you are done debugging!). 163// 164// 0 = off, 1 = on 165// 166$sb_debug = 0; 167 168 169 170// ------------------------------------------------------------------- 171// 172// BUTTON/LINK SUPPRESSION OPTIONS 173// 174 175 176// When the user is in this folder (or folders), suppress 177// all SPAM button/links 178// 179// Set to an empty list to show the spam button in all folders, 180// or the exact name of the specified spam folder(s) (the format 181// of which may depend on your IMAP server). 182// 183// In the case of collision with $sb_show_spam_button_folder 184// (see below), this setting will lose. 185// 186// $sb_suppress_spam_button_folder = array('INBOX.Spam'); 187// $sb_suppress_spam_button_folder = array('INBOX.Spam', 'INBOX.Junk'); 188// 189$sb_suppress_spam_button_folder = array(); 190 191 192 193// Should users be able to choose what the value 194// of $sb_suppress_spam_button_folder is? Set to 1 195// if so, or set to 0 (zero) if the administrator's 196// setting above goes for all users. 197// 198$sb_suppress_spam_button_folder_allow_override = 1; 199 200 201 202// When the user is in this folder (or folders), suppress 203// all HAM (not spam) button/links 204// 205// Set to an empty list to show the ham button in all folders, 206// or the exact name of the specified ham folder(s) (the format 207// of which may depend on your IMAP server). 208// 209// In the case of collision with $sb_show_not_spam_button_folder 210// (see below), this setting will lose. 211// 212// $sb_suppress_not_spam_button_folder = array('INBOX.Ham'); 213// $sb_suppress_not_spam_button_folder = array('INBOX.Ham', 'INBOX.Personal'); 214// 215$sb_suppress_not_spam_button_folder = array(); 216 217 218 219// Should users be able to choose what the value 220// of $sb_suppress_not_spam_button_folder is? Set to 1 221// if so, or set to 0 (zero) if the administrator's 222// setting above goes for all users. 223// 224$sb_suppress_not_spam_button_folder_allow_override = 0; 225 226 227 228// ------------------------------------------------------------------- 229// 230// BUTTON/LINK INCLUSION OPTIONS 231// 232 233 234// Only when the user is in this folder (or folders), 235// show SPAM button/links 236// 237// When this option is set to anything other than an 238// empty list, spam buttons/links won't be shown in 239// any folder other than the one(s) specified here. 240// 241// In the case of collision with 242// $sb_suppress_spam_button_folder, this setting will win. 243// 244// If set, this value must contain the exact name(s) 245// of the specified folder(s) (the format of which 246// may depend on your IMAP server). 247// 248// $sb_show_spam_button_folder = array('INBOX.Ham'); 249// $sb_show_spam_button_folder = array('INBOX.Ham', 'INBOX.Personal'); 250// 251$sb_show_spam_button_folder = array(); 252 253 254 255// Should users be able to choose what the value 256// of $sb_show_spam_button_folder is? Set to 1 257// if so, or set to 0 (zero) if the administrator's 258// setting above goes for all users. 259// 260$sb_show_spam_button_folder_allow_override = 0; 261 262 263 264// Only when the user is in this folder (or folders), 265// show HAM (not spam) button/links 266// 267// When this option is set to anything other than an 268// empty list, ham buttons/links won't be shown in 269// any folder other than the one(s) specified here. 270// 271// In the case of collision with 272// $sb_suppress_not_spam_button_folder, this setting will win. 273// 274// If set, this value must contain the exact name(s) 275// of the specified folder(s) (the format of which 276// may depend on your IMAP server). 277// 278// $sb_show_not_spam_button_folder = array('INBOX.Spam'); 279// $sb_show_not_spam_button_folder = array('INBOX.Spam', 'INBOX.Junk'); 280// 281$sb_show_not_spam_button_folder = array(); 282 283 284 285// Should users be able to choose what the value 286// of $sb_show_not_spam_button_folder is? Set to 1 287// if so, or set to 0 (zero) if the administrator's 288// setting above goes for all users. 289// 290$sb_show_not_spam_button_folder_allow_override = 1; 291 292 293 294// ------------------------------------------------------------------- 295// 296// POST-REPORT OPTIONS 297// 298 299 300// When reporting spam (NOT ham), should messages 301// be deleted afterward? 302// 303// NOTE that this will be ignored if $sb_move_after_report_spam 304// (or the user-overridden value for such) is turned on. 305// 306// NOTE that when using the move-to-folder type 307// reporting method, this feature will be disabled. 308// 309// 0 = no, 1 = yes 310// 311$sb_delete_after_report = 0; 312 313 314 315// Should users be able to choose what the value 316// of $sb_delete_after_report is? Set to 1 if so, 317// or set to 0 (zero) if the administrator's 318// setting above goes for all users. 319// 320$sb_delete_after_report_allow_override = 1; 321 322 323 324// When reporting spam, should messages be moved 325// to another folder afterward? 326// 327// Set to an empty string to disable, or the exact 328// name of the target folder (the format of which 329// may depend on your IMAP server). 330// 331// NOTE that this will take precedence over 332// $sb_delete_after_report. 333// 334// NOTE that when using the move-to-folder type 335// reporting method, this feature will be disabled. 336// 337// $sb_move_after_report_spam = 'INBOX.Spam'; 338// 339$sb_move_after_report_spam = ''; 340 341 342 343// Should users be able to choose what the value 344// of $sb_move_after_report_spam is? Set to 1 if so, 345// or set to 0 (zero) if the administrator's 346// setting above goes for all users. 347// 348$sb_move_after_report_spam_allow_override = 1; 349 350 351 352// Should $sb_move_after_report_spam COPY reported 353// messages instead of moving them? 354// 355// 0 = no, just move messages, 1 = yes, copy messages 356// 357// This setting has no effect when 358// $sb_move_after_report_spam is not enabled. 359// 360$sb_copy_after_report_spam = 0; 361 362 363 364// Should users be able to choose what the value 365// of $sb_copy_after_report_spam is? Set to 1 if so, 366// or set to 0 (zero) if the administrator's 367// setting above goes for all users. 368// 369$sb_copy_after_report_spam_allow_override = 1; 370 371 372 373// When reporting non-spam, should messages be moved 374// to another folder afterward? 375// 376// Set to an empty string to disable, or the exact 377// name of the target folder (the format of which 378// may depend on your IMAP server). 379// 380// NOTE that when using the move-to-folder type 381// reporting method, this feature will be disabled. 382// 383// $sb_move_after_report_not_spam = 'INBOX.Ham'; 384// 385$sb_move_after_report_not_spam = ''; 386 387 388 389// Should users be able to choose what the value 390// of $sb_move_after_report_not_spam is? Set to 1 if so, 391// or set to 0 (zero) if the administrator's 392// setting above goes for all users. 393// 394$sb_move_after_report_not_spam_allow_override = 1; 395 396 397 398// Should $sb_move_after_report_not_spam COPY reported 399// messages instead of moving them? 400// 401// 0 = no, just move messages, 1 = yes, copy messages 402// 403// This setting has no effect when 404// $sb_move_after_report_not_spam is not enabled. 405// 406$sb_copy_after_report_not_spam = 0; 407 408 409 410// Should users be able to choose what the value 411// of $sb_copy_after_report_not_spam is? Set to 1 if so, 412// or set to 0 (zero) if the administrator's 413// setting above goes for all users. 414// 415$sb_copy_after_report_not_spam_allow_override = 1; 416 417 418 419// When selecting messages to report from the 420// message list page, the messages will be re- 421// selected after they are reported (as of 422// SquirrelMail 1.4.11 and 1.5.2). You can turn 423// this functionality off by setting this to zero. 424// 425$sb_reselect_messages = 1; 426 427 428 429// Should users be able to choose what the value 430// of $sb_reselect_messages is? Set to 1 if so, 431// or set to 0 (zero) if the administrator's 432// setting above goes for all users. 433// 434$sb_reselect_messages_allow_override = 1; 435 436 437 438// When either report-by-move or delete-after-report is 439// enabled, should the user be directed to the next or 440// previous message after the report, or just back to 441// the message list? 442// 443// Acceptable values are "next", "previous" and "" (empty), 444// which indicates that the user will be returned to the 445// message list. 446// 447// $sb_move_to_other_message_after_report = 'next'; 448// $sb_move_to_other_message_after_report = 'previous'; 449// $sb_move_to_other_message_after_report = ''; 450// 451$sb_move_to_other_message_after_report = ''; 452 453 454 455// Should users be able to choose what the value 456// of $sb_move_to_other_message_after_report is? 457// Set to 1 if so, or set to 0 (zero) if the 458// administrator's setting above goes for all users. 459// 460$sb_move_to_other_message_after_report_allow_override = 1; 461 462 463 464// ------------------------------------------------------------------- 465// 466// REPORT BY MOVE-TO-FOLDER OPTIONS 467// 468// Be sure if you use this that you have NOT turned on 469// reporting by email, by shell command or by custom function. 470// 471 472 473// This reporting method does not acutually make any reports itself. 474// Instead, the message is moved to the specified folder and some 475// other process is assumed to examine the messages in that folder 476// on a regular basis. 477// 478// If you enable this reporting method, the report-and-delete and 479// report-and-move functions above will be automatically disabled. 480// 481// You will need to set these values to the exact name of the target 482// folders where messages will be moved. The format of the folder 483// names may depend on your IMAP server. 484// 485// $sb_report_spam_by_move_to_folder = 'INBOX.Spam'; 486// $sb_report_not_spam_by_move_to_folder = 'INBOX.Ham'; 487// 488$sb_report_spam_by_move_to_folder = ''; 489$sb_report_not_spam_by_move_to_folder = ''; 490 491 492 493// If messages should be copied instead of moved, set either of these 494// settings to 1. Leave as 0 (zero) if messages should be moved. 495// 496// Note that these settings have no effect if their counterparts 497// above are not enabled. 498// 499$sb_report_spam_by_copy_to_folder = 0; 500$sb_report_not_spam_by_copy_to_folder = 0; 501 502 503 504// ------------------------------------------------------------------- 505// 506// REPORT-BY-SHELL COMMAND OPTIONS 507// 508// Be sure if you use this that you have NOT turned on 509// reporting by email, by move-to-folder or by custom function. 510// 511 512 513// If you use a command-line utility for reporting spam/non-spam, 514// this is where you set it up. This plugin will append " < message" 515// to the end of such a command (without the quotes), where "message" 516// will be a file containing the full message as it was originally 517// received. 518// 519// If you need to include any information about the user for which 520// the report is being made, you can use these constants in your command: 521// 522// ###EMAIL_PREF### Will be replaced with the user's 523// main email address preference 524// setting (under Options -> Personal 525// Information) (email addresses under 526// Multiple Identiies not supported) 527// 528// ###EMAIL_ADDRESS### Will be replaced with the user's 529// full email address (based on the 530// login username and user's domain) 531// 532// ###USERNAME### Will be replaced with the username 533// portion of the user's email address 534// 535// ###DOMAIN### Will be replaced with the domain 536// portion of the user's email address 537// 538// 539// 540// Note that you are not necessarily limited to just calling a spam 541// reporting application; you can also do clever things such as dump 542// the message to a file that can be used to do cron-based reporting 543// at a later time. For example: 544// 545// $is_spam_shell_command = 'cat >> /path/to/spam-###EMAIL_ADDRESS###'; 546// $is_not_spam_shell_command = 'cat >> /path/to/ham-###EMAIL_ADDRESS###'; 547// 548// 549// 550// Sample for Bogofilter: 551// 552// $is_spam_shell_command = 'HOME=/home/###USERNAME### sudo -u ###USERNAME### /usr/bin/bogofilter -s'; 553// $is_not_spam_shell_command = 'HOME=/home/###USERNAME### sudo -u ###USERNAME### /usr/bin/bogofilter -n'; 554// 555// 556// 557// Sample for CRM114: 558// 559// $is_spam_shell_command = '/usr/bin/crm -u /home/crm114 mailfilter.crm --learnspam'; 560// $is_not_spam_shell_command = '/usr/bin/crm -u /home/crm114 mailfilter.crm --learnnonspam'; 561// 562// 563// 564// Sample for DSPAM: 565// 566// $is_spam_shell_command = '/usr/local/bin/dspam --user ###EMAIL_ADDRESS### --mode=teft --class=spam --source=error --client'; 567// $is_not_spam_shell_command = '/usr/local/bin/dspam --user ###EMAIL_ADDRESS### --mode=teft --class=innocent --source=error --client'; 568// 569// 570// 571// Sample for SpamAssassin: 572// 573// $is_spam_shell_command = '/usr/bin/sa-learn --spam --configpath=/etc/spamassassin -p /root/.spamassassin/user_prefs'; 574// $is_not_spam_shell_command = '/usr/bin/sa-learn --ham --configpath=/etc/spamassassin -p /root/.spamassassin/user_prefs'; 575// 576// 577// 578// Sample for SpamAssassin per-user configuration: 579// 580// $is_spam_shell_command = '/usr/bin/sa-learn --spam --username=###EMAIL_ADDRESS###'; 581// $is_not_spam_shell_command = '/usr/bin/sa-learn --ham --username=###EMAIL_ADDRESS###'; 582// 583// 584// 585// Sample for SpamAssassin per-user configuration using spamc/spamd: 586// 587// $is_spam_shell_command = '/usr/bin/spamc -L spam -d localhost -u ###EMAIL_ADDRESS###'; 588// $is_not_spam_shell_command = '/usr/bin/spamc -L ham -d localhost -u ###EMAIL_ADDRESS###'; 589// 590// 591// 592// Advanced sample for SpamAssassin: 593// 594// In order to make sure you are running sa-learn (or equivalent) as the correct user 595// (else it will be run as the user that your web server runs as), you may need to run 596// the command with sudo. In /etc/sudoers, you will want to set this: 597// 598// web_server_user ALL=(sa_user) NOPASSWD: /usr/bin/sa-learn, /usr/bin/spamassassin, /usr/bin/spamc 599// 600// Where you need to change "web_server_user" to the actual userID of the user running 601// your web server, and "sa_user" to the user that should run sa-learn (or spamassasin 602// or spamc). 603// 604// After that, one of the following command pairs should work for you (remember to 605// replace "sa_user" with the correct username): 606// 607// $is_spam_shell_command = 'sudo -u sa_user /usr/bin/sa-learn --spam'; 608// $is_not_spam_shell_command = 'sudo -u sa_user /usr/bin/sa-learn --ham'; 609// 610// $is_spam_shell_command = 'sudo -u sa_user /usr/bin/spamassassin -r --configpath=/etc/spamassassin -p /root/.spamassassin/user_prefs'; 611// $is_not_spam_shell_command = 'sudo -u sa_user /usr/bin/spamassassin -k --configpath=/etc/spamassassin -p /root/.spamassassin/user_prefs'; 612// 613// $is_spam_shell_command = 'sudo -u sa_user /usr/bin/spamc -L spam'; 614// $is_not_spam_shell_command = 'sudo -u sa_user /usr/bin/spamc -L ham'; 615// 616// 617// 618$is_spam_shell_command = ''; 619$is_not_spam_shell_command = ''; 620 621 622 623// ------------------------------------------------------------------- 624// 625// REPORT-BY-EMAIL OPTIONS 626// 627// Be sure if you use this that you have NOT turned on reporting 628// by shell command, by move-to-folder or by custom function. 629// 630 631 632// If you resend the message in order to report it as spam/non-spam, 633// specify the destination address here. 634// 635// If you need to include any information about the user for which 636// the report is being made, you can use these constants in the 637// destination address: 638// 639// ###EMAIL_PREF### Will be replaced with the user's 640// main email address preference 641// setting (under Options -> Personal 642// Information) (email addresses under 643// Multiple Identiies not supported) 644// 645// ###EMAIL_ADDRESS### Will be replaced with the user's 646// full email address (based on the 647// login username and user's domain) 648// 649// ###USERNAME### Will be replaced with the username 650// portion of the user's email address 651// 652// ###DOMAIN### Will be replaced with the domain 653// portion of the user's email address 654// 655// 656// $is_spam_resend_destination = 'spam_report'; // let SM append user's domain automatically 657// $is_not_spam_resend_destination = 'not_spam_report'; 658// 659// $is_spam_resend_destination = 'spam-###USERNAME###@###DOMAIN###'; 660// $is_not_spam_resend_destination = 'ham-###USERNAME###@###DOMAIN###'; 661// 662$is_spam_resend_destination = ''; 663$is_not_spam_resend_destination = ''; 664 665 666 667// When reporting via email, should the message be resent (leaving 668// all message headers intact), or should it be sent as an attachment? 669// 670// resend = 'bounce' 671// attach = 'attachment' 672// 673// $spam_report_email_method = 'bounce'; 674// 675$spam_report_email_method = 'attachment'; 676 677 678 679// When reporting via email by sending as an attachment, 680// should a copy of the spam notification message (with 681// the offending message attachment) be placed in the 682// user's sent folder? 683// 684// 1 = yes, 0 (zero) = no 685// 686$is_spam_keep_copy_in_sent = 0; 687$is_not_spam_keep_copy_in_sent = 0; 688 689 690 691// When reporting via email (at least when sending as attachment), you 692// may indicate any extra subject information here (default empty) 693// 694// When set to "SPAM", the subject might end up looking like "[SPAM: Buy our product!]" 695// 696$is_spam_subject_prefix = 'SPAM'; 697$is_not_spam_subject_prefix = 'HAM'; 698 699 700 701// You may also specify overrides for the SMTP server for the 702// email only (see SquirrelMail's main configuration file or 703// use config/conf.pl to understand what these settings normally 704// are). 705// 706// Set to empty strings to use system defaults. 707// 708$spam_report_smtpServerAddress = ''; 709$spam_report_smtpPort = ''; 710$spam_report_useSendmail = ''; 711$spam_report_smtp_auth_mech = ''; 712$spam_report_use_smtp_tls = ''; 713 714 715 716// ------------------------------------------------------------------- 717// 718// REPORT-BY-CUSTOM-FUNCTION OPTIONS 719// 720// Be sure if you use this that you have NOT turned on 721// reporting by email, by shell command or by move-to-folder. 722// 723 724 725// You must provide any custom PHP function defined here. 726// Each of these functions will be called with two parameters, 727// the first being an array of message ID strings for each 728// of the message(s) being reported (even when there is only 729// one message being reported). The second parameter will 730// usually be zero, but when the message being reported is an 731// attachment to another message, it will be its entity ID 732// within its parent message. 733// 734// The functions must return an empty string when all messages 735// were reported successfully, or an error message string 736// if reporting failed or any other problem occurred. 737// 738// Leave these empty when not using custom PHP callbacks 739// for spam/ham reporting. 740// 741// Sample custom functions that report the spam/ham by adding 742// the sender to a black/white-list are included near the 743// bottom of this file. 744// 745// $sb_report_spam_by_custom_function = 'report_spam_by_blacklist'; 746// $sb_report_not_spam_by_custom_function = 'report_ham_by_whitelist'; 747// 748$sb_report_spam_by_custom_function = ''; 749$sb_report_not_spam_by_custom_function = ''; 750 751 752 753// ------------------------------------------------------------------- 754// 755// EXTRA BUTTONS AND LINKS 756// 757// Any number of additional (custom) buttons or links may 758// be added to the SquirrelMail interface by declaring 759// them and their handlers here. 760// 761 762 763// Define any extra buttons or links here. 764// 765// Each one is keyed by its displayable name - what 766// the user will see in the interface. This text 767// will be passed through SquirrelMail's translation 768// engine, so if you use one of the sample names included 769// in the Spam Buttons translation file, it will be 770// translated into other languages (assuming translation 771// availability). You can also add your own translations 772// as needed for different text values. Currently, these 773// values are included as suggestions: 774// 775// Whitelist 776// Whitelist Sender 777// Blacklist 778// Blacklist Sender 779// 780// For each of these button/link names, a six-element array 781// is needed: 782// 783// The first element determines if the button will show up 784// on the message list screen. It can be set to 1 to 785// indicate that it should always be shown there, 0 (zero) 786// to indicate that it should never be shown there, or the 787// name of a custom callback function that can be used to 788// perform more complex operations to determine if the 789// button should be shown or not. If you define a custom 790// callback function, it will be called with two 791// arguments: first, the string "MESSAGE_LIST_BUTTON" (which 792// indicates that the plugin is asking if the button can be 793// shown on the message list page), and second, the username 794// of the current user who is logged in. The function must 795// then return either TRUE to indicate that the button is 796// to be shown, or FALSE when it should not. 797// 798// The second element determines if the link will show up 799// on the message view screen. It can be set to 1 to 800// indicate that it should always be shown there, 0 (zero) 801// to indicate that it should never be shown there, or the 802// name of a custom callback function that can be used to 803// perform more complex operations to determine if the 804// link should be shown or not. If you define a custom 805// callback function, it will be called with five 806// arguments: first, the string "MESSAGE_VIEW_LINK" (which 807// indicates that the plugin is asking if the link can be 808// shown on the message view page), second, the username 809// of the current user who is logged in, third, the email 810// address of the sender of the message currently being 811// viewed (it is possible to get more information about 812// the message if needed - see the example function below 813// to learn how), fourth, the message ID of the message 814// currently being viewed, and fifth, the message entity ID 815// if the message being viewed is an attachment to another 816// message (if not, it will be empty). The function must 817// then return either TRUE to indicate that the link is to 818// be shown, or FALSE when it should not. 819// 820// The third element determines if the button (as opposed to 821// the link explained above) will show up on the message view 822// screen (only applicable for SquirrelMail 1.5.2+). It can 823// be set to 1 to indicate that it should always be shown 824// there, 0 (zero) to indicate that it should never be shown 825// there, or the name of a custom callback function that can 826// be used to perform more complex operations to determine if 827// the button should be shown or not. If you define a custom 828// callback function, it will be called with five arguments: 829// first, the string "MESSAGE_VIEW_BUTTON" (which indicates 830// that the plugin is asking if the button can be shown on the 831// message view page), second, the username of the current 832// user who is logged in, third, the email address of the 833// sender of the message currently being viewed (it is possible 834// to get more information about the message if needed - see 835// the example function below to learn how) fourth, the message 836// ID of the message currently being viewed, and fifth, the 837// message entity ID if the message being viewed is an 838// attachment to another message (if not, it will be empty). 839// The function must then return either TRUE to indicate that 840// the button is to be shown, or FALSE when it should not. 841// 842// The fourth element is the name of the callback function 843// that will handle the requested action when this button 844// or link is clicked by the user. You must define this 845// function yourself (see below for an example). When called, 846// it is given five arguments, the first of which is the name 847// of the button that was clicked, although if your button names 848// have any non-alphanumeric characters in them (such as dashes, 849// spaces, etc.), those will be converted to underscores. The 850// second argument is the username of the user who is currently 851// logged in. The third argument is the email address of the 852// sender of the message that is being processed (it is possible 853// to get more information about the message if needed - see the 854// example function below to learn how). The fourth argument is 855// the message ID for the message that needs to be processed. 856// The fifth parameter is the message entity ID if the message 857// being processed is an attachment to another message (if not, 858// it will be empty). The function must then return either a 859// boolean (TRUE/FALSE) success indicator *OR* an array with two 860// elements. When using an array return value, the first element 861// is a boolean value that is TRUE if the message was processed 862// normally and FALSE if some error occured. The second element 863// is a string containing a note that will be displayed to the 864// user upon completion. Note that this message will be ignored 865// pending the following: 866// 867// The fifth and sixth elements are text strings that contain 868// the messages that will be displayed to the user upon 869// successful (but not failed) execution of a button or link 870// click. The fifth element is the message used when only one 871// message has been processed, and the sixth is the message used 872// when more than one message has been processed (this presumes 873// Germanic plurality rules, but these strings will be used with 874// ngettext(), so translators can correctly use their language's 875// native plurality rules) You may leave these blank and the 876// message returned by the callback function defined just above 877// will be used instead. This text will be passed through 878// SquirrelMail's translation engine, so if you use sample messages 879// included in the Spam Buttons translation file, it will be 880// translated into other languages (assuming translation 881// availability). You can also add your own translations as 882// needed for different message values. Currently, these messages 883// are included as suggestions: 884// 885// Sender has been blacklisted 886// Senders have been blacklisted 887// Sender has been whitelisted 888// Senders have been whitelisted 889// 890// $extra_buttons = array('Blacklist' => array(1, 891// 'is_not_blacklisted', // see below 892// 0, 893// 'blacklist', // see below 894// 'Sender has been blacklisted', 895// 'Senders have been blacklisted'), 896// 'Whitelist' => array(1, 897// 'is_not_whitelisted', // see below 898// 0, 899// 'whitelist', // see below 900// 'Sender has been whitelisted', 901// 'Senders have been whitelisted')); 902// 903$extra_buttons = array(); 904 905 906 907/** 908 * Example custom button test function 909 * 910 * Determines if the current user has not yet whitelisted the given sender. 911 * 912 * Implementation is left to your imagination. 913 * 914 * @param string $action A string indicating what button or link 915 * is being created ("MESSAGE_LIST_BUTTON", 916 * "MESSAGE_VIEW_LINK", or 917 * "MESSAGE_VIEW_BUTTON"). 918 * @param string $user The user whose whitelist we should check. 919 * @param string $sender The sender to check for (will be empty 920 * when $action is "MESSAGE_LIST_BUTTON"). 921 * @param string $message_id The ID of the message currently being 922 * viewed, if any (will be empty when 923 * $action is "MESSAGE_LIST_BUTTON"). 924 * @param string $entity_id The entity ID of the message currently 925 * being viewed when it is an attachment 926 * to another message, if any (will be 927 * empty when it is not an attachment, or 928 * when $action is "MESSAGE_LIST_BUTTON"). 929 * 930 * @return boolean TRUE if the sender has NOT been whitelisted, 931 * FALSE otherwise. 932 * 933 */ 934function is_not_whitelisted($action, $user, $sender, $message_id, $entity_id) 935{ 936 937 // you need to supply the functionality herein 938 // 939 return TRUE; 940 941 942 // here is how you can use the Server Settings plugin 943 // to ask it about a value on the server (assumes 944 // you have a setting called "whitelist" that is 945 // correctly configured therein) 946 // 947 include_once(SM_PATH . 'plugins/server_settings/functions.php'); 948 return !server_settings_test_value('whitelist', $sender); 949 950 951 // here is how you can retrieve additional headers from 952 // the current message, in case you need them... 953 // 954 // this retrieves the message's Subject header in the format 955 // array(0 => 'Subject:', 1 => 'This is my message subject') 956 // 957 $subject = ''; 958 if (!empty($message_id)) 959 $subject = sb_get_message_header($message_id, $entity_id, 'Subject'); 960 961} 962 963 964 965/** 966 * Example custom button test function 967 * 968 * Determines if the current user has not yet blacklisted the given sender. 969 * 970 * Implementation is left to your imagination. 971 * 972 * @param string $action A string indicating what button or link 973 * is being created ("MESSAGE_LIST_BUTTON", 974 * "MESSAGE_VIEW_LINK", or 975 * "MESSAGE_VIEW_BUTTON"). 976 * @param string $user The user whose whitelist we should check. 977 * @param string $sender The sender to check for (will be empty 978 * when $action is "MESSAGE_LIST_BUTTON"). 979 * @param string $message_id The ID of the message currently being 980 * viewed, if any (will be empty when 981 * $action is "MESSAGE_LIST_BUTTON"). 982 * @param string $entity_id The entity ID of the message currently 983 * being viewed when it is an attachment 984 * to another message, if any (will be 985 * empty when it is not an attachment, or 986 * when $action is "MESSAGE_LIST_BUTTON"). 987 * 988 * @return boolean TRUE if the sender has NOT been blacklisted, 989 * FALSE otherwise. 990 * 991 */ 992function is_not_blacklisted($action, $user, $sender, $message_id, $entity_id) 993{ 994 995 // you need to supply the functionality herein 996 // 997 return TRUE; 998 999 1000 // here is how you can use the Server Settings plugin 1001 // to ask it about a value on the server (assumes 1002 // you have a setting called "blacklist" that is 1003 // correctly configured therein) 1004 // 1005 include_once(SM_PATH . 'plugins/server_settings/functions.php'); 1006 return !server_settings_test_value('blacklist', $sender); 1007 1008 1009 // here is how you can retrieve additional headers from 1010 // the current message, in case you need them... 1011 // 1012 // this retrieves the message's Subject header in the format 1013 // array(0 => 'Subject:', 1 => 'This is my message subject') 1014 // 1015 $subject = ''; 1016 if (!empty($message_id)) 1017 $subject = sb_get_message_header($message_id, $entity_id, 'Subject'); 1018 1019} 1020 1021 1022 1023/** 1024 * Example custom button handler function 1025 * 1026 * Whitelist the given sender. 1027 * 1028 * Implementation is left to your imagination. 1029 * 1030 * @param string $button_name The name of the button or link 1031 * (with non-alphanumerics having 1032 * been replaced with underscores). 1033 * @param string $user The user whose whitelist we are adding to. 1034 * @param string $sender The sender to whitelist. 1035 * @param string $message_id The ID of the message currently being 1036 * processed. 1037 * @param string $entity_id The entity ID of the message currently 1038 * being processed when it is an attachment 1039 * to another message (otherwise, it will 1040 * be empty). 1041 * 1042 * @return array A two-element array, the first element being 1043 * a boolean value that is TRUE if the sender was 1044 * added to the whitelist normally and FALSE if 1045 * some error occured. The second element is a 1046 * string containing a note that usually contains 1047 * any error information that should be shown to 1048 * the user when an error occurs. 1049 * 1050 */ 1051function whitelist($button_name, $user, $sender, $message_id, $entity_id) 1052{ 1053 1054 // you need to supply the functionality herein 1055 // 1056 return TRUE; 1057 1058 1059 // if multiple entries into the whitelist is a possilbe problem 1060 // (caused by multiple clicks of a button from the message *list* 1061 // screen), then you make sure the user isn't already listed: 1062 // 1063 if (!is_not_whitelisted('', $user, $sender, $message_id, $entity_id)) 1064 return array(TRUE, ''); 1065 1066 1067 // here is how you can use the Server Settings plugin 1068 // to send the value to the server backend (assumes 1069 // you have a setting called "whitelist" that is 1070 // correctly configured therein) 1071 // 1072 include_once(SM_PATH . 'plugins/server_settings/functions.php'); 1073 if (server_settings_update_value('whitelist', $sender, '', '', TRUE)) 1074 return array(TRUE, ''); 1075 else 1076 return array(FALSE, 'ERROR attempting to whitelist ' . $sender); 1077 1078 1079 // here is how you can retrieve additional headers from 1080 // the current message, in case you need them... 1081 // 1082 // this retrieves the message's Subject header in the format 1083 // array(0 => 'Subject:', 1 => 'This is my message subject') 1084 // 1085 $subject = sb_get_message_header($message_id, $entity_id, 'Subject'); 1086 1087} 1088 1089 1090 1091/** 1092 * Example custom button handler function 1093 * 1094 * Blacklist the given sender. 1095 * 1096 * Implementation is left to your imagination. 1097 * 1098 * @param string $button_name The name of the button or link 1099 * (with non-alphanumerics having 1100 * been replaced with underscores). 1101 * @param string $user The user whose blacklist we are adding to. 1102 * @param string $sender The sender to blacklist. 1103 * @param string $message_id The ID of the message currently being 1104 * processed. 1105 * @param string $entity_id The entity ID of the message currently 1106 * being processed when it is an attachment 1107 * to another message (otherwise, it will 1108 * be empty). 1109 * 1110 * @return array A two-element array, the first element being 1111 * a boolean value that is TRUE if the sender was 1112 * added to the blacklist normally and FALSE if 1113 * some error occured. The second element is a 1114 * string containing a note that usually contains 1115 * any error information that should be shown to 1116 * the user when an error occurs. 1117 * 1118 */ 1119function blacklist($button_name, $user, $sender, $message_id, $entity_id) 1120{ 1121 1122 // you need to supply the functionality herein 1123 // 1124 return TRUE; 1125 1126 1127 // if multiple entries into the blacklist is a possilbe problem 1128 // (caused by multiple clicks of a button from the message *list* 1129 // screen), then you make sure the user isn't already listed: 1130 // 1131 if (!is_not_blacklisted('', $user, $sender, $message_id, $entity_id)) 1132 return array(TRUE, ''); 1133 1134 1135 // here is how you can use the Server Settings plugin 1136 // to send the value to the server backend (assumes 1137 // you have a setting called "blacklist" that is 1138 // correctly configured therein) 1139 // 1140 include_once(SM_PATH . 'plugins/server_settings/functions.php'); 1141 if (server_settings_update_value('blacklist', $sender, '', '', TRUE)) 1142 return array(TRUE, ''); 1143 else 1144 return array(FALSE, 'ERROR attempting to blacklist ' . $sender); 1145 1146 1147 // here is how you can retrieve additional headers from 1148 // the current message, in case you need them... 1149 // 1150 // this retrieves the message's Subject header in the format 1151 // array(0 => 'Subject:', 1 => 'This is my message subject') 1152 // 1153 $subject = sb_get_message_header($message_id, $entity_id, 'Subject'); 1154 1155} 1156 1157 1158 1159/** 1160 * Example custom spam report handler 1161 * 1162 * Reports one or more spam by blacklisting the message sender(s). 1163 * 1164 * This function is intended as an example for use with the 1165 * report-by-custom-function ($sb_report_spam_by_custom_function) 1166 * feature, and NOT particularly for use with the extra buttons 1167 * functionality, although it does also call to the example 1168 * blacklist() function above that is also used by the sample 1169 * extra button settings. 1170 * 1171 * @param array $message_ids An array of message IDs to be reported. 1172 * @param string $passed_ent_id The message entity being reported 1173 * (zero if the message itself is being 1174 * reported (only applicable when there 1175 * is just one element in the $message_ids 1176 * array)) 1177 * 1178 * @return string An error message if an error occurred, 1179 * empty string otherwise 1180 * 1181 */ 1182function report_spam_by_blacklist($message_ids, $passed_ent_id) 1183{ 1184 1185 // you need to supply the functionality herein 1186 // 1187 return ''; 1188 1189 1190 global $username, $sb_debug; 1191 $error = ''; 1192 $me = 'report_spam_by_blacklist'; 1193 1194 include_once(SM_PATH . 'plugins/spam_buttons/functions.php'); 1195 spam_buttons_init(); 1196 1197 1198 // just loop through the messages, reporting one at a time 1199 // 1200 if (is_array($message_ids)) foreach ($message_ids as $messageID) 1201 { 1202 1203 // here is how you can retrieve additional headers from 1204 // the message, in case you need them... 1205 // 1206 // this retrieves the message's From header in the format 1207 // array(0 => 'From:', 1 => '"Jose" <jose@example.org>') 1208 // 1209 $sender = sb_get_message_header($messageID, $passed_ent_id, 'From'); 1210 1211 1212 // this parses out just the email address portion of the From header 1213 // 1214 if (function_exists('parseRFC822Address')) 1215 { 1216 $sender = parseRFC822Address($sender[1], 1); 1217 $sender = $sender[0][2] . '@' . $sender[0][3]; 1218 } 1219 else 1220 { 1221 $sender = parseAddress($sender[1], 1); 1222 $sender = $sender[0][0]; 1223 } 1224 1225 1226 // now, blacklist the sender 1227 // 1228 $ret = blacklist('', $username, $sender, $messageID, $passed_ent_id); 1229 if (is_array($ret) && empty($ret[0]) && !empty($ret[1])) 1230 $error = $ret[1]; 1231 1232 1233 // dump stuff out if debugging 1234 // 1235 if ($sb_debug) 1236 { 1237 echo '<hr /><strong>REPORTED BY CUSTOM FUNCTION:</strong> ' . $me . '<br /><br />'; 1238 echo '<hr /><strong>SENDER REPORTED:</strong> ' . $sender . '<br /><br />'; 1239 echo '<hr /><strong>RESULTS FROM REPORT:</strong> (' . $error . ')<br /><br />'; 1240 exit; 1241 } 1242 1243 1244 // oops, report failed - put together nicely formatted error message 1245 // 1246 if (!empty($error)) 1247 { 1248 $previous_domain = sq_change_text_domain('spam_buttons'); 1249 1250 if (empty($passed_ent_id)) 1251 $error = str_replace(array('%1', '%2'), 1252 array($messageID, $error), 1253 _("ERROR: Problem reporting message ID %1: %2")); 1254 else 1255 $error = str_replace(array('%1', '%2', '%3'), 1256 array($messageID, $passed_ent_id, $error), 1257 _("ERROR: Problem reporting message ID %1 (entity %2): %3")); 1258 1259 sq_change_text_domain($previous_domain); 1260 1261 break; // out of foreach loop 1262 } 1263 1264 } 1265 1266 return $error; 1267 1268} 1269 1270 1271 1272/** 1273 * Example custom ham report handler 1274 * 1275 * Reports one or more ham by whitelisting the message sender(s). 1276 * 1277 * This function is intended as an example for use with the 1278 * report-by-custom-function ($sb_report_not_spam_by_custom_function) 1279 * feature, and NOT particularly for use with the extra buttons 1280 * functionality, although it does also call to the example 1281 * whitelist() function above that is also used by the sample 1282 * extra button settings. 1283 * 1284 * @param array $message_ids An array of message IDs to be reported. 1285 * @param string $passed_ent_id The message entity being reported 1286 * (zero if the message itself is being 1287 * reported (only applicable when there 1288 * is just one element in the $message_ids 1289 * array)) 1290 * 1291 * @return string An error message if an error occurred, 1292 * empty string otherwise 1293 * 1294 */ 1295function report_ham_by_whitelist($message_ids, $passed_ent_id) 1296{ 1297 1298 // you need to supply the functionality herein 1299 // 1300 return ''; 1301 1302 1303 global $username, $sb_debug; 1304 $error = ''; 1305 $me = 'report_spam_by_whitelist'; 1306 1307 include_once(SM_PATH . 'plugins/spam_buttons/functions.php'); 1308 spam_buttons_init(); 1309 1310 1311 // just loop through the messages, reporting one at a time 1312 // 1313 if (is_array($message_ids)) foreach ($message_ids as $messageID) 1314 { 1315 1316 // here is how you can retrieve additional headers from 1317 // the message, in case you need them... 1318 // 1319 // this retrieves the message's From header in the format 1320 // array(0 => 'From:', 1 => '"Jose" <jose@example.org>') 1321 // 1322 $sender = sb_get_message_header($messageID, $passed_ent_id, 'From'); 1323 1324 1325 // this parses out just the email address portion of the From header 1326 // 1327 if (function_exists('parseRFC822Address')) 1328 { 1329 $sender = parseRFC822Address($sender[1], 1); 1330 $sender = $sender[0][2] . '@' . $sender[0][3]; 1331 } 1332 else 1333 { 1334 $sender = parseAddress($sender[1], 1); 1335 $sender = $sender[0][0]; 1336 } 1337 1338 1339 // now, whitelist the sender 1340 // 1341 $ret = whitelist('', $username, $sender, $messageID, $passed_ent_id); 1342 if (is_array($ret) && empty($ret[0]) && !empty($ret[1])) 1343 $error = $ret[1]; 1344 1345 1346 // dump stuff out if debugging 1347 // 1348 if ($sb_debug) 1349 { 1350 echo '<hr /><strong>REPORTED BY CUSTOM FUNCTION:</strong> ' . $me . '<br /><br />'; 1351 echo '<hr /><strong>SENDER REPORTED:</strong> ' . $sender . '<br /><br />'; 1352 echo '<hr /><strong>RESULTS FROM REPORT:</strong> (' . $error . ')<br /><br />'; 1353 exit; 1354 } 1355 1356 1357 // oops, report failed - put together nicely formatted error message 1358 // 1359 if (!empty($error)) 1360 { 1361 $previous_domain = sq_change_text_domain('spam_buttons'); 1362 1363 if (empty($passed_ent_id)) 1364 $error = str_replace(array('%1', '%2'), 1365 array($messageID, $error), 1366 _("ERROR: Problem reporting message ID %1: %2")); 1367 else 1368 $error = str_replace(array('%1', '%2', '%3'), 1369 array($messageID, $passed_ent_id, $error), 1370 _("ERROR: Problem reporting message ID %1 (entity %2): %3")); 1371 1372 sq_change_text_domain($previous_domain); 1373 1374 break; // out of foreach loop 1375 } 1376 1377 } 1378 1379 return $error; 1380 1381} 1382 1383 1384 1385