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