functions.php 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. <?php
  2. /**
  3. * SpamCop plugin - functions
  4. *
  5. * @copyright &copy; 1999-2007 The SquirrelMail Project Team
  6. * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  7. * @version $Id$
  8. * @package plugins
  9. * @subpackage spamcop
  10. */
  11. /* sqgetGlobalVar(), getPref(), setPref(), sqimap functions are used */
  12. /**
  13. * Disable Quick Reporting by default
  14. * @global boolean $spamcop_quick_report
  15. * @since 1.4.3 and 1.5.0
  16. */
  17. global $spamcop_quick_report;
  18. $spamcop_quick_report = false;
  19. /**
  20. * Loads spamcop settings and validates some of values (make '' into 'default', etc.)
  21. *
  22. * Internal function used to reduce size of setup.php
  23. * @since 1.5.1
  24. * @access private
  25. */
  26. function spamcop_load_function() {
  27. global $username, $data_dir, $spamcop_enabled, $spamcop_delete, $spamcop_save,
  28. $spamcop_method, $spamcop_id, $spamcop_quick_report, $spamcop_type;
  29. $spamcop_enabled = getPref($data_dir, $username, 'spamcop_enabled');
  30. $spamcop_delete = getPref($data_dir, $username, 'spamcop_delete');
  31. $spamcop_save = getPref($data_dir, $username, 'spamcop_save',true);
  32. $spamcop_method = getPref($data_dir, $username, 'spamcop_method');
  33. $spamcop_type = getPref($data_dir, $username, 'spamcop_type');
  34. $spamcop_id = getPref($data_dir, $username, 'spamcop_id');
  35. if ($spamcop_method == '') {
  36. // Default to web_form. It is faster.
  37. $spamcop_method = 'web_form';
  38. setPref($data_dir, $username, 'spamcop_method', $spamcop_method);
  39. }
  40. if (! $spamcop_quick_report && $spamcop_method=='quick_email') {
  41. $spamcop_method = 'web_form';
  42. setPref($data_dir, $username, 'spamcop_method', $spamcop_method);
  43. }
  44. if ($spamcop_type == '') {
  45. $spamcop_type = 'free';
  46. setPref($data_dir, $username, 'spamcop_type', $spamcop_type);
  47. }
  48. if ($spamcop_id == '')
  49. $spamcop_enabled = 0;
  50. }
  51. /**
  52. * Add spamcop link to read_body (internal function)
  53. * @since 1.5.1
  54. * @access private
  55. */
  56. function spamcop_show_link_function(&$links) {
  57. global $spamcop_enabled, $spamcop_method, $spamcop_quick_report;
  58. if (! $spamcop_enabled)
  59. return;
  60. /* GLOBALS */
  61. sqgetGlobalVar('passed_id', $passed_id, SQ_FORM);
  62. sqgetGlobalVar('passed_ent_id',$passed_ent_id,SQ_FORM);
  63. sqgetGlobalVar('mailbox', $mailbox, SQ_FORM);
  64. if ( sqgetGlobalVar('startMessage', $startMessage, SQ_FORM) ) {
  65. $startMessage = (int)$startMessage;
  66. }
  67. /* END GLOBALS */
  68. // catch unset passed_ent_id
  69. if (! sqgetGlobalVar('passed_ent_id', $passed_ent_id, SQ_FORM) ) {
  70. $passed_ent_id = 0;
  71. }
  72. /*
  73. Catch situation when user uses quick_email and does not update
  74. preferences. User gets web_form link. If prefs are set to
  75. quick_email format - they will be updated after clicking the link
  76. */
  77. if (! $spamcop_quick_report && $spamcop_method=='quick_email') {
  78. $spamcop_method = 'web_form';
  79. }
  80. // FIXME: do we need this javascript and if so, fix it
  81. // <script type="text/javascript">
  82. // document.write('<a href="../plugins/spamcop/spamcop.php?passed_id=<php echo urlencode($passed_id); >&amp;js_web=1&amp;mailbox=<php echo urlencode($mailbox); >&amp;passed_ent_id=<php echo urlencode($passed_ent_id); >" target="_blank">');
  83. //document.write("<php echo _("Report as Spam"); >");
  84. //document.write("</a>");
  85. //</script>
  86. $url = '../plugins/spamcop/spamcop.php?passed_id=' . urlencode($passed_id) .
  87. '&amp;mailbox=' . urlencode($mailbox) . '&amp;startMessage=' . urlencode($startMessage) .
  88. '&amp;passed_ent_id=' . urlencode($passed_ent_id);
  89. if ( $spamcop_method == 'web_form' && checkForJavascript() ) {
  90. $url .= '&amp;js_web=1';
  91. }
  92. $links[] = array ( 'URL' => $url,
  93. 'Text' => _("Report as Spam")
  94. );
  95. }
  96. /**
  97. * Add spamcop option block (internal function)
  98. * @since 1.5.1
  99. * @access private
  100. */
  101. function spamcop_options_function() {
  102. global $optpage_blocks;
  103. $optpage_blocks[] = array(
  104. 'name' => _("SpamCop - Spam Reporting"),
  105. 'url' => '../plugins/spamcop/options.php',
  106. 'desc' => _("Help fight the battle against unsolicited email. SpamCop reads the spam email and determines the correct addresses to send complaints to. Quite fast, really smart, and easy to use."),
  107. 'js' => false
  108. );
  109. }
  110. /**
  111. * Process messages that are submitted by email.
  112. *
  113. * Delete spam if user wants to delete it. Don't save submitted emails.
  114. * Implement overrides that fix compose.php behavior.
  115. * @since 1.5.1
  116. * @access private
  117. */
  118. function spamcop_while_sending_function() {
  119. global $mailbox, $spamcop_delete, $spamcop_save, $spamcop_is_composing, $auto_expunge,
  120. $username, $imapServerAddress, $imapPort;
  121. if (sqgetGlobalVar('spamcop_is_composing' , $spamcop_is_composing)) {
  122. // delete spam message
  123. if ($spamcop_delete) {
  124. $imapConnection = sqimap_login($username, false, $imapServerAddress, $imapPort, 0);
  125. sqimap_mailbox_select($imapConnection, $mailbox);
  126. sqimap_msgs_list_delete($imapConnection, $mailbox, array($spamcop_is_composing));
  127. if ($auto_expunge)
  128. sqimap_mailbox_expunge($imapConnection, $mailbox, true);
  129. }
  130. if (! $spamcop_save) {
  131. // disable use of send folder.
  132. // Temporally override in order to disable saving of 'reply anyway' messages.
  133. global $default_move_to_sent;
  134. $default_move_to_sent=false;
  135. }
  136. // change default email composition setting. Plugin always operates in right frame.
  137. // make sure that compose.php redirects to right page. Temporally override.
  138. global $compose_new_win;
  139. $compose_new_win = false;
  140. }
  141. }
  142. /**
  143. * Internal spamcop plugin function.
  144. *
  145. * It is used to display similar action links.
  146. * @access private
  147. */
  148. function spamcop_enable_disable($option,$disable_action,$enable_action) {
  149. if ($option) {
  150. $ret= _("Enabled") . " (<a href=\"options.php?action=$disable_action\">" . _("Disable it") . "</a>)\n";
  151. } else {
  152. $ret = _("Disabled") . " (<a href=\"options.php?action=$enable_action\">" . _("Enable it") . "</a>)\n";
  153. }
  154. return $ret;
  155. }
  156. /**
  157. * Stores message in attachment directory, when email based reports are used
  158. * @access private
  159. * @todo Duplicate code in src/compose.php
  160. */
  161. function spamcop_getMessage_RFC822_Attachment($message, $composeMessage, $passed_id,
  162. $passed_ent_id='', $imapConnection) {
  163. if (!$passed_ent_id) {
  164. $body_a = sqimap_run_command($imapConnection,
  165. 'FETCH '.$passed_id.' RFC822',
  166. TRUE, $response, $readmessage,
  167. TRUE);
  168. } else {
  169. $body_a = sqimap_run_command($imapConnection,
  170. 'FETCH '.$passed_id.' BODY['.$passed_ent_id.']',
  171. TRUE, $response, $readmessage,TRUE);
  172. $message = $message->parent;
  173. }
  174. if ($response == 'OK') {
  175. array_shift($body_a);
  176. $body = implode('', $body_a) . "\r\n";
  177. $filename = sq_get_attach_tempfile();
  178. $fp = fopen($filename, 'wb');
  179. fwrite ($fp, $body);
  180. fclose($fp);
  181. $composeMessage->initAttachment('message/rfc822','email.txt',
  182. $filename);
  183. }
  184. return $composeMessage;
  185. }