function folderExists($mbox, $server, $mailbox) { $folders = imap_listmailbox($mbox, "{" . $server . "}", $mailbox); if (empty($folders)) { return false; } else { return true; } }
/** * Lista de buzones * * @return Array */ public function listMailBoxes() { $mailBoxes = imap_listmailbox($this->connect, $this->authhost, "*"); $boxerList = []; if ($mailBoxes == false) { echo "Error! en la llamada"; } else { foreach ($mailBoxes as $boxe) { $boxe = str_replace($this->authhost, '', $boxe); array_push($boxerList, $boxe); } } return $boxerList; }
function mailcwp_find_folder($mbox, $account, $name) { $found_folder = null; $mbox_name = "{$account['host']}:{$account['port']}"; $use_ssl_flag = $account["use_ssl"] ? "/ssl" : ""; //write_log($mbox_name . " - " . $use_ssl_flag); $folders = imap_listmailbox($mbox, "{" . $mbox_name . $use_ssl_flag . "}", "*"); foreach ($folders as $folder) { //write_log($folder); if (stripos($folder, $name)) { $found_folder = substr($folder, strlen($mbox_name) + strlen($use_ssl_flag) + 2); } } return $found_folder; }
function TOOLS_IMPORT_TESTS() { $uid = $_GET["uid"]; $user = new usersMenus(); $sock = new sockets(); $conf = $sock->GET_INFO("{$uid}ImportMailBoxData"); $ini = new Bs_IniHandler(); $ini->loadString($conf); if ($ini->_params["INFO"]["use_ssl"] == yes) { $dn = "{$ini->_params["INFO"]["remote_imap_server"]}:993/imap/ssl/novalidate-cert"; } else { $dn = "{$ini->_params["INFO"]["remote_imap_server"]}:143"; } $mbox = imap_open("{{$dn}}", $ini->_params["INFO"]["remote_imap_username"], $ini->_params["INFO"]["remote_imap_password"]); if (!$mbox) { $error = imap_last_error(); echo "\n\t<table style='width:100%'>\n\t\t<tr>\n\t\t\t<td width=1%><img src='img/danger24.png'></td>\n\t\t\t<td><strong style='font-size:11px'>{$error}</td>\n\t\t</tr>\n\t</table>\n\t"; return null; } $folders = imap_listmailbox($mbox, "{{$dn}}", "*"); if (!$folders) { $error = imap_last_error(); echo "\n\t<table style='width:100%'>\n\t\t<tr>\n\t\t\t<td width=1%><img src='img/danger24.png'></td>\n\t\t\t<td><strong style='font-size:11px'>{$error}</td>\n\t\t</tr>\n\t</table>\n\t"; imap_close($mbox); return null; } imap_close($mbox); $countfolder = count($folders); $tpl = new templates(); echo $tpl->_ENGINE_parse_body("\n\t<table style='width:100%'>\n\t\t<tr>\n\t\t\t<td width=1%><img src='img/ok24.png'></td>\n\t\t\t<td><strong style='font-size:11px'>{success} {$countfolder} {folder}(s)</td>\n\t\t</tr>\n\t\t<tr>\n\t\t\t<td colspan=2 align='right'><input type='button' OnClick=\"javascript:LauchMbxImport();\" value='{import_now} »'>\n\t\t</tr>\n\t</table>\n\t"); }
/** * @param $callback function that is called with parsed mail header + attachments */ function getMail($callback = '', $timeout = 30) { if (!$this->connect()) { echo "ERROR: IMAP connection to " . $this->server . ":" . $this->port . " failed\n"; return false; } $folders = imap_listmailbox($this->handle, '{' . $this->server . ':' . $this->port . '}', '*'); $msginfo = imap_mailboxmsginfo($this->handle); //dp('found '.$msginfo->Nmsgs.' messages in mailbox'); $this->tot_mails = $msginfo->Nmsgs; for ($i = 1; $i <= $this->tot_mails; $i++) { //dp("Downloading ".$i." of ".$this->tot_mails." ..."); //XXX hack because retarded imap_fetchbody() dont allow to fetch the whole message $fp = fopen('php://temp', 'w'); imap_savebody($this->handle, $fp, $i); rewind($fp); $msg = stream_get_contents($fp); fclose($fp); $mime = new MimeReader(); $mime->parseMail($msg); $this->emails[] = $mime->getAsEMail($i); } if (!function_exists($callback)) { throw new \Exception('ERROR callback function ' . $callback . ' not found'); } call_user_func($callback, $this->emails, $this); }
<?php require "IMAPv2.php"; $mbox = imap_open("{213.37.50.43:143}", "sci3432", "rafa123"); echo "<p><h1>Mailboxes</h1>\n"; $folders = imap_listmailbox($mbox, "{your.imap.host:143}", "*"); if ($folders == false) { echo "Call failed<br>\n"; } else { while (list($key, $val) = each($folders)) { echo $val . "<br>\n"; } } echo "<p><h1>Headers in INBOX</h1>\n"; $headers = imap_headers($mbox); if ($headers == false) { echo "Call failed<br>\n"; } else { while (list($key, $val) = each($headers)) { echo $val . "<br>\n"; } } imap_close($mbox);
// copy flag values into a new array $flag_user = array_search('/user', $flags); $flag_authuser = array_search('/authuser', $flags); if ($flag_user !== FALSE) { $flags[$flag_user] = '/user' . "={$_POST['username']}"; } if ($flag_authuser !== FALSE) { $flags[$flag_authuser] = '/authuser' . "={$_POST['username']}"; } $flags = implode("", $flags); } $mbox = @imap_open("{" . $_POST[host] . ":" . $_POST[port] . "{$flags}}{$_POST['mailbox']}", "{$_POST['username']}", "{$_POST['password']}") or die("Couldn't connect: " . imap_last_error()); echo "<div id=\"results\" style=\"width:650;height:200;overflow:auto;\">\n"; echo "<span style=\"color:Green;font-weight:bold\">Mailbox connection successful</span>\n"; echo "<h3>Mailboxes</h3>\n"; $folders = imap_listmailbox($mbox, "{" . $_POST[host] . ":" . $_POST[port] . "}", "*"); if ($folders == false) { echo "Mailbox call failed<br />\n"; } else { foreach ($folders as $val) { echo $val . "<br />\n"; } } echo "<h3>Headers in {$_POST['mailbox']}</h3>\n"; $headers = imap_headers($mbox); if ($headers == false) { echo "Get mail headers failed - no messages found<br />\n"; } else { foreach ($headers as $val) { echo $val . "<br />\n"; }
} else { echo 'Не удалось открыть ящик'; } } // if break; ////////////////////////////////////////////////// ////////////////////////////////////////////////// case 'mailboxes': // нет параметров // нет параметров case 'headers': // нет параметров ////////////////////////////////////////////////// if ($mbi) { $r = $cmd == 'mailboxes' ? imap_listmailbox($mbi, $ibox['mailbox'], '*') : imap_headers($mbi); if ($r) { while (list($key, $val) = each($r)) { echo "{$val}\n"; } } else { echo 'Не получилось'; } } // if break; ////////////////////////////////////////////////// ////////////////////////////////////////////////// case 'header': // $params - номер письма //////////////////////////////////////////////////
function getMailboxes() { $mstr = sprintf('{%s:%d/%s', $this->hostname, $this->port, strtolower($this->protocol)); if (!strcasecmp($this->encryption, 'SSL')) { $mstr .= '/ssl'; } $mstr .= '/novalidate-cert}'; $list = array(); if (($folders = imap_listmailbox($this->mbox, $mstr, '*')) && is_array($folders)) { foreach ($folders as $k => $folder) { $list[] = str_replace($mstr, "", imap_utf7_decode(trim($folder))); } } return $list; }
* * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU Affero General Public License for more details. * * * * You should have received a copy of the GNU Affero General Public License * * along with this program. If not, see <http://www.gnu.org/licenses/>. * * * *******************************************************************************/ if ($row = $SqlDatabase->FetchObject(' SELECT * FROM FMail WHERE UserID=\'' . $User->ID . '\' AND `Address`=\'' . $args->args->account . '\' ')) { $r = []; if ($imap = imap_open('{' . $row->Server . ':' . $row->Port . '/imap/ssl}', $row->Username, $row->Password)) { if (is_array($list = imap_listmailbox($imap, '{' . $row->Server . '}', '*'))) { for ($c = 0; $c < 2; $c++) { foreach ($list as $val) { $o = new Object(); $showName = $val; if (preg_match('/.*?\\}.*?\\./i', $showName) && $c == 1) { $showName = preg_replace('/.*?\\}.*?\\.(.*)/i', '$1', imap_utf7_decode($showName)); $o->Name = imap_utf7_decode($val); $o->DisplayName = $showName; $r[] = $o; } else { if (!preg_match('/.*?\\}.*?\\./i', $showName) && $c == 0) { $showName = preg_replace('/.*?\\}(.*)/i', '$1', imap_utf7_decode($showName)); $o->Name = imap_utf7_decode($val); $o->DisplayName = $showName; $r[] = $o;
$archivesh = "./scripts/archive.sh"; } $there = file_exists($archivesh); $empty = filesize($archivesh) == 0 ? true : false; $fp = fopen($archivesh, "a-"); if (!$there || $empty) { fwrite($fp, $script_header); } $src_imap_string = '{' . $src_server . ':143/notls}'; // Get list of mailboxes from src_server for $username $src_mbox = imap_open($src_imap_string, "{$src_username}", "{$src_password}") or die("can't connect: " . imap_last_error()); // TODO - provide the user with a checkbox for only archiving subscribed folders // array imap_listsubscribed(int imap_stream, string ref, string pattern) // $src_mbox \{$src_server} * // (Maybe imap_lsub() or imap_getsubscribed()) $list = imap_listmailbox($src_mbox, $src_imap_string, "*"); if (is_array($list)) { reset($list); } else { print "imap_listmailbox failed: " . imap_last_error() . "\n"; } while (list($key, $val) = each($list)) { $skipthis = false; $mailbox = imap_utf7_decode($val); $mailbox = mb_convert_encoding($val, "ISO_8859-1", "UTF7-IMAP"); $fullmailbox = $mailbox; $mailbox = str_replace($src_imap_string, '', $mailbox); // Skip UNIX hidden files if (preg_match("/^\\./", $mailbox)) { continue; }
function listmailbox($stream, $ref, $pattern) { //return imap_listmailbox($stream,$ref,$pattern); $pattern = $this->utf7_encode($pattern); $return_list = imap_listmailbox($stream, $ref, $pattern); return $this->utf7_decode($return_list); }