-
- flush();
-
- if (!$pop3->connect($mailfetch_server)) {
- 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 );
- continue;
+
+ 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;
+ }
+ }
+ }