cbf4d9174b016d3de2222152ad4ed533680d9656
3 require_once( '../plugins/mail_fetch/functions.php' );
5 function squirrelmail_plugin_init_mail_fetch() {
6 global $squirrelmail_plugin_hooks;
7 global $mailbox, $imap_stream, $imapConnection;
9 $squirrelmail_plugin_hooks["menuline"]["mail_fetch"] = 'mail_fetch_link';
10 $squirrelmail_plugin_hooks["options_save"]["mail_fetch"] = "mail_fetch_save_pref";
11 $squirrelmail_plugin_hooks["loading_prefs"]["mail_fetch"] = "mail_fetch_load_pref";
12 $squirrelmail_plugin_hooks["login_verified"]["mail_fetch"] = "mail_fetch_setnew";
13 $squirrelmail_plugin_hooks["left_main_before"]["mail_fetch"] = "mail_fetch_login";
14 $squirrelmail_plugin_hooks['optpage_register_block']['mail_fetch'] = 'mailfetch_optpage_register_block';
18 function mail_fetch_link() {
20 displayInternalLink('plugins/mail_fetch/fetch.php', _("Fetch"), '');
25 function mail_fetch_load_pref() {
27 global $username,$data_dir;
28 global $mailfetch_server_number;
29 global $mailfetch_cypher;
30 global $mailfetch_server_,$mailfetch_alias_,$mailfetch_user_,$mailfetch_pass_;
31 global $mailfetch_lmos_, $mailfetch_uidl_, $mailfetch_login_, $mailfetch_fref_;
34 if( stristr( $PHP_SELF, 'mail_fetch' ) ) {
35 $mailfetch_server_number = getPref($data_dir, $username, "mailfetch_server_number");
36 if (!isset($mailfetch_server_number)) $mailfetch_server_number=0;
37 $mailfetch_cypher = getPref($data_dir, $username, "mailfetch_cypher");
38 if ($mailfetch_server_number<1) $mailfetch_server_number=0;
39 for ($i=0;$i<$mailfetch_server_number;$i++
) {
40 $mailfetch_server_[$i] = getPref($data_dir, $username, "mailfetch_server_$i");
41 $mailfetch_alias_[$i] = getPref($data_dir, $username, "mailfetch_alias_$i");
42 $mailfetch_user_[$i] = getPref($data_dir, $username, "mailfetch_user_$i");
43 $mailfetch_pass_[$i] = getPref($data_dir, $username, "mailfetch_pass_$i");
44 $mailfetch_lmos_[$i] = getPref($data_dir, $username, "mailfetch_lmos_$i");
45 $mailfetch_login_[$i] = getPref($data_dir, $username, "mailfetch_login_$i");
46 $mailfetch_fref_[$i] = getPref($data_dir, $username, "mailfetch_fref_$i");
47 $mailfetch_uidl_[$i] = getPref($data_dir, $username, "mailfetch_uidl_$i");
48 if( $mailfetch_cypher == 'on' ) $mailfetch_pass_[$i] = decrypt( $mailfetch_pass_[$i] );
53 function mail_fetch_save_pref() {
54 global $username,$data_dir;
55 global $mf_server, $mf_user, $mf_pass, $mf_lmos, $mf_alias;
58 global $mf_login, $mf_fref, $submit_mailfetch;
59 global $mf_action, $mf_sn, $mf_subfolder;
61 if (isset($submit_mailfetch)) {
62 if ($mf_action=="add") {
64 if ($mf_sn<1) $mf_sn=0;
65 if (!isset($mf_server)) return;
66 setPref($data_dir,$username,"mailfetch_server_$mf_sn", (isset($mf_server)?
$mf_server:""));
67 setPref($data_dir,$username,"mailfetch_alias_$mf_sn", (isset($mf_alias)?
$mf_alias:""));
68 setPref($data_dir,$username,"mailfetch_user_$mf_sn",(isset($mf_user)?
$mf_user:""));
69 setPref($data_dir,$username,"mailfetch_pass_$mf_sn",(isset($mf_pass)?
encrypt( $mf_pass ) :""));
70 if( $mf_cypher <> 'on' ) SetPref($data_dir,$username,"mailfetch_cypher", 'on');
71 setPref($data_dir,$username,"mailfetch_lmos_$mf_sn",(isset($mf_lmos)?
$mf_lmos:""));
72 setPref($data_dir,$username,"mailfetch_login_$mf_sn",(isset($mf_login)?
$mf_login:""));
73 setPref($data_dir,$username,"mailfetch_fref_$mf_sn",(isset($mf_fref)?
$mf_fref:""));
74 setPref($data_dir,$username,"mailfetch_subfolder_$mf_sn",(isset($mf_subfolder)?
$mf_subfolder:""));
76 setPref($data_dir,$username,"mailfetch_server_number", $mf_sn);
77 } elseif ($mf_action=="confirm_modify") {
79 if (!isset($mf_server)) return;
80 setPref($data_dir,$username,"mailfetch_server_$mf_sn", (isset($mf_server)?
$mf_server:""));
81 setPref($data_dir,$username,"mailfetch_alias_$mf_sn", (isset($mf_alias)?
$mf_alias:""));
82 setPref($data_dir,$username,"mailfetch_user_$mf_sn",(isset($mf_user)?
$mf_user:""));
83 setPref($data_dir,$username,"mailfetch_pass_$mf_sn",(isset($mf_pass)?
encrypt( $mf_pass ) :""));
84 if( $mf_cypher <> 'on' ) setPref($data_dir,$username,"mailfetch_cypher", 'on');
85 setPref($data_dir,$username,"mailfetch_lmos_$mf_sn",(isset($mf_lmos)?
$mf_lmos:""));
86 setPref($data_dir,$username,"mailfetch_login_$mf_sn",(isset($mf_login)?
$mf_login:""));
87 setPref($data_dir,$username,"mailfetch_fref_$mf_sn",(isset($mf_fref)?
$mf_fref:""));
88 setPref($data_dir,$username,"mailfetch_subfolder_$mf_sn",(isset($mf_subfolder)?
$mf_subfolder:""));
89 } elseif ($mf_action=="confirm_delete") {
91 $mailfetch_server_number = getPref($data_dir, $username, "mailfetch_server_number");
92 if ($mf_sn+
1==$mailfetch_server_number) {
93 //is the last server, whe can only decrase $mailfetch_server_number
94 $mailfetch_server_number--;
95 setPref($data_dir,$username,"mailfetch_server_number", $mailfetch_server_number);
97 //if not the last, all the sequel server come up one step
98 //then whe decrase $mailfetch_server_number
99 $mailfetch_server_number--;
100 for ($i=$mf_sn;$i<$mailfetch_server_number;$i++
) {
102 setPref($data_dir,$username,"mailfetch_server_$mf_sn", getPref($data_dir, $username, "mailfetch_server_$tmp"));
103 setPref($data_dir,$username,"mailfetch_alias_$mf_sn", getPref($data_dir, $username, "mailfetch_alias_$tmp"));
104 setPref($data_dir,$username,"mailfetch_user_$mf_sn", getPref($data_dir, $username, "mailfetch_user_$tmp"));
105 setPref($data_dir,$username,"mailfetch_pass_$mf_sn",(isset($mf_pass)?
encrypt( $mf_pass ) :""));
106 // if( $mf_cypher <> 'on' ) setPref($data_dir,$username,"mailfetch_cypher", 'on');
107 setPref($data_dir,$username,"mailfetch_lmos_$mf_sn", getPref($data_dir, $username, "mailfetch_lmos_$tmp"));
108 setPref($data_dir,$username,"mailfetch_login_$mf_sn", getPref($data_dir, $username, "mailfetch_login_$tmp"));
109 setPref($data_dir,$username,"mailfetch_fref_$mf_sn", getPref($data_dir, $username, "mailfetch_fref_$tmp"));
110 setPref($data_dir,$username,"mailfetch_subfolder_$mf_sn", getPref($data_dir, $username, "mailfetch_subfolder_$tmp"));
112 setPref($data_dir,$username,"mailfetch_server_number", $mailfetch_server_number);
118 function mail_fetch_login() {
120 require_once ('../src/validate.php');
121 require_once ('../functions/imap.php');
122 require_once ('../plugins/mail_fetch/class.POP3.php');
123 require_once ('../plugins/mail_fetch/functions.php');
124 require_once('../functions/i18n.php');
126 global $username, $data_dir, $key,$imapServerAddress,$imapPort;
128 $mailfetch_newlog = getPref($data_dir, $username, 'mailfetch_newlog');
132 $mailfetch_server_number = getPref($data_dir, $username, "mailfetch_server_number");
133 if (!isset($mailfetch_server_number)) $mailfetch_server_number=0;
134 $mailfetch_cypher = getPref($data_dir, $username, "mailfetch_cypher");
135 if ($mailfetch_server_number<1) $mailfetch_server_number=0;
137 for ($i_loop=0;$i_loop<$mailfetch_server_number;$i_loop++
) {
139 $mailfetch_login_[$i_loop] = getPref($data_dir, $username, "mailfetch_login_$i_loop");
140 $mailfetch_fref_[$i_loop] = getPref($data_dir, $username, "mailfetch_fref_$i_loop");
141 $mailfetch_pass_[$i_loop] = getPref($data_dir, $username, "mailfetch_pass_$i_loop");
142 if( $mailfetch_cypher == 'on' )
143 $mailfetch_pass_[$i_loop] = decrypt( $mailfetch_pass_[$i_loop] );
145 if( $mailfetch_pass_[$i_loop] <> '' && // Empty passwords no allowed
146 ( ( $mailfetch_login_[$i_loop] == 'on' && $mailfetch_newlog == 'on' ) ||
$mailfetch_fref_[$i_loop] == 'on' ) ) {
148 $mailfetch_server_[$i_loop] = getPref($data_dir, $username, "mailfetch_server_$i_loop");
149 $mailfetch_alias_[$i_loop] = getPref($data_dir, $username, "mailfetch_alias_$i_loop");
150 $mailfetch_user_[$i_loop] = getPref($data_dir, $username, "mailfetch_user_$i_loop");
151 $mailfetch_lmos_[$i_loop] = getPref($data_dir, $username, "mailfetch_lmos_$i_loop");
152 $mailfetch_uidl_[$i_loop] = getPref($data_dir, $username, "mailfetch_uidl_$i_loop");
153 $mailfetch_subfolder_[$i_loop] = getPref($data_dir, $username, "mailfetch_subfolder_$i_loop");
155 $mailfetch_server=$mailfetch_server_[$i_loop];
156 $mailfetch_user=$mailfetch_user_[$i_loop];
157 $mailfetch_alias=$mailfetch_alias_[$i_loop];
158 $mailfetch_pass=$mailfetch_pass_[$i_loop];
159 $mailfetch_lmos=$mailfetch_lmos_[$i_loop];
160 $mailfetch_login=$mailfetch_login_[$i_loop];
161 $mailfetch_uidl=$mailfetch_uidl_[$i_loop];
162 $mailfetch_subfolder=$mailfetch_subfolder_[$i_loop];
164 // $outMsg .= "$mailfetch_alias checked<br>";
166 // $outMsg .= "$mailfetch_alias_[$i_loop]<br>";
168 $pop3 = new POP3($mailfetch_server, 60);
170 if (!$pop3->connect($mailfetch_server)) {
171 $outMsg .= _("Warning, ") . $pop3->ERROR
;
175 $imap_stream = sqimap_login($username, $key, $imapServerAddress, $imapPort, 10);
177 $Count = $pop3->login($mailfetch_user, $mailfetch_pass);
178 if (($Count == false ||
$Count == -1) && $pop3->ERROR
!= '') {
179 $outMsg .= _("Login Failed:") . $pop3->ERROR
;
183 // register_shutdown_function($pop3->quit());
185 $msglist = $pop3->uidl();
188 for ($j = 1; $j < sizeof($msglist); $j++
) {
189 if ($msglist["$j"] == $mailfetch_uidl) {
203 $newmsgcount = $Count - $i +
1;
206 // Faster to get them all at once
207 $mailfetch_uidl = $pop3->uidl();
209 if (! is_array($mailfetch_uidl) && $mailfetch_lmos == 'on')
210 $outMsg .= _("Server does not support UIDL.");
212 for (; $i <= $Count; $i++
) {
213 set_time_limit(20); // 20 seconds per message max
215 $MessArray = $pop3->get($i);
217 if ( (!$MessArray) or (gettype($MessArray) != "array")) {
218 $outMsg .= _("Warning, ") . $pop3->ERROR
;
222 while (list($lineNum, $line) = each ($MessArray)) {
226 if ($mailfetch_subfolder=="") {
227 fputs($imap_stream, "A3$i APPEND INBOX {" . (strlen($Message) - 1) . "}\r\n");
229 fputs($imap_stream, "A3$i APPEND $mailfetch_subfolder {" . (strlen($Message) - 1) . "}\r\n");
231 $Line = fgets($imap_stream, 1024);
232 if (substr($Line, 0, 1) == '+') {
233 fputs($imap_stream, $Message);
234 sqimap_read_data($imap_stream, "A3$i", false, $response, $message);
236 if ($mailfetch_lmos != 'on') {
241 $outMsg .= _("Error Appending Message!");
246 sqimap_logout($imap_stream);
247 if (is_array($mailfetch_uidl)) {
248 setPref($data_dir,$username,"mailfetch_uidl_$i_loop", array_pop($mailfetch_uidl));
253 if( trim( $outMsg ) <> '' )
254 echo '<br><font size=1>' . _("Mail Fetch Result:") . "<br>$outMsg</font>";
256 if( $mailfetch_newlog == 'on' )
257 setPref($data_dir,$username,"mailfetch_newlog", 'off');
261 function mail_fetch_setnew() {
263 global $data_dir,$username;
264 // require_once ('../src/load_prefs.php');
265 // require_once ('../src/validate.php');
266 require_once('../functions/prefs.php');
268 if( $username <> '' ) {
269 // Creates the pref file if it does not exist.
270 checkForPrefs( $data_dir, $username );
271 setPref( $data_dir, $username, 'mailfetch_newlog', 'on' );
276 function mailfetch_optpage_register_block() {
277 global $optpage_blocks;
279 $optpage_blocks[] = array(
280 'name' => _("Simple POP3 Fetch Mail"),
281 'url' => '../plugins/mail_fetch/options.php',
282 'desc' => _("This configures settings for downloading email from a pop3 mailbox to your account on this server."),