function getdata($host, $login, $password, $savedirpath) { $mbox = imap_open($host, $login, $password) or die("can't connect: " . imap_last_error()); $message = array(); $message["attachment"]["type"][0] = "text"; $message["attachment"]["type"][1] = "multipart"; $message["attachment"]["type"][2] = "message"; $message["attachment"]["type"][3] = "application"; $message["attachment"]["type"][4] = "audio"; $message["attachment"]["type"][5] = "image"; $message["attachment"]["type"][6] = "video"; $message["attachment"]["type"][7] = "other"; $buzon_destino = "cfdi"; echo imap_createmailbox($mbox, imap_utf7_encode("{$buzon_destino}")); echo imap_num_msg($mbox); for ($jk = 1; $jk <= imap_num_msg($mbox); $jk++) { $structure = imap_fetchstructure($mbox, $jk); $parts = $structure->parts; $fpos = 2; for ($i = 1; $i < count($parts); $i++) { $message["pid"][$i] = $i; $part = $parts[$i]; if (strtolower($part->disposition) == "attachment") { $message["type"][$i] = $message["attachment"]["type"][$part->type] . "/" . strtolower($part->subtype); $message["subtype"][$i] = strtolower($part->subtype); $ext = $part->subtype; $params = $part->dparameters; $filename = $part->dparameters[0]->value; if (!($ext == 'xml' or $ext == 'XML' or $ext == 'PDF' or $ext == 'pdf')) { continue; } $mege = ""; $data = ""; $mege = imap_fetchbody($mbox, $jk, $fpos); $data = $this->getdecodevalue($mege, $part->type); $fp = fopen($filename, 'w'); fputs($fp, $data); fclose($fp); $fpos += 1; /* Se mueve el archiv descargado al directorio de recibidos */ // rename($filename, $savedirpath.$filename); // printf("\nSe movio el archivo $filename"); } } $result = imap_fetch_overview($mbox, $jk); echo $result[0]->from; // imap_mail_move($mbox, $jk, $buzon_destino); //imap_delete tags a message for deletion // imap_delete($mbox,$jk); } // imap_expunge deletes all tagged messages // imap_expunge($mbox); imap_close($mbox); }
public function free($util) { $stream = imap_open("{imap.club-internet.fr:993/imap/SSL}", $util, "wrasuxwr"); var_dump($stream); $check = imap_check($stream); $list = imap_list($stream, "{imap.club-internet.fr}", "*"); imap_createmailbox($stream, '{imap.club-internet.fr}brubru'); $getmailboxes = imap_getmailboxes($stream, "{imap.club-internet.fr}", "*"); $headers = imap_headers($stream); $num_msg = imap_num_msg($stream); $status = imap_status($stream, "{imap.club-internet.fr:993/imap/SSL}INBOX", SA_ALL); $messages = imap_fetch_overview($stream, "1:" . $num_msg); $structure = imap_fetchstructure($stream, 2); $body = utf8_encode(quoted_printable_decode(imap_body($stream, '2'))); // imap_delete($stream, '1'); // imap_expunge($stream); return view('Imap.Imap')->with(compact('resource'))->with(compact('check'))->with(compact('list'))->with(compact('getmailboxes'))->with(compact('headers'))->with(compact('num_msg'))->with(compact('status'))->with(compact('errors'))->with(compact('messages'))->with(compact('structure'))->with(compact('body')); }
function store_email_into_folder($msg, $folder = 'SentFromDolibarr') { global $user, $db; $mailboxconfig = new Usermailboxconfig($db); $mailboxconfig->fetch_from_user($user->id); $user->mailbox_imap_login = $mailboxconfig->mailbox_imap_login; $user->mailbox_imap_password = $mailboxconfig->mailbox_imap_password; $user->mailbox_imap_host = $mailboxconfig->mailbox_imap_host; $user->mailbox_imap_port = $mailboxconfig->mailbox_imap_port; $user->mailbox_imap_ssl = $mailboxconfig->mailbox_imap_ssl; $user->mailbox_imap_ssl_novalidate_cert = $mailboxconfig->mailbox_imap_ssl_novalidate_cert; $user->mailbox_imap_ref = $mailboxconfig->get_ref(); $user->mailbox_imap_connector_url = $mailboxconfig->get_connector_url(); $mbox = imap_open($user->mailbox_imap_connector_url . $folder, $user->mailbox_imap_login, $user->mailbox_imap_password); $check = imap_check($mbox); $before = $check->Nmsgs; $result = imap_append($mbox, $user->mailbox_imap_connector_url . $folder, $msg); $check = imap_check($mbox); $after = $check->Nmsgs; if ($result == FALSE) { if (imap_createmailbox($mbox, imap_utf7_encode($user->mailbox_imap_ref . $folder))) { $mbox = imap_open($user->mailbox_imap_connector_url . $folder, $user->mailbox_imap_login, $user->mailbox_imap_password); $check = imap_check($mbox); $before = $check->Nmsgs; $result = imap_append($mbox, $user->mailbox_imap_connector_url . $folder, $msg); $check = imap_check($mbox); $after = $check->Nmsgs; } } imap_close($mbox); }
/** * Primary method for downloading and processing email replies */ public function download_and_process_email_replies($connection_details) { imap_timeout(IMAP_OPENTIMEOUT, apply_filters('supportflow_imap_open_timeout', 5)); $ssl = $connection_details['imap_ssl'] ? '/ssl' : ''; $ssl = apply_filters('supportflow_imap_ssl', $ssl, $connection_details['imap_host']); $mailbox = "{{$connection_details['imap_host']}:{$connection_details['imap_port']}{$ssl}}"; $inbox = "{$mailbox}{$connection_details['inbox']}"; $archive_box = "{$mailbox}{$connection_details['archive']}"; $imap_connection = imap_open($mailbox, $connection_details['username'], $connection_details['password']); $redacted_connection_details = $connection_details; $redacted_connection_details['password'] = '******'; // redact the password to avoid unnecessarily exposing it in logs $imap_errors = imap_errors(); SupportFlow()->extend->logger->log('email_retrieve', __METHOD__, $imap_connection ? __('Successfully opened IMAP connection.', 'supportflow') : __('Failed to open IMAP connection.', 'supportflow'), compact('redacted_connection_details', 'mailbox', 'imap_errors')); if (!$imap_connection) { return new WP_Error('connection-error', __('Error connecting to mailbox', 'supportflow')); } // Check to see if the archive mailbox exists, and create it if it doesn't $mailboxes = imap_getmailboxes($imap_connection, $mailbox, '*'); if (!wp_filter_object_list($mailboxes, array('name' => $archive_box))) { imap_createmailbox($imap_connection, $archive_box); } // Make sure here are new emails to process $email_count = imap_num_msg($imap_connection); if ($email_count < 1) { SupportFlow()->extend->logger->log('email_retrieve', __METHOD__, __('No new messages to process.', 'supportflow'), compact('mailboxes')); return false; } $emails = imap_search($imap_connection, 'ALL', SE_UID); $email_count = min($email_count, apply_filters('supportflow_max_email_process_count', 20)); $emails = array_slice($emails, 0, $email_count); $processed = 0; // Process each new email and put it in the archive mailbox when done. foreach ($emails as $uid) { $email = new stdClass(); $email->uid = $uid; $email->msgno = imap_msgno($imap_connection, $email->uid); $email->headers = imap_headerinfo($imap_connection, $email->msgno); $email->structure = imap_fetchstructure($imap_connection, $email->msgno); $email->body = $this->get_body_from_connection($imap_connection, $email->msgno); if (0 === strcasecmp($connection_details['username'], $email->headers->from[0]->mailbox . '@' . $email->headers->from[0]->host)) { $connection_details['password'] = '******'; // redact the password to avoid unnecessarily exposing it in logs SupportFlow()->extend->logger->log('email_retrieve', __METHOD__, __('Skipping message because it was sent from a SupportFlow account.', 'supportflow'), compact('email')); continue; } // @todo Confirm this a message we want to process $result = $this->process_email($imap_connection, $email, $email->msgno, $connection_details['username'], $connection_details['account_id']); // If it was successful, move the email to the archive if ($result) { imap_mail_move($imap_connection, $email->uid, $connection_details['archive'], CP_UID); $processed++; } } imap_close($imap_connection, CL_EXPUNGE); $status_message = sprintf(__('Processed %d emails', 'supportflow'), $processed); SupportFlow()->extend->logger->log('email_retrieve', __METHOD__, $status_message); return $status_message; }
/** * Create mailbox * * @param $name * * @return Mailbox * @throws Exception */ public function createMailbox($name) { if (\imap_createmailbox($this->resource, $this->server . $name)) { $this->mailboxNames = $this->mailboxes = null; return $this->getMailbox($name); } throw new Exception("Can not create '{$name}' mailbox at '{$this->server}'"); }
/** * Create mailbox * * @param $name * * @return Mailbox * @throws Exception */ public function createMailbox($name) { // Add support for International characters if (\imap_createmailbox($this->resource, \imap_utf7_encode($this->server . $name))) { $this->mailboxNames = $this->mailboxes = null; return $this->getMailbox($name); } throw new Exception("Can not create '{$name}' mailbox at '{$this->server}'"); }
public function createFolder($name = NULL) { $nameArr = explode(".", $name); $folders = $this->getFoldersList(); $createName = NULL; foreach ($nameArr as $v) { $createName .= !is_null($createName) ? "." : $this->getMailbox(); $createName .= $v; if (!in_array($createName, $folders)) { imap_createmailbox($this->imapStream, imap_utf7_encode($createName)); } } }
function createmailbox($mbox, $server, $mailbox) { global $src_username; $mailbox = mb_convert_encoding($mailbox, "UTF7-IMAP", "ISO_8859-1"); if (@imap_createmailbox($mbox, "{" . $server . "}{$mailbox}")) { $status = @imap_status($mbox, "{" . $server . "}" . $mailbox, SA_ALL); if ($status) { print "{$src_username} - {$mailbox}:\n"; print "UIDvalidity:" . $status->uidvalidity . "\n\n"; imap_subscribe($mbox, "{" . $server . "}{$mailbox}"); } else { print "imap_status on new mailbox - {$mailbox} failed: " . imap_last_error() . "\n"; } } else { print "could not create new mailbox - {$mailbox}: " . implode("\n", imap_errors()) . "\n"; } }
/** * This method creates, renames and deletes mailboxes from the server. * * @param string $action * One of create|rename|delete, this tells the method what you want to * do with a mailbox. * @param string $mb_name * The name of the mailbox to create, delete or rename. * @param string $mb_rename * (optional) New name for the mailbox, if it is being renamed. * * @return BOOL * @access public * @see imap_createmailbox * @see imap_renamemailbox * @see imap_deletemailbox * @tutorial http://www.smilingsouls.net/Mail_IMAP?content=Mail_IMAP_ManageMB/manageMB */ function manageMB($action, $mb_name, $mb_rename = NULL) { switch ($action) { case 'create': if (@imap_createmailbox($this->mailbox, imap_utf7_encode($this->mailboxInfo['host'] . 'INBOX.' . $mb_name))) { $ret = TRUE; } else { $this->error->push(Mail_IMAPv2_ERROR, 'error', NULL, 'Unable to create MB: ' . $mb_name); $ret = FALSE; } break; case 'rename': if (empty($mb_rename)) { $this->error->push(Mail_IMAPv2_ERROR, 'error', NULL, 'No mailbox provided to rename.'); } if (@imap_renamemailbox($this->mailbox, $this->mailboxInfo['host'] . 'INBOX.' . $mb_name, $this->mailboxInfo['host'] . 'INBOX.' . $mb_rename)) { $ret = TRUE; } else { $this->error->push(Mail_IMAPv2_ERROR, 'error', NULL, 'Unable to rename MB: ' . $mb_name); $ret = FALSE; } break; case 'delete': if (@imap_deletemailbox($this->mailbox, $this->mailboxInfo['host'] . 'INBOX.' . $mb_name)) { $ret = TRUE; } else { $this->error->push(Mail_IMAPv2_ERROR, 'error', NULL, 'Unable to delete MB: ' . $mb_name); $ret = FALSE; } break; default: $this->error->push(Mail_IMAPv2_ERROR_INVALID_ACTION, 'error', array('action' => $action, 'arg' => '$action')); $ret = FALSE; return $ret; } }
function ChangeFolder($folderid, $oldid, $displayname, $type) { debugLog("ChangeFolder: (parent: '{$folderid}' oldid: '{$oldid}' displayname: '{$displayname}' type: '{$type}')"); // go to parent mailbox $this->imap_reopenFolder($folderid); // build name for new mailbox $newname = $this->_server . str_replace(".", $this->_serverdelimiter, $folderid) . $this->_serverdelimiter . $displayname; $csts = false; // if $id is set => rename mailbox, otherwise create if ($oldid) { // rename doesn't work properly with IMAP // the activesync client doesn't support a 'changing ID' //$csts = imap_renamemailbox($this->_mbox, $this->_server . imap_utf7_encode(str_replace(".", $this->_serverdelimiter, $oldid)), $newname); } else { $csts = @imap_createmailbox($this->_mbox, $newname); } if ($csts) { return $this->StatFolder($folderid . "." . $displayname); } else { return false; } }
/** * Function to check if a mailbox exists * - if not found, it will create it * * @param string $mailbox the mailbox name, must be in 'INBOX.checkmailbox' format * @param boolean $create whether or not to create the checkmailbox if not found, defaults to true * * @return boolean */ public function mailboxExist($mailbox, $create = true) { if (trim($mailbox) == '' || !strstr($mailbox, ' INBOX.')) { // this is a critical error with either the mailbox name blank or an invalid mailbox name // need to stop processing and exit at this point echo "Invalid mailbox name for move operation. Cannot continue.<br />\n"; echo "TIP: the mailbox you want to move the message to must include 'INBOX.' at the start.<br />\n"; exit; } $port = $this->port . '/' . $this->service . '/' . $this->serviceOption; $mbox = imap_open('{' . $this->mailhost . ":" . $port . '}', $this->mailboxUserName, $this->mailboxPassword, OP_HALFOPEN); $list = imap_getmailboxes($mbox, '{' . $this->mailhost . ":" . $port . '}', "*"); $mailboxFound = false; if (is_array($list)) { foreach ($list as $key => $val) { // get the mailbox name only $nameArr = split('}', imap_utf7_decode($val->name)); $nameRaw = $nameArr[count($nameArr) - 1]; if ($mailbox == $nameRaw) { $mailboxFound = true; } } if ($mailboxFound === false && $create) { @imap_createmailbox($mbox, imap_utf7_encode('{' . $this->mailhost . ":" . $port . '}' . $mailbox)); imap_close($mbox); return true; } else { imap_close($mbox); return false; } } else { imap_close($mbox); return false; } }
/** * Moves a msg to a different folder * * @param <int> $msgId id number of the msg in current mailbox * @param <string> $new_folder new folder's name * @param <bool> $create create folder if doesn't exist ? * @return <bool> true/false according to success */ public function moveMsg($msgId, $new_folder, $create = true) { if (!$this->connectIfNeeded()) { return false; } if ($create) { @imap_createmailbox($this->connection, imap_utf7_encode('{' . $this->hostname . '}' . $new_folder)); } $success = @imap_mail_move($this->connection, $msgId, $new_folder, CP_UID); @imap_expunge($this->connection); return $success; }
/** * Create mailbox * * @param $name * * @return Mailbox * @throws Exception */ public function createMailbox($name) { if ($this->closed) { return true; } //name must be encoded in utf7 if (imap_createmailbox($this->resource, $this->server . $name)) { $this->mailboxNames = $this->mailboxes = null; return $this->getMailbox($name); } throw new Exception("Can not create '{$name}' mailbox at '{$this->server}'"); }
<?php echo "Checking with no parameters\n"; imap_lsub(); echo "Checking with incorrect parameter type\n"; imap_lsub(''); imap_lsub(false); require_once dirname(__FILE__) . '/imap_include.inc'; $stream_id = imap_open($default_mailbox, $username, $password) or die("Cannot connect to mailbox {$default_mailbox}: " . imap_last_error()); imap_lsub($stream_id); imap_lsub($stream_id, $default_mailbox); var_dump(imap_lsub($stream_id, $default_mailbox, 'ezDvfXvbvcxSerz')); echo "Checking OK\n"; $newbox = $default_mailbox . "." . $mailbox_prefix; imap_createmailbox($stream_id, $newbox); imap_subscribe($stream_id, $newbox); $z = imap_lsub($stream_id, $default_mailbox, '*'); var_dump(is_array($z)); var_dump($z[0]); imap_close($stream_id); require_once 'clean.inc';
function updateAccount($_hookValues) { #_debug_array($_hookValues); $username = $_hookValues['account_lid']; if (isset($_hookValues['new_passwd'])) { $userPassword = $_hookValues['new_passwd']; } #_debug_array($this->profileData); $imapAdminUsername = $this->profileData['imapAdminUsername']; $imapAdminPW = $this->profileData['imapAdminPW']; $folderNames = array("user.{$username}", "user.{$username}.Trash", "user.{$username}.Sent"); // create the mailbox if ($mbox = @imap_open($this->getMailboxString(), $imapAdminUsername, $imapAdminPW)) { // create the users folders foreach ($folderNames as $mailBoxName) { if (imap_createmailbox($mbox, imap_utf7_encode("{" . $this->profileData['imapServer'] . "}{$mailBoxName}"))) { if (!imap_setacl($mbox, $mailBoxName, $username, "lrswipcd")) { # log error message } } } imap_close($mbox); } else { return false; } // we can only subscribe to the folders, if we have the users password if (isset($_hookValues['new_passwd'])) { if ($mbox = @imap_open($this->getMailboxString(), $username, $userPassword)) { imap_subscribe($mbox, $this->getMailboxString('INBOX')); imap_subscribe($mbox, $this->getMailboxString('INBOX.Sent')); imap_subscribe($mbox, $this->getMailboxString('INBOX.Trash')); imap_close($mbox); } else { # log error message } } }
/** * Saves new folders * @param string $name Name of new IMAP mailbox * @param string $mbox "::" delimited IMAP mailbox path, ie, INBOX.saved.stuff * @return bool True on success */ function saveNewFolder($name, $mbox) { global $sugar_config; //Remove Folder cache global $sugar_config; //unlink("{$this->EmailCachePath}/{$this->id}/folders/folders.php"); //$mboxImap = $this->getImapMboxFromSugarProprietary($mbox); $delimiter = $this->get_stored_options('folderDelimiter'); if (!$delimiter) { $delimiter = '.'; } $newFolder = $mbox . $delimiter . $name; $mbox .= $delimiter . str_replace($delimiter, "_", $name); $connectString = $this->getConnectString('', $mbox); if (imap_createmailbox($this->conn, imap_utf7_encode($connectString))) { imap_subscribe($this->conn, imap_utf7_encode($connectString)); $status = imap_status($this->conn, str_replace("{$delimiter}{$name}", "", $connectString), SA_ALL); $this->mailbox = $this->mailbox . "," . $newFolder; $this->save(); $sessionFoldersString = $this->getSessionInboundFoldersString($this->server_url, $this->email_user, $this->port, $this->protocol); $sessionFoldersString = $sessionFoldersString . "," . $newFolder; $this->setSessionInboundFoldersString($this->server_url, $this->email_user, $this->port, $this->protocol, $sessionFoldersString); echo json_encode($status); return true; } else { echo "NOOP: could not create folder"; $GLOBALS['log']->error("*** ERROR: EMAIL2.0 - could not create IMAP mailbox with path: [ {$connectString} ]"); return false; } }
/** * Creates a new mailbox specified by mailbox. * * @return bool */ public function createMailbox() { return imap_createmailbox($this->getImapStream(), imap_utf7_encode($this->imapPath)); }
/** * mailbox_create() * On servers supporting that create a new mailbox/folder. * IMAP is an example of that. */ function mailbox_create($mailbox) { if ($this->connection == 0) { return false; } if (!imap_createmailbox($this->connection, "\\{{$this->server}:{$this->port}}{$mailbox}")) { if ($this->debug) { echo "We had problems creating the mailbox: {$ourbox}{$mailbox}<br>"; echo implode("<br />\n", imap_errors()); } return false; } return true; }
/** Sets the Current Mailfolder, Creates if Needed */ function setPath($p) { if (substr($p, 0, 1) != '{') { $p = $this->_c_host . trim($p, '/'); } $ret = imap_reopen($this->_c, $p); // Always returns true :( $buf = imap_errors(); if (empty($buf)) { return true; } $buf = implode(', ', $buf); if (preg_match('/EXIST/i', $buf)) { // Couldn't Open on Target Side, So Create $ret = imap_createmailbox($this->_c, $p); $buf = imap_errors(); if (empty($buf)) { // Reopen Again imap_reopen($this->_c, $p); return true; } die(print_r($buf, true) . "\nFailed to Create setPath({$p})\n"); } die(print_r($buf, true) . "\nFailed to Switch setPath({$p})\n"); }
/** * add new folder * * @return bool success or not * @param $name of the folder */ public function addFolder($name) { return imap_createmailbox($this->imap, $this->mailbox . $name); }
/** * Wrapper for imap_createmailbox() function. * @param $mailbox * @return bool */ public function createMailbox($mailbox) { return imap_createmailbox($this->connection->getConnection(), $mailbox); }
/** */ function makeFolder($f) { if (is_object($f)) { $f = self::folderName($f->name); } $name = sprintf('%s%s', $this->_c_host, $f); //echo "New Name: $name\n"; @imap_createmailbox($this->_c, $name); return $this->stat(); }
/** * legt eine neue Mailbox *auf dem selben Server* an * @param string $mbox * @return boolean */ public function imapCreateMailbox($mbox) { if ($this->imap === null) { throw new IMAPException(__METHOD__ . ' not connected'); } $this->imapPing(true); return imap_createmailbox($this->imap, $this->server . $mbox); }
function imap_createmailbox($_folderName, $_subscribe = False) { $mailboxString = ExecMethod('emailadmin.bo.getMailboxString', $_folderName, 3, $this->profileID); $result = @imap_createmailbox($this->mbox, $mailboxString); if ($_subscribe) { return @imap_subscribe($this->mbox, $mailboxString); } return $result; }
function createMailbox($folder) { if (!$folder) { return false; } return imap_createmailbox($this->mbox, $this->srvstr . $this->mailbox_encode(trim($folder))); }
/** * Creates a new IMAP folder. * * @param string $foldername full folder name * * @access private * @return boolean success */ private function imap_create_folder($foldername) { $name = Utils::Utf7_iconv_encode(Utils::Utf8_to_utf7($foldername)); $res = @imap_createmailbox($this->mbox, $name); if ($res) { ZLog::Write(LOGLEVEL_DEBUG, sprintf("BackendIMAP->imap_create_folder('%s'): new folder created", $foldername)); } else { ZLog::Write(LOGLEVEL_WARN, sprintf("BackendIMAP->imap_create_folder('%s'): failed to create folder: %s", $foldername, implode(", ", imap_errors()))); } return $res; }
/** * Move message to another mailbox * * @param integer $msgno Message number to move * @param string $mbox Mailbox to move message to * @return boolean */ function move($msgno, $mbox) { // Only imap supports moving of mesages if ($server_type == "imap") { $list = imap_list($this->conn, $this->server, "*"); if (!in_array($mbox, $list)) { if (!imap_createmailbox($this->conn, imap_utf7_encode($this->server . $mbox))) { // $_ENV['api']['sys']->log("Creation of $mbox mailbox failed!","mailer"); } } return imap_mail_move($this->conn, $msgno, $mbox); } else { return imap_delete($this->conn, $msgno); } }
/** * Creates or modifies a folder * The folder type is ignored in IMAP, as all folders are Email folders * * @param string $folderid id of the parent folder * @param string $oldid if empty -> new folder created, else folder is to be renamed * @param string $displayname new folder name (to be created, or to be renamed to) * @param int $type folder type * * @access public * @return boolean status * @throws StatusException could throw specific SYNC_FSSTATUS_* exceptions * */ public function ChangeFolder($folderid, $oldid, $displayname, $type) { ZLog::Write(LOGLEVEL_INFO, sprintf("BackendIMAP->ChangeFolder('%s','%s','%s','%s')", $folderid, $oldid, $displayname, $type)); // go to parent mailbox $this->imap_reopenFolder($folderid); // build name for new mailboxBackendMaildir $displayname = Utils::Utf7_iconv_encode(Utils::Utf8_to_utf7($displayname)); $newname = $this->server . $folderid . $this->serverdelimiter . $displayname; $csts = false; // if $id is set => rename mailbox, otherwise create if ($oldid) { // rename doesn't work properly with IMAP // the activesync client doesn't support a 'changing ID' // TODO this would be solved by implementing hex ids (Mantis #459) //$csts = imap_renamemailbox($this->mbox, $this->server . imap_utf7_encode(str_replace(".", $this->serverdelimiter, $oldid)), $newname); } else { $csts = @imap_createmailbox($this->mbox, $newname); } if ($csts) { return $this->StatFolder($folderid . $this->serverdelimiter . $displayname); } else { return false; } }
/** * Called by storemore() after a mailbox has been created. * Immediately returns, unless configuration indicates * that one or more sub-folders should be created. * * Triggers E_USER_ERROR if configuration error is detected. * * If IMAP login fails, the problem is logged to the system log * (such as /var/log/httpd/error_log), and the function returns * FALSE. * * Doesn't clean up, if only some of the folders could be * created. * * @return Boolean TRUE if everything succeeds, FALSE on all errors */ protected function create_mailbox_subfolders() { $create_mailbox_subdirs = Config::read('create_mailbox_subdirs'); if (empty($create_mailbox_subdirs)) { return TRUE; } if (!is_array($create_mailbox_subdirs)) { trigger_error('create_mailbox_subdirs must be an array', E_USER_ERROR); return FALSE; } $s_host = Config::read('create_mailbox_subdirs_host'); if (empty($s_host)) { trigger_error('An IMAP/POP server host ($CONF["create_mailbox_subdirs_host"]) must be configured, if sub-folders are to be created', E_USER_ERROR); return FALSE; } $s_options = ''; $create_mailbox_subdirs_hostoptions = Config::read('create_mailbox_subdirs_hostoptions'); if (!empty($create_mailbox_subdirs_hostoptions)) { if (!is_array($create_mailbox_subdirs_hostoptions)) { trigger_error('The $CONF["create_mailbox_subdirs_hostoptions"] parameter must be an array', E_USER_ERROR); return FALSE; } foreach ($create_mailbox_subdirs_hostoptions as $o) { $s_options .= '/' . $o; } } $s_port = ''; $create_mailbox_subdirs_hostport = Config::read('create_mailbox_subdirs_hostport'); if (!empty($create_mailbox_subdirs_hostport)) { $s_port = $create_mailbox_subdirs_hostport; if (intval($s_port) != $s_port) { trigger_error('The $CONF["create_mailbox_subdirs_hostport"] parameter must be an integer', E_USER_ERROR); return FALSE; } $s_port = ':' . $s_port; } $s = '{' . $s_host . $s_port . $s_options . '}'; sleep(1); # give the mail triggering the mailbox creation a chance to do its job $i = @imap_open($s, $this->id, $this->values['password']); if (FALSE == $i) { error_log('Could not log into IMAP/POP server: ' . $this->id . ': ' . imap_last_error()); return FALSE; } $s_prefix = Config::read('create_mailbox_subdirs_prefix'); foreach ($create_mailbox_subdirs as $f) { $f = '{' . $s_host . '}' . $s_prefix . $f; $res = imap_createmailbox($i, $f); if (!$res) { error_log('Could not create IMAP folder $f: ' . $this->id . ': ' . imap_last_error()); @imap_close($i); return FALSE; } @imap_subscribe($i, $f); } @imap_close($i); return TRUE; }
/** * Creates the given mailbox. * * @param $mailbox * * @return bool */ public function createMailBox($mailbox) { return imap_createmailbox($this->getImapStream(), $this->getServerSpecification() . $mailbox); }