rtl alignment fix
[squirrelmail.git] / plugins / spamcop / spamcop.php
1 <?php
2 /**
3 ** spamcop.php -- SpamCop plugin
4 **
5 ** Copyright (c) 1999-2003 The SquirrelMail development team
6 ** Licensed under the GNU GPL. For full terms see the file COPYING.
7 **
8 ** $Id$
9 * @package plugins
10 * @subpackage spamcop
11 **/
12
13 /** @ignore */
14 define('SM_PATH','../../');
15
16 /* SquirrelMail required files. */
17 require_once(SM_PATH . 'include/validate.php');
18 require_once(SM_PATH . 'functions/imap.php');
19
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 }
36 if ($response == 'OK') {
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 }
59
60
61 /* GLOBALS */
62
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 */
84
85
86 displayPageHeader($color, $mailbox);
87
88 $imap_stream = sqimap_login($username, $key, $imapServerAddress,
89 $imapPort, 0);
90 sqimap_mailbox_select($imap_stream, $mailbox);
91
92 if ($spamcop_method == 'quick_email' ||
93 $spamcop_method == 'thorough_email') {
94 // Use email-based reporting -- save as an attachment
95 $session = "$composesession"+1;
96 $composesession = $session;
97 sqsession_register($composesession,'composesession');
98 if (!isset($compose_messages)) {
99 $compose_messages = array();
100 }
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];
110 }
111
112
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 != '')
125 $HowItLooks .= '<' . $em . '>';
126 }
127
128
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 ?>
134
135 <table align="center" width="75%" border="0" cellpadding="0" cellspacing="0">
136 <tr>
137 <td align="left" valign="top">
138 <?PHP if (isset($js_web) && $js_web) {
139 ?><form method="post" action="javascript:return false">
140 <input type="button" value="Close Window"
141 onClick="window.close(); return true;">
142 <?PHP
143 } else {
144 ?><form method="post" action="../../src/right_main.php">
145 <input type="hidden" name="mailbox" value="<?PHP echo htmlspecialchars($mailbox) ?>">
146 <input type="hidden" name="startMessage" value="<?PHP echo htmlspecialchars($startMessage) ?>">
147 <input type="submit" value="Cancel / Done">
148 <?PHP
149 }
150 ?></form>
151 </td>
152 <td align="right" valign="top">
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';
159 $form_action = SM_PATH . 'src/compose.php';
160 ?> <form method="post" action="<?PHP echo $form_action?>">
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) ?>">
163 <input type="hidden" name="send_to" value="<?PHP echo $report_email?>">
164 <input type="hidden" name="subject" value="reply anyway">
165 <input type="hidden" name="identity" value="0">
166 <input type="hidden" name="session" value="<?PHP echo $session?>">
167 <input type="submit" name="send" value="Send Spam Report">
168 <?PHP } else {
169 $spam_message = mime_fetch_body ($imap_stream, $passed_id, 0, 50000);
170
171 if (strlen($spam_message) == 50000) {
172 $Warning = "\n[truncated by SpamCop]\n";
173 $spam_message = substr($spam_message, 0, 50000 - strlen($Warning)) . $Warning;
174 }
175 if (isset($js_web) && $js_web) {
176 ?> <form method="post" action="http://www.spamcop.net/sc" name="submitspam"
177 enctype="multipart/form-data"><?PHP
178 } else {
179 ?> <form method="post" action="http://www.spamcop.net/sc" name="submitspam"
180 enctype="multipart/form-data" target="_blank"><?PHP
181 } ?>
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 ?>">
185 <input type="hidden" name="spam" value="<?PHP echo htmlspecialchars($spam_message); ?>">
186 <input type="submit" name="x1" value="Send Spam Report">
187 <?PHP }
188 ?> </form>
189 </td>
190 </tr>
191 </table>
192 </body>
193 </html>