X-Git-Url: https://vcs.fsf.org/?p=squirrelmail.git;a=blobdiff_plain;f=plugins%2Fmail_fetch%2Ffetch.php;h=898cecc0275c33c2f3c46c34e569af001278703d;hp=2510b6cb36a5d3516430e8b7e8913e5831e10133;hb=6c84ba1ec45ab854c37b6f65c5b4d84ab1c7aad4;hpb=4cf438432a1f2bfdba752e075ec6458ec3e290ba diff --git a/plugins/mail_fetch/fetch.php b/plugins/mail_fetch/fetch.php index 2510b6cb..898cecc0 100644 --- a/plugins/mail_fetch/fetch.php +++ b/plugins/mail_fetch/fetch.php @@ -1,26 +1,35 @@
'; - - echo html_tag( 'table', - html_tag( 'tr', - html_tag( 'td', '' . _("Remote POP server Fetching Mail") . '', 'center', $color[0] ) - ) , - 'center', '', 'width="95%" cols="1"' ); - - if (!isset( $server_to_fetch ) ) { - - echo '
' . - "
" . + + function Mail_Fetch_Select_Server($mailfetch) { + global $PHP_SELF; + + echo '
' . + '' . html_tag( 'table', '', 'center', '', 'width="70%" cols="2"' ) . html_tag( 'tr' ) . html_tag( 'td', _("Select Server:") . '    ', 'right' ) . html_tag( 'td', '', 'left' ) . '' . '' . ''; - + //if password not set, ask for it - for ($i=0;$i<$mailfetch_server_number;$i++) { - if ($mailfetch_pass_[$i]=='') { + for ($i = 0;$i < $mailfetch['server_number'];$i++) { + if ($mailfetch[$i]['pass'] == '') { echo html_tag( 'tr', html_tag( 'td', _("Password for") . ' ' . - (($mailfetch_alias_[$i]=='')?$mailfetch_server_[$i]:$mailfetch_alias_[$i]) . + htmlspecialchars($mailfetch[$i]['alias']) . ':     ', 'right' ) . - html_tag( 'td', '', 'left' ) + html_tag( 'td', '', 'left' ) ); } } echo html_tag( 'tr', html_tag( 'td', ' ' ) . - html_tag( 'td', '', 'left' ) - ); - + html_tag( 'td', '', 'left' ) + ) . '
'; + } + + $mailfetch = Mail_Fetch_Servers(); + displayPageHeader($color, 'None'); + + echo '
'; + + echo html_tag( 'table', + html_tag( 'tr', + html_tag( 'td', '' . _("Remote POP server Fetching Mail") . '', 'center', $color[0] ) + ) , + 'center', '', 'width="95%" cols="1"' ); + + + /* there are no servers defined yet... */ + if($mailfetch['server_number'] == 0) { + echo '

' . _("No POP3 servers configured yet.") . '

'; + displayInternalLink('plugins/mail_fetch/options.php', + _("Click here to go to the options page.") ); + echo ''; + exit(); + } + + // get $server_to_fetch from globals, if not set display a choice to the user + if (! sqgetGlobalVar('server_to_fetch', $server_to_fetch, SQ_POST) ) { + Mail_Fetch_Select_Server($mailfetch); exit(); } if ( $server_to_fetch == 'all' ) { $i_start = 0; - $i_stop = $mailfetch_server_number; + $i_stop = $mailfetch['server_number']; } else { $i_start = $server_to_fetch; - $i_stop = $i_start+1; + $i_stop = $i_start+1; } - + for ($i_loop=$i_start;$i_loop<$i_stop;$i_loop++) { - $mailfetch_server=$mailfetch_server_[$i_loop]; - $mailfetch_user=$mailfetch_user_[$i_loop]; - if ($mailfetch_pass_[$i_loop]=="") { - $tmp="pass_$i_loop"; - $mailfetch_pass=$$tmp; - } else { - $mailfetch_pass=$mailfetch_pass_[$i_loop]; + $mailfetch_server = $mailfetch[$i_loop]['server']; + $mailfetch_port = $mailfetch[$i_loop]['port']; + $mailfetch_user = $mailfetch[$i_loop]['user']; + $mailfetch_pass = $mailfetch[$i_loop]['pass']; + $mailfetch_lmos = $mailfetch[$i_loop]['lmos']; + $mailfetch_login = $mailfetch[$i_loop]['login']; + $mailfetch_uidl = $mailfetch[$i_loop]['uidl']; + $mailfetch_subfolder = $mailfetch[$i_loop]['subfolder']; + if($mailfetch_subfolder == '') { + $mailfetch_subfolder == 'INBOX'; } - $mailfetch_lmos=$mailfetch_lmos_[$i_loop]; - $mailfetch_login=$mailfetch_login_[$i_loop]; - $mailfetch_uidl=$mailfetch_uidl_[$i_loop]; - $mailfetch_subfolder=$mailfetch_subfolder_[$i_loop]; - - + $pop3 = new POP3($mailfetch_server, 60); - - echo '
' . + + echo '
' . html_tag( 'table', html_tag( 'tr', - html_tag( 'td', '' . _("Fetching from ") . - (($mailfetch_alias_[$i_loop] == '')?$mailfetch_server:$mailfetch_alias_[$i_loop]) . + html_tag( 'td', '' . _("Fetching from ") . + htmlspecialchars($mailfetch[$i_loop]['alias']) . '', 'center' ) , '', $color[9] ) , '', '', 'width="90%"' ); - + flush(); - - if (!$pop3->connect($mailfetch_server)) { + + if (!$pop3->connect($mailfetch_server,$mailfetch_port)) { Mail_Fetch_Status(_("Oops, ") . $pop3->ERROR ); continue; } - + Mail_Fetch_Status(_("Opening IMAP server")); $imap_stream = sqimap_login($username, $key, $imapServerAddress, $imapPort, 10); - + Mail_Fetch_Status(_("Opening POP server")); $Count = $pop3->login($mailfetch_user, $mailfetch_pass); if (($Count == false || $Count == -1) && $pop3->ERROR != '') { - Mail_Fetch_Status(_("Login Failed:") . ' ' . $pop3->ERROR ); + Mail_Fetch_Status(_("Login Failed:") . ' ' . htmlspecialchars($pop3->ERROR) ); continue; } - + // register_shutdown_function($pop3->quit()); - + $msglist = $pop3->uidl(); $i = 1; for ($j = 1; $j < sizeof($msglist); $j++) { - if ($msglist["$j"] == $mailfetch_uidl) { + if ($msglist[$j] == $mailfetch_uidl) { $i = $j+1; break; } @@ -174,13 +210,14 @@ continue; } else { $newmsgcount = $Count - $i + 1; - Mail_Fetch_Status(_("Login OK: Inbox contains [") . $newmsgcount . _("] messages")); + Mail_Fetch_Status(sprintf(ngettext("Login OK: Inbox contains %s message", + "Login OK: Inbox contains %s messages",$newmsgcount), $newmsgcount)); } - + Mail_Fetch_Status(_("Fetching UIDL...")); // Faster to get them all at once $mailfetch_uidl = $pop3->uidl(); - + if (! is_array($mailfetch_uidl) && $mailfetch_lmos == 'on') Mail_Fetch_Status(_("Server does not support UIDL.")); @@ -189,19 +226,21 @@ } else { Mail_Fetch_Status(_("Deleting messages from server...")); } - + for (; $i <= $Count; $i++) { Mail_Fetch_Status(_("Fetching message ") . "$i" ); - set_time_limit(20); // 20 seconds per message max - $Message = ""; + + if (!ini_get('safe_mode')) + set_time_limit(20); // 20 seconds per message max + $Message = ''; $MessArray = $pop3->get($i); - + while ( (!$MessArray) or (gettype($MessArray) != "array")) { Mail_Fetch_Status(_("Oops, ") . $pop3->ERROR); // re-connect pop3 Mail_Fetch_Status(_("Server error...Disconnect")); - $pop3->quit(); - Mail_Fetch_Status(_("Re-connect from dead connectoin")); + $pop3->quit(); + Mail_Fetch_Status(_("Reconnect from dead connection")); if (!$pop3->connect($mailfetch_server)) { Mail_Fetch_Status(_("Oops, ") . $pop3->ERROR ); Mail_Fetch_Status(_("Saving UIDL")); @@ -217,26 +256,25 @@ continue; } - Mail_Fetch_Status(_("Re-fetching message ") . "$i" ); - $MessArray = $pop3->get($i); + Mail_Fetch_Status(_("Refetching message ") . "$i" ); + $MessArray = $pop3->get($i); } // end while - + while (list($lineNum, $line) = each ($MessArray)) { $Message .= $line; } - - if ($mailfetch_subfolder=="") { - fputs($imap_stream, "A3$i APPEND INBOX {" . (strlen($Message) - 1) . "}\r\n"); - } else { - fputs($imap_stream, "A3$i APPEND \"$mailfetch_subfolder\" {" . (strlen($Message) - 1) . "}\r\n"); - } + + fputs($imap_stream, "A3$i APPEND \"$mailfetch_subfolder\" {" . strlen($Message) . "}\r\n"); $Line = fgets($imap_stream, 1024); if (substr($Line, 0, 1) == '+') { fputs($imap_stream, $Message); + fputs($imap_stream, "\r\n"); sqimap_read_data($imap_stream, "A3$i", false, $response, $message); - if ( $response <> 'OK' ) { - Mail_Fetch_Status(_("Error Appending Message!")." ".$message ); + $response=(implode('',$response)); + $message=(implode('',$message)); + if ($response != 'OK') { + Mail_Fetch_Status(_("Error Appending Message!")." ".htmlspecialchars($message) ); Mail_Fetch_Status(_("Closing POP")); $pop3->quit(); Mail_Fetch_Status(_("Logging out from IMAP")); @@ -244,20 +282,20 @@ Mail_Fetch_Status(_("Saving UIDL")); setPref($data_dir,$username,"mailfetch_uidl_$i_loop", $mailfetch_uidl[$i-1]); - exit; + exit; } else { Mail_Fetch_Status(_("Message appended to mailbox")); } - + if ($mailfetch_lmos != 'on') { if( $pop3->delete($i) ) { Mail_Fetch_Status(_("Message ") . $i . _(" deleted from Remote Server!")); } else { - Mail_Fetch_Status(_("Delete failed:") . $pop3->ERROR ); + Mail_Fetch_Status(_("Delete failed:") . htmlspecialchars($pop3->ERROR) ); } } } else { - echo "$Line"; + echo $Line; Mail_Fetch_Status(_("Error Appending Message!")); Mail_Fetch_Status(_("Closing POP")); $pop3->quit(); @@ -270,7 +308,7 @@ exit; } } - + Mail_Fetch_Status(_("Closing POP")); $pop3->quit(); Mail_Fetch_Status(_("Logging out from IMAP")); @@ -279,7 +317,7 @@ Mail_Fetch_Status(_("Saving UIDL")); setPref($data_dir,$username,"mailfetch_uidl_$i_loop", array_pop($mailfetch_uidl)); } - + Mail_Fetch_Status(_("Done")); } @@ -287,4 +325,4 @@ ?>
- + \ No newline at end of file