Search was broken. fixed. List all is weird however, it works but does not alternate...
[squirrelmail.git] / plugins / mail_fetch / setup.php
CommitLineData
d622d38a 1<?php
2
d3c89357 3 /**
4 ** mail_fetch/setup.php
5 **
15e6162e 6 ** Copyright (c) 1999-2002 The SquirrelMail Project Team
d3c89357 7 ** Licensed under the GNU GPL. For full terms see the file COPYING.
8 **
9 ** Setup of the mailfetch plugin.
10 **
11 ** $Id$
12 **/
13
d622d38a 14 require_once( '../plugins/mail_fetch/functions.php' );
15
16 function squirrelmail_plugin_init_mail_fetch() {
17 global $squirrelmail_plugin_hooks;
18 global $mailbox, $imap_stream, $imapConnection;
19
d3c89357 20 $squirrelmail_plugin_hooks['menuline']['mail_fetch'] = 'mail_fetch_link';
21 $squirrelmail_plugin_hooks['loading_prefs']['mail_fetch'] = 'mail_fetch_load_pref';
22 $squirrelmail_plugin_hooks['login_verified']['mail_fetch'] = 'mail_fetch_setnew';
23 $squirrelmail_plugin_hooks['left_main_before']['mail_fetch'] = 'mail_fetch_login';
d622d38a 24 $squirrelmail_plugin_hooks['optpage_register_block']['mail_fetch'] = 'mailfetch_optpage_register_block';
25
26 }
27
28 function mail_fetch_link() {
29
30 displayInternalLink('plugins/mail_fetch/fetch.php', _("Fetch"), '');
31 echo '&nbsp;&nbsp;';
32
33 }
34
35 function mail_fetch_load_pref() {
36
37 global $username,$data_dir;
38 global $mailfetch_server_number;
39 global $mailfetch_cypher;
40 global $mailfetch_server_,$mailfetch_alias_,$mailfetch_user_,$mailfetch_pass_;
41 global $mailfetch_lmos_, $mailfetch_uidl_, $mailfetch_login_, $mailfetch_fref_;
42 global $PHP_SELF;
43
d3c89357 44 if( stristr( $PHP_SELF, 'mail_fetch' ) ) {
45 $mailfetch_server_number = getPref($data_dir, $username, 'mailfetch_server_number', 0);
46 $mailfetch_cypher = getPref($data_dir, $username, 'mailfetch_cypher', 'on' );
d622d38a 47 if ($mailfetch_server_number<1) $mailfetch_server_number=0;
48 for ($i=0;$i<$mailfetch_server_number;$i++) {
49 $mailfetch_server_[$i] = getPref($data_dir, $username, "mailfetch_server_$i");
50 $mailfetch_alias_[$i] = getPref($data_dir, $username, "mailfetch_alias_$i");
51 $mailfetch_user_[$i] = getPref($data_dir, $username, "mailfetch_user_$i");
52 $mailfetch_pass_[$i] = getPref($data_dir, $username, "mailfetch_pass_$i");
53 $mailfetch_lmos_[$i] = getPref($data_dir, $username, "mailfetch_lmos_$i");
54 $mailfetch_login_[$i] = getPref($data_dir, $username, "mailfetch_login_$i");
55 $mailfetch_fref_[$i] = getPref($data_dir, $username, "mailfetch_fref_$i");
56 $mailfetch_uidl_[$i] = getPref($data_dir, $username, "mailfetch_uidl_$i");
57 if( $mailfetch_cypher == 'on' ) $mailfetch_pass_[$i] = decrypt( $mailfetch_pass_[$i] );
58 }
59 }
60 }
61
d622d38a 62 function mail_fetch_login() {
63
64 require_once ('../src/validate.php');
65 require_once ('../functions/imap.php');
66 require_once ('../plugins/mail_fetch/class.POP3.php');
67 require_once ('../plugins/mail_fetch/functions.php');
68 require_once('../functions/i18n.php');
69
70 global $username, $data_dir, $key,$imapServerAddress,$imapPort;
71
72 $mailfetch_newlog = getPref($data_dir, $username, 'mailfetch_newlog');
73
74 $outMsg = '';
75
d3c89357 76 $mailfetch_server_number = getPref($data_dir, $username, 'mailfetch_server_number');
d622d38a 77 if (!isset($mailfetch_server_number)) $mailfetch_server_number=0;
d3c89357 78 $mailfetch_cypher = getPref($data_dir, $username, 'mailfetch_cypher');
d622d38a 79 if ($mailfetch_server_number<1) $mailfetch_server_number=0;
80
81 for ($i_loop=0;$i_loop<$mailfetch_server_number;$i_loop++) {
82
83 $mailfetch_login_[$i_loop] = getPref($data_dir, $username, "mailfetch_login_$i_loop");
84 $mailfetch_fref_[$i_loop] = getPref($data_dir, $username, "mailfetch_fref_$i_loop");
85 $mailfetch_pass_[$i_loop] = getPref($data_dir, $username, "mailfetch_pass_$i_loop");
86 if( $mailfetch_cypher == 'on' )
87 $mailfetch_pass_[$i_loop] = decrypt( $mailfetch_pass_[$i_loop] );
88
89 if( $mailfetch_pass_[$i_loop] <> '' && // Empty passwords no allowed
90 ( ( $mailfetch_login_[$i_loop] == 'on' && $mailfetch_newlog == 'on' ) || $mailfetch_fref_[$i_loop] == 'on' ) ) {
91
92 $mailfetch_server_[$i_loop] = getPref($data_dir, $username, "mailfetch_server_$i_loop");
93 $mailfetch_alias_[$i_loop] = getPref($data_dir, $username, "mailfetch_alias_$i_loop");
94 $mailfetch_user_[$i_loop] = getPref($data_dir, $username, "mailfetch_user_$i_loop");
95 $mailfetch_lmos_[$i_loop] = getPref($data_dir, $username, "mailfetch_lmos_$i_loop");
96 $mailfetch_uidl_[$i_loop] = getPref($data_dir, $username, "mailfetch_uidl_$i_loop");
97 $mailfetch_subfolder_[$i_loop] = getPref($data_dir, $username, "mailfetch_subfolder_$i_loop");
98
99 $mailfetch_server=$mailfetch_server_[$i_loop];
100 $mailfetch_user=$mailfetch_user_[$i_loop];
101 $mailfetch_alias=$mailfetch_alias_[$i_loop];
102 $mailfetch_pass=$mailfetch_pass_[$i_loop];
103 $mailfetch_lmos=$mailfetch_lmos_[$i_loop];
104 $mailfetch_login=$mailfetch_login_[$i_loop];
105 $mailfetch_uidl=$mailfetch_uidl_[$i_loop];
106 $mailfetch_subfolder=$mailfetch_subfolder_[$i_loop];
107
108 // $outMsg .= "$mailfetch_alias checked<br>";
109
110 // $outMsg .= "$mailfetch_alias_[$i_loop]<br>";
111
112 $pop3 = new POP3($mailfetch_server, 60);
113
114 if (!$pop3->connect($mailfetch_server)) {
115 $outMsg .= _("Warning, ") . $pop3->ERROR;
116 continue;
117 }
118
119 $imap_stream = sqimap_login($username, $key, $imapServerAddress, $imapPort, 10);
120
121 $Count = $pop3->login($mailfetch_user, $mailfetch_pass);
122 if (($Count == false || $Count == -1) && $pop3->ERROR != '') {
123 $outMsg .= _("Login Failed:") . $pop3->ERROR;
124 continue;
125 }
126
127 // register_shutdown_function($pop3->quit());
128
129 $msglist = $pop3->uidl();
130
131 $i = 1;
132 for ($j = 1; $j < sizeof($msglist); $j++) {
133 if ($msglist["$j"] == $mailfetch_uidl) {
134 $i = $j+1;
135 break;
136 }
137 }
138
139 if ($Count < $i) {
140 $pop3->quit();
141 continue;
142 }
143 if ($Count == 0) {
144 $pop3->quit();
145 continue;
146 } else {
147 $newmsgcount = $Count - $i + 1;
148 }
149
150 // Faster to get them all at once
151 $mailfetch_uidl = $pop3->uidl();
152
153 if (! is_array($mailfetch_uidl) && $mailfetch_lmos == 'on')
154 $outMsg .= _("Server does not support UIDL.");
155
156 for (; $i <= $Count; $i++) {
157 set_time_limit(20); // 20 seconds per message max
158 $Message = "";
159 $MessArray = $pop3->get($i);
160
161 if ( (!$MessArray) or (gettype($MessArray) != "array")) {
162 $outMsg .= _("Warning, ") . $pop3->ERROR;
163 continue 2;
164 }
165
166 while (list($lineNum, $line) = each ($MessArray)) {
167 $Message .= $line;
168 }
169
170 if ($mailfetch_subfolder=="") {
171 fputs($imap_stream, "A3$i APPEND INBOX {" . (strlen($Message) - 1) . "}\r\n");
172 } else {
173 fputs($imap_stream, "A3$i APPEND $mailfetch_subfolder {" . (strlen($Message) - 1) . "}\r\n");
174 }
175 $Line = fgets($imap_stream, 1024);
176 if (substr($Line, 0, 1) == '+') {
177 fputs($imap_stream, $Message);
178 sqimap_read_data($imap_stream, "A3$i", false, $response, $message);
179
180 if ($mailfetch_lmos != 'on') {
181 $pop3->delete($i);
182 }
183 } else {
184 echo "$Line";
185 $outMsg .= _("Error Appending Message!");
186 }
187 }
188
189 $pop3->quit();
190 sqimap_logout($imap_stream);
191 if (is_array($mailfetch_uidl)) {
192 setPref($data_dir,$username,"mailfetch_uidl_$i_loop", array_pop($mailfetch_uidl));
193 }
194 }
195 }
196
197 if( trim( $outMsg ) <> '' )
198 echo '<br><font size=1>' . _("Mail Fetch Result:") . "<br>$outMsg</font>";
199
200 if( $mailfetch_newlog == 'on' )
201 setPref($data_dir,$username,"mailfetch_newlog", 'off');
202
203 }
204
205 function mail_fetch_setnew() {
206
207 global $data_dir,$username;
208 // require_once ('../src/load_prefs.php');
209 // require_once ('../src/validate.php');
210 require_once('../functions/prefs.php');
211
212 if( $username <> '' ) {
213 // Creates the pref file if it does not exist.
d622d38a 214 setPref( $data_dir, $username, 'mailfetch_newlog', 'on' );
215 }
216
217 }
218
219 function mailfetch_optpage_register_block() {
220 global $optpage_blocks;
221
222 $optpage_blocks[] = array(
223 'name' => _("Simple POP3 Fetch Mail"),
224 'url' => '../plugins/mail_fetch/options.php',
225 'desc' => _("This configures settings for downloading email from a pop3 mailbox to your account on this server."),
226 'js' => false
227 );
228 }
229
165829a3 230?>