spamcop.php 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. <?php
  2. /**
  3. * spamcop.php -- SpamCop plugin -- main page
  4. *
  5. * @copyright (c) 1999-2004 The SquirrelMail development team
  6. * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  7. * @version $Id$
  8. * @package plugins
  9. * @subpackage spamcop
  10. */
  11. /** @ignore */
  12. define('SM_PATH','../../');
  13. /* SquirrelMail required files. */
  14. require_once(SM_PATH . 'include/validate.php');
  15. require_once(SM_PATH . 'functions/imap.php');
  16. /**
  17. * Stores message in attachment directory, when email based reports are used
  18. * @access private
  19. */
  20. function getMessage_RFC822_Attachment($message, $composeMessage, $passed_id,
  21. $passed_ent_id='', $imapConnection) {
  22. global $attachments, $attachment_dir, $username, $data_dir;
  23. $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
  24. if (!$passed_ent_id) {
  25. $body_a = sqimap_run_command($imapConnection,
  26. 'FETCH '.$passed_id.' RFC822',
  27. TRUE, $response, $readmessage,
  28. TRUE);
  29. } else {
  30. $body_a = sqimap_run_command($imapConnection,
  31. 'FETCH '.$passed_id.' BODY['.$passed_ent_id.']',
  32. TRUE, $response, $readmessage,TRUE);
  33. $message = $message->parent;
  34. }
  35. if ($response == 'OK') {
  36. $subject = encodeHeader($message->rfc822_header->subject);
  37. array_shift($body_a);
  38. $body = implode('', $body_a) . "\r\n";
  39. $localfilename = GenerateRandomString(32, 'FILE', 7);
  40. $full_localfilename = "$hashed_attachment_dir/$localfilename";
  41. $fp = fopen( $full_localfilename, 'w');
  42. fwrite ($fp, $body);
  43. fclose($fp);
  44. /* dirty relative dir fix */
  45. if (substr($attachment_dir,0,3) == '../') {
  46. $attachment_dir = substr($attachment_dir,3);
  47. $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
  48. }
  49. $full_localfilename = "$hashed_attachment_dir/$localfilename";
  50. $composeMessage->initAttachment('message/rfc822','email.txt',
  51. $full_localfilename);
  52. }
  53. return $composeMessage;
  54. }
  55. /* GLOBALS */
  56. sqgetGlobalVar('username', $username, SQ_SESSION);
  57. sqgetGlobalVar('key', $key, SQ_COOKIE);
  58. sqgetGlobalVar('onetimepad', $onetimepad, SQ_SESSION);
  59. sqgetGlobalVar('mailbox', $mailbox, SQ_GET);
  60. sqgetGlobalVar('passed_id', $passed_id, SQ_GET);
  61. sqgetGlobalVar('js_web', $js_web, SQ_GET);
  62. if (! sqgetGlobalVar('startMessage', $startMessage, SQ_GET) ) {
  63. $startMessage = 1;
  64. }
  65. if (! sqgetGlobalVar('passed_ent_id', $passed_ent_id, SQ_GET) ) {
  66. $passed_ent_id = 0;
  67. }
  68. if (! sqgetGlobalVar('js_web', $js_web, SQ_GET) ) {
  69. $js_web = 0;
  70. }
  71. sqgetGlobalVar('compose_messages', $compose_messages, SQ_SESSION);
  72. if(! sqgetGlobalVar('composesession', $composesession, SQ_SESSION) ) {
  73. $composesession = 0;
  74. sqsession_register($composesession, 'composesession');
  75. }
  76. /* END GLOBALS */
  77. // js_web variable is 1 only when link opens web based report page in new window
  78. // and in new window menu line or extra javascript code is not needed.
  79. if ($js_web) {
  80. displayHTMLHeader(_("SpamCop reporting"));
  81. echo "<body text=\"$color[8]\" bgcolor=\"$color[4]\" link=\"$color[7]\" vlink=\"$color[7]\" alink=\"$color[7]\">\n";
  82. } else {
  83. displayPageHeader($color,$mailbox);
  84. }
  85. $imap_stream = sqimap_login($username, $key, $imapServerAddress,
  86. $imapPort, 0);
  87. sqimap_mailbox_select($imap_stream, $mailbox);
  88. if ($spamcop_method == 'quick_email' ||
  89. $spamcop_method == 'thorough_email') {
  90. // Use email-based reporting -- save as an attachment
  91. $session = "$composesession"+1;
  92. $composesession = $session;
  93. sqsession_register($composesession,'composesession');
  94. if (!isset($compose_messages)) {
  95. $compose_messages = array();
  96. }
  97. if (!isset($compose_messages[$session]) || ($compose_messages[$session] == NULL)) {
  98. $composeMessage = new Message();
  99. $rfc822_header = new Rfc822Header();
  100. $composeMessage->rfc822_header = $rfc822_header;
  101. $composeMessage->reply_rfc822_header = '';
  102. $compose_messages[$session] = $composeMessage;
  103. sqsession_register($compose_messages,'compose_messages');
  104. } else {
  105. $composeMessage=$compose_messages[$session];
  106. }
  107. $message = sqimap_get_message($imap_stream, $passed_id, $mailbox);
  108. $composeMessage = getMessage_RFC822_Attachment($message, $composeMessage, $passed_id,
  109. $passed_ent_id, $imap_stream);
  110. $compose_messages[$session] = $composeMessage;
  111. sqsession_register($compose_messages, 'compose_messages');
  112. $fn = getPref($data_dir, $username, 'full_name');
  113. $em = getPref($data_dir, $username, 'email_address');
  114. $HowItLooks = $fn . ' ';
  115. if ($em != '')
  116. $HowItLooks .= '<' . $em . '>';
  117. }
  118. echo "<p>";
  119. echo _("Sending this spam report will give you back a reply with URLs that you can click on to properly report this spam message to the proper authorities. This is a free service. By pressing the \"Send Spam Report\" button, you agree to follow SpamCop's rules/terms of service/etc.");
  120. echo "</p>";
  121. ?>
  122. <table align="center" width="75%" border="0" cellpadding="0" cellspacing="0">
  123. <tr>
  124. <td align="left" valign="top">
  125. <?PHP if (isset($js_web) && $js_web) {
  126. echo '<form method="post" action="javascript:return false">';
  127. echo '<input type="button" value="' . _("Close Window") . "\" onClick=\"window.close(); return true;\" />\n";
  128. } else {
  129. ?><form method="post" action="../../src/right_main.php">
  130. <input type="hidden" name="mailbox" value="<?PHP echo htmlspecialchars($mailbox) ?>" />
  131. <input type="hidden" name="startMessage" value="<?PHP echo htmlspecialchars($startMessage) ?>" />
  132. <?PHP
  133. echo '<input type="submit" value="' . _("Cancel / Done") . "\" />";
  134. }
  135. ?></form>
  136. </td>
  137. <td align="right" valign="top">
  138. <?PHP if ($spamcop_method == 'thorough_email' ||
  139. $spamcop_method == 'quick_email') {
  140. if ($spamcop_method == 'thorough_email')
  141. $report_email = 'submit.' . $spamcop_id . '@spam.spamcop.net';
  142. else
  143. $report_email = 'quick.' . $spamcop_id . '@spam.spamcop.net';
  144. $form_action = SM_PATH . 'src/compose.php';
  145. ?> <form method="post" action="<?PHP echo $form_action?>">
  146. <input type="hidden" name="mailbox" value="<?PHP echo htmlspecialchars($mailbox) ?>" />
  147. <input type="hidden" name="spamcop_is_composing" value="<?PHP echo htmlspecialchars($passed_id) ?>" />
  148. <input type="hidden" name="send_to" value="<?PHP echo htmlspecialchars($report_email)?>" />
  149. <input type="hidden" name="subject" value="reply anyway" />
  150. <input type="hidden" name="identity" value="0" />
  151. <input type="hidden" name="session" value="<?PHP echo $session?>" />
  152. <?php
  153. echo '<input type="submit" name="send" value="' . _("Send Spam Report") . "\" />\n";
  154. } else {
  155. $spam_message = mime_fetch_body ($imap_stream, $passed_id, $passed_ent_id, 50000);
  156. if (strlen($spam_message) == 50000) {
  157. $Warning = "\n[truncated by SpamCop]\n";
  158. $spam_message = substr($spam_message, 0, 50000 - strlen($Warning)) . $Warning;
  159. }
  160. if ($spamcop_type=='member') {
  161. $action_url="http://members.spamcop.net/sc";
  162. } else {
  163. $action_url="http://www.spamcop.net/sc";
  164. }
  165. if (isset($js_web) && $js_web) {
  166. echo "<form method=\"post\" action=\"$action_url\" name=\"submitspam\"".
  167. " enctype=\"multipart/form-data\">\n";
  168. } else {
  169. echo "<form method=\"post\" action=\"$action_url\" name=\"submitspam\"".
  170. " enctype=\"multipart/form-data\" target=\"_blank\">\n";
  171. } ?>
  172. <input type="hidden" name="action" value="submit" />
  173. <input type="hidden" name="oldverbose" value="1" />
  174. <input type="hidden" name="code" value="<?PHP echo htmlspecialchars($spamcop_id) ?>" />
  175. <input type="hidden" name="spam" value="<?PHP echo htmlspecialchars($spam_message); ?>" />
  176. <?php
  177. echo '<input type="submit" name="x1" value="' . _("Send Spam Report") . "\" />\n";
  178. }
  179. ?> </form>
  180. </td>
  181. </tr>
  182. </table>
  183. </body>
  184. </html>