5121598d |
1 | <?php |
04f6008a |
2 | /** |
3 | ** spamcop.php -- SpamCop plugin |
4 | ** |
76911253 |
5 | ** Copyright (c) 1999-2003 The SquirrelMail development team |
04f6008a |
6 | ** Licensed under the GNU GPL. For full terms see the file COPYING. |
7 | ** |
ea5f4b8e |
8 | ** $Id$ |
9 | * @package plugins |
10 | * @subpackage spamcop |
04f6008a |
11 | **/ |
5121598d |
12 | |
ea5f4b8e |
13 | /** @ignore */ |
8d6a115b |
14 | define('SM_PATH','../../'); |
7afb9a75 |
15 | |
8d6a115b |
16 | /* SquirrelMail required files. */ |
17 | require_once(SM_PATH . 'include/validate.php'); |
18 | require_once(SM_PATH . 'functions/imap.php'); |
04f6008a |
19 | |
1e89ed41 |
20 | function getMessage_RFC822_Attachment($message, $composeMessage, $passed_id, |
21 | $passed_ent_id='', $imapConnection) { |
22 | global $attachments, $attachment_dir, $username, $data_dir, $uid_support; |
23 | |
24 | $hashed_attachment_dir = getHashedDir($username, $attachment_dir); |
25 | if (!$passed_ent_id) { |
26 | $body_a = sqimap_run_command($imapConnection, |
27 | 'FETCH '.$passed_id.' RFC822', |
28 | TRUE, $response, $readmessage, |
29 | $uid_support); |
30 | } else { |
31 | $body_a = sqimap_run_command($imapConnection, |
32 | 'FETCH '.$passed_id.' BODY['.$passed_ent_id.']', |
33 | TRUE, $response, $readmessage, $uid_support); |
34 | $message = $message->parent; |
35 | } |
7e449464 |
36 | if ($response == 'OK') { |
1e89ed41 |
37 | $subject = encodeHeader($message->rfc822_header->subject); |
38 | array_shift($body_a); |
39 | $body = implode('', $body_a) . "\r\n"; |
40 | |
41 | $localfilename = GenerateRandomString(32, 'FILE', 7); |
42 | $full_localfilename = "$hashed_attachment_dir/$localfilename"; |
43 | $fp = fopen( $full_localfilename, 'w'); |
44 | fwrite ($fp, $body); |
45 | fclose($fp); |
46 | |
47 | /* dirty relative dir fix */ |
48 | if (substr($attachment_dir,0,3) == '../') { |
49 | $attachment_dir = substr($attachment_dir,3); |
50 | $hashed_attachment_dir = getHashedDir($username, $attachment_dir); |
51 | } |
52 | $full_localfilename = "$hashed_attachment_dir/$localfilename"; |
53 | |
54 | $composeMessage->initAttachment('message/rfc822','email.txt', |
55 | $full_localfilename); |
56 | } |
57 | return $composeMessage; |
58 | } |
04f6008a |
59 | |
1e89ed41 |
60 | |
8ddc4111 |
61 | /* GLOBALS */ |
04f6008a |
62 | |
8ddc4111 |
63 | sqgetGlobalVar('username', $username, SQ_SESSION); |
64 | sqgetGlobalVar('key', $key, SQ_COOKIE); |
65 | sqgetGlobalVar('onetimepad', $onetimepad, SQ_SESSION); |
66 | |
67 | sqgetGlobalVar('mailbox', $mailbox, SQ_GET); |
68 | sqgetGlobalVar('passed_id', $passed_id, SQ_GET); |
69 | |
70 | if (! sqgetGlobalVar('startMessage', $startMessage, SQ_GET) ) { |
71 | $startMessage = 1; |
72 | } |
73 | if (! sqgetGlobalVar('passed_ent_id', $passed_ent_id, SQ_GET) ) { |
74 | $passed_ent_id = ''; |
75 | } |
76 | |
77 | sqgetGlobalVar('compose_messages', $compose_messages, SQ_SESSION); |
78 | |
79 | if(! sqgetGlobalVar('composesession', $composesession, SQ_SESSION) ) { |
80 | $composesession = 0; |
81 | sqsession_register($composesession, 'composesession'); |
82 | } |
83 | /* END GLOBALS */ |
1e89ed41 |
84 | |
5121598d |
85 | |
86 | displayPageHeader($color, $mailbox); |
87 | |
88 | $imap_stream = sqimap_login($username, $key, $imapServerAddress, |
89 | $imapPort, 0); |
90 | sqimap_mailbox_select($imap_stream, $mailbox); |
5121598d |
91 | |
92 | if ($spamcop_method == 'quick_email' || |
93 | $spamcop_method == 'thorough_email') { |
94 | // Use email-based reporting -- save as an attachment |
1e89ed41 |
95 | $session = "$composesession"+1; |
96 | $composesession = $session; |
97 | sqsession_register($composesession,'composesession'); |
98 | if (!isset($compose_messages)) { |
99 | $compose_messages = array(); |
430be822 |
100 | } |
1e89ed41 |
101 | if (!isset($compose_messages[$session]) || ($compose_messages[$session] == NULL)) { |
102 | $composeMessage = new Message(); |
103 | $rfc822_header = new Rfc822Header(); |
104 | $composeMessage->rfc822_header = $rfc822_header; |
105 | $composeMessage->reply_rfc822_header = ''; |
106 | $compose_messages[$session] = $composeMessage; |
107 | sqsession_register($compose_messages,'compose_messages'); |
108 | } else { |
109 | $composeMessage=$compose_messages[$session]; |
430be822 |
110 | } |
111 | |
04f6008a |
112 | |
1e89ed41 |
113 | $message = sqimap_get_message($imap_stream, $passed_id, $mailbox); |
114 | $composeMessage = getMessage_RFC822_Attachment($message, $composeMessage, $passed_id, |
115 | $passed_ent_id='', $imap_stream); |
116 | |
117 | $compose_messages[$session] = $composeMessage; |
118 | sqsession_register($compose_messages, 'compose_messages'); |
119 | |
120 | $fn = getPref($data_dir, $username, 'full_name'); |
121 | $em = getPref($data_dir, $username, 'email_address'); |
122 | |
123 | $HowItLooks = $fn . ' '; |
124 | if ($em != '') |
5121598d |
125 | $HowItLooks .= '<' . $em . '>'; |
1e89ed41 |
126 | } |
5121598d |
127 | |
5121598d |
128 | |
2bd52bbe |
129 | echo "<p>"; |
130 | 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."); |
131 | echo "</p>"; |
132 | |
133 | ?> |
5121598d |
134 | |
8ddc4111 |
135 | <table align="center" width="75%" border="0" cellpadding="0" cellspacing="0"> |
5121598d |
136 | <tr> |
8ddc4111 |
137 | <td align="left" valign="top"> |
5121598d |
138 | <?PHP if (isset($js_web) && $js_web) { |
8ddc4111 |
139 | ?><form method="post" action="javascript:return false"> |
140 | <input type="button" value="Close Window" |
5121598d |
141 | onClick="window.close(); return true;"> |
142 | <?PHP |
143 | } else { |
8ddc4111 |
144 | ?><form method="post" action="../../src/right_main.php"> |
2bd52bbe |
145 | <input type="hidden" name="mailbox" value="<?PHP echo htmlspecialchars($mailbox) ?>"> |
146 | <input type="hidden" name="startMessage" value="<?PHP echo htmlspecialchars($startMessage) ?>"> |
8ddc4111 |
147 | <input type="submit" value="Cancel / Done"> |
5121598d |
148 | <?PHP |
149 | } |
150 | ?></form> |
151 | </td> |
8ddc4111 |
152 | <td align="right" valign="top"> |
5121598d |
153 | <?PHP if ($spamcop_method == 'thorough_email' || |
154 | $spamcop_method == 'quick_email') { |
155 | if ($spamcop_method == 'thorough_email') |
156 | $report_email = 'submit.' . $spamcop_id . '@spam.spamcop.net'; |
157 | else |
158 | $report_email = 'quick.' . $spamcop_id . '@spam.spamcop.net'; |
1e89ed41 |
159 | $form_action = SM_PATH . 'src/compose.php'; |
8ddc4111 |
160 | ?> <form method="post" action="<?PHP echo $form_action?>"> |
2bd52bbe |
161 | <input type="hidden" name="mailbox" value="<?PHP echo htmlspecialchars($mailbox) ?>"> |
162 | <input type="hidden" name="spamcop_is_composing" value="<?PHP echo htmlspecialchars($passed_id) ?>"> |
8ddc4111 |
163 | <input type="hidden" name="send_to" value="<?PHP echo $report_email?>"> |
164 | <input type="hidden" name="subject" value="reply anyway"> |
15ac78fe |
165 | <input type="hidden" name="identity" value="0"> |
8ddc4111 |
166 | <input type="hidden" name="session" value="<?PHP echo $session?>"> |
167 | <input type="submit" name="send" value="Send Spam Report"> |
5121598d |
168 | <?PHP } else { |
2b5fddf5 |
169 | $spam_message = mime_fetch_body ($imap_stream, $passed_id, 0, 50000); |
9538cd4c |
170 | |
2b5fddf5 |
171 | if (strlen($spam_message) == 50000) { |
5121598d |
172 | $Warning = "\n[truncated by SpamCop]\n"; |
2b5fddf5 |
173 | $spam_message = substr($spam_message, 0, 50000 - strlen($Warning)) . $Warning; |
5121598d |
174 | } |
175 | if (isset($js_web) && $js_web) { |
2b5fddf5 |
176 | ?> <form method="post" action="http://www.spamcop.net/sc" name="submitspam" |
5121598d |
177 | enctype="multipart/form-data"><?PHP |
178 | } else { |
2b5fddf5 |
179 | ?> <form method="post" action="http://www.spamcop.net/sc" name="submitspam" |
5121598d |
180 | enctype="multipart/form-data" target="_blank"><?PHP |
181 | } ?> |
8ddc4111 |
182 | <input type="hidden" name="action" value="submit"> |
183 | <input type="hidden" name="oldverbose" value="1"> |
184 | <input type="hidden" name="code" value="<?PHP echo $spamcop_id ?>"> |
2b5fddf5 |
185 | <input type="hidden" name="spam" value="<?PHP echo htmlspecialchars($spam_message); ?>"> |
8ddc4111 |
186 | <input type="submit" name="x1" value="Send Spam Report"> |
5121598d |
187 | <?PHP } |
188 | ?> </form> |
189 | </td> |
190 | </tr> |
191 | </table> |
192 | </body> |
193 | </html> |