3 * spamcop.php -- SpamCop plugin -- main page
5 * @copyright (c) 1999-2004 The SquirrelMail development team
6 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
13 define('SM_PATH','../../');
15 /* SquirrelMail required files. */
16 require_once(SM_PATH
. 'include/validate.php');
17 require_once(SM_PATH
. 'functions/imap.php');
20 * Stores message in attachment directory, when email based reports are used
23 function getMessage_RFC822_Attachment($message, $composeMessage, $passed_id,
24 $passed_ent_id='', $imapConnection) {
25 global $attachment_dir, $username;
27 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
28 if (!$passed_ent_id) {
29 $body_a = sqimap_run_command($imapConnection,
30 'FETCH '.$passed_id.' RFC822',
31 TRUE, $response, $readmessage,
34 $body_a = sqimap_run_command($imapConnection,
35 'FETCH '.$passed_id.' BODY['.$passed_ent_id.']',
36 TRUE, $response, $readmessage,TRUE);
37 $message = $message->parent
;
39 if ($response == 'OK') {
41 $body = implode('', $body_a) . "\r\n";
43 $localfilename = GenerateRandomString(32, 'FILE', 7);
44 $full_localfilename = "$hashed_attachment_dir/$localfilename";
45 $fp = fopen( $full_localfilename, 'w');
49 /* dirty relative dir fix */
50 if (substr($attachment_dir,0,3) == '../') {
51 $attachment_dir = substr($attachment_dir,3);
52 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
54 $full_localfilename = "$hashed_attachment_dir/$localfilename";
56 $composeMessage->initAttachment('message/rfc822','email.txt',
59 return $composeMessage;
65 sqgetGlobalVar('username', $username, SQ_SESSION
);
66 sqgetGlobalVar('key', $key, SQ_COOKIE
);
67 sqgetGlobalVar('onetimepad', $onetimepad, SQ_SESSION
);
69 sqgetGlobalVar('mailbox', $mailbox, SQ_GET
);
70 sqgetGlobalVar('passed_id', $passed_id, SQ_GET
);
71 sqgetGlobalVar('js_web', $js_web, SQ_GET
);
73 if (! sqgetGlobalVar('startMessage', $startMessage, SQ_GET
) ) {
76 if (! sqgetGlobalVar('passed_ent_id', $passed_ent_id, SQ_GET
) ) {
79 if (! sqgetGlobalVar('js_web', $js_web, SQ_GET
) ) {
83 sqgetGlobalVar('compose_messages', $compose_messages, SQ_SESSION
);
85 if(! sqgetGlobalVar('composesession', $composesession, SQ_SESSION
) ) {
87 sqsession_register($composesession, 'composesession');
91 // js_web variable is 1 only when link opens web based report page in new window
92 // and in new window menu line or extra javascript code is not needed.
94 displayHTMLHeader(_("SpamCop reporting"));
95 echo "<body text=\"$color[8]\" bgcolor=\"$color[4]\" link=\"$color[7]\" vlink=\"$color[7]\" alink=\"$color[7]\">\n";
97 displayPageHeader($color,$mailbox);
100 $imap_stream = sqimap_login($username, $key, $imapServerAddress,
102 sqimap_mailbox_select($imap_stream, $mailbox);
104 if ($spamcop_method == 'quick_email' ||
105 $spamcop_method == 'thorough_email') {
106 // Use email-based reporting -- save as an attachment
107 $session = "$composesession"+
1;
108 $composesession = $session;
109 sqsession_register($composesession,'composesession');
110 if (!isset($compose_messages)) {
111 $compose_messages = array();
113 if (!isset($compose_messages[$session]) ||
($compose_messages[$session] == NULL)) {
114 $composeMessage = new Message();
115 $rfc822_header = new Rfc822Header();
116 $composeMessage->rfc822_header
= $rfc822_header;
117 $composeMessage->reply_rfc822_header
= '';
118 $compose_messages[$session] = $composeMessage;
119 sqsession_register($compose_messages,'compose_messages');
121 $composeMessage=$compose_messages[$session];
125 $message = sqimap_get_message($imap_stream, $passed_id, $mailbox);
126 $composeMessage = getMessage_RFC822_Attachment($message, $composeMessage, $passed_id,
127 $passed_ent_id, $imap_stream);
129 $compose_messages[$session] = $composeMessage;
130 sqsession_register($compose_messages, 'compose_messages');
132 $fn = getPref($data_dir, $username, 'full_name');
133 $em = getPref($data_dir, $username, 'email_address');
135 $HowItLooks = $fn . ' ';
137 $HowItLooks .= '<' . $em . '>';
142 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.");
147 <table align
="center" width
="75%" border
="0" cellpadding
="0" cellspacing
="0">
149 <td align
="left" valign
="top">
150 <?php
if (isset($js_web) && $js_web) {
151 echo '<form method="post" action="javascript:return false">';
152 echo '<input type="button" value="' . _("Close Window") . "\" onClick=\"window.close(); return true;\" />\n";
154 ?
><form method
="post" action
="../../src/right_main.php">
155 <input type
="hidden" name
="mailbox" value
="<?php echo htmlspecialchars($mailbox) ?>" />
156 <input type
="hidden" name
="startMessage" value
="<?php echo htmlspecialchars($startMessage) ?>" />
158 echo '<input type="submit" value="' . _("Cancel / Done") . "\" />";
162 <td align
="right" valign
="top">
163 <?php
if ($spamcop_method == 'thorough_email' ||
164 $spamcop_method == 'quick_email') {
165 if ($spamcop_method == 'thorough_email')
166 $report_email = 'submit.' . $spamcop_id . '@spam.spamcop.net';
168 $report_email = 'quick.' . $spamcop_id . '@spam.spamcop.net';
169 $form_action = SM_PATH
. 'src/compose.php';
170 ?
> <form method
="post" action
="<?php echo $form_action?>">
171 <input type
="hidden" name
="mailbox" value
="<?php echo htmlspecialchars($mailbox) ?>" />
172 <input type
="hidden" name
="spamcop_is_composing" value
="<?php echo htmlspecialchars($passed_id) ?>" />
173 <input type
="hidden" name
="send_to" value
="<?php echo htmlspecialchars($report_email)?>" />
174 <input type
="hidden" name
="subject" value
="reply anyway" />
175 <input type
="hidden" name
="identity" value
="0" />
176 <input type
="hidden" name
="session" value
="<?php echo $session?>" />
178 echo '<input type="submit" name="send" value="' . _("Send Spam Report") . "\" />\n";
180 $spam_message = mime_fetch_body ($imap_stream, $passed_id, $passed_ent_id, 50000);
182 if (strlen($spam_message) == 50000) {
183 $Warning = "\n[truncated by SpamCop]\n";
184 $spam_message = substr($spam_message, 0, 50000 - strlen($Warning)) . $Warning;
186 if ($spamcop_type=='member') {
187 $action_url="http://members.spamcop.net/sc";
189 $action_url="http://www.spamcop.net/sc";
191 if (isset($js_web) && $js_web) {
192 echo "<form method=\"post\" action=\"$action_url\" name=\"submitspam\"".
193 " enctype=\"multipart/form-data\">\n";
195 echo "<form method=\"post\" action=\"$action_url\" name=\"submitspam\"".
196 " enctype=\"multipart/form-data\" target=\"_blank\">\n";
198 <input type
="hidden" name
="action" value
="submit" />
199 <input type
="hidden" name
="oldverbose" value
="1" />
200 <input type
="hidden" name
="code" value
="<?php echo htmlspecialchars($spamcop_id) ?>" />
201 <input type
="hidden" name
="spam" value
="<?php echo htmlspecialchars($spam_message); ?>" />
203 echo '<input type="submit" name="x1" value="' . _("Send Spam Report") . "\" />\n";