+ }
+ echo html_tag( 'tr',
+ html_tag( 'td', ' ' ) .
+ html_tag( 'td', '<input type="submit" name="submit_mailfetch" value="' . _("Fetch Mail"). '" />', 'left' )
+ ) .
+ '</table></form>';
+}
+
+$mailfetch = Mail_Fetch_Servers();
+displayPageHeader($color);
+
+echo '<br />';
+
+echo html_tag( 'table',
+ html_tag( 'tr',
+ html_tag( 'td', '<b>' . _("Remote POP server Fetching Mail") . '</b>', 'center', $color[0] )
+ ) ,
+ 'center', '', 'width="95%" cols="1"' );
+
+
+/* there are no servers defined yet... */
+if($mailfetch['server_number'] == 0) {
+//FIXME: do not echo directly to browser -- use templates only
+ echo '<p>' . _("No POP3 servers configured yet.") . '</p>';
+ echo makeInternalLink('plugins/mail_fetch/options.php',
+ _("Click here to go to the options page.") );
+ $oTemplate->display('footer.tpl');
+ 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);
+ $oTemplate->display('footer.tpl');
+ exit();
+}
+
+if ( $server_to_fetch == 'all' ) {
+ $i_start = 0;
+ $i_stop = $mailfetch['server_number'];
+} else {
+ $i_start = $server_to_fetch;
+ $i_stop = $i_start+1;
+}
+
+for ($i_loop=$i_start;$i_loop<$i_stop;$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'];
+ $mailfetch_auth = $mailfetch[$i_loop]['auth'];
+ $mailfetch_type = $mailfetch[$i_loop]['type'];
+
+ echo '<br />' .
+ html_tag( 'table',
+ html_tag( 'tr',
+ html_tag( 'td', '<b>' .
+ sprintf(_("Fetching from %s"),
+ htmlspecialchars($mailfetch[$i_loop]['alias'])) .
+ '</b>',
+ 'center' ) ,
+ '', $color[9] ) ,
+ '', '', 'width="90%"' );
+
+ flush();
+
+ $pop3 = new mail_fetch(array('host' => $mailfetch_server,
+ 'port' => $mailfetch_port,
+ 'auth' => $mailfetch_auth,
+ 'tls' => $mailfetch_type,
+ 'timeout' => 60));
+
+ if (!empty($pop3->error)) {
+ Mail_Fetch_Status($pop3->error);
+ continue;
+ }
+
+ Mail_Fetch_Status(_("Opening IMAP server"));
+ $imap_stream = sqimap_login($username, false, $imapServerAddress, $imapPort, 10);
+
+ // check if destination folder is not set, is not subscribed and is not \noselect folder
+ if($mailfetch_subfolder == '' ||
+ ! mail_fetch_check_folder($imap_stream,$mailfetch_subfolder)) {
+ $mailfetch_subfolder = 'INBOX';
+ }
+
+ Mail_Fetch_Status(_("Opening POP server"));
+
+ /* log into pop server*/
+ if (! $pop3->login($mailfetch_user, $mailfetch_pass)) {
+ Mail_Fetch_Status(_("Login Failed:") . ' ' . htmlspecialchars($pop3->error));
+ continue;
+ }
+
+ $aMsgStat = $pop3->command_stat();
+ if (is_bool($aMsgStat)) {
+ Mail_Fetch_Status(_("Can't get mailbox status:") . ' ' . htmlspecialchars($pop3->error) );
+ continue;
+ }
+
+ $Count = $aMsgStat['count'];
+
+ $i = 1;
+
+ if ($Count>0) {
+ // If we leave messages on server, try using UIDL
+ if ($mailfetch_lmos == 'on') {
+ Mail_Fetch_Status(_("Fetching UIDL..."));
+ $msglist = $pop3->command_uidl();
+ if (is_bool($msglist)) {
+ Mail_Fetch_Status(_("Server does not support UIDL.") . ' '.htmlspecialchars($pop3->error));
+ // User asked to leave messages on server, but we can't do that.
+ $pop3->command_quit();
+ continue;
+ // $mailfetch_lmos = 'off';
+ } else {
+ // calculate number of new messages
+ for ($j = 1; $j <= sizeof($msglist); $j++) {
+ // do strict comparison ('1111.10' should not be equal to '1111.100')
+ if ($msglist[$j] === $mailfetch_uidl) {
+ $i = $j+1;
+ break;
+ }
+ }
+ }