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"; } }
/** * 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; }
/** * 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; } }
<?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';
/** * 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)); // 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->getServerDelimiter(), $oldid)), $newname); ZLog::Write(LOGLEVEL_ERROR, "BackendIMAP->ChangeFolder() : we do not support rename for now"); return false; } else { // build name for new mailboxBackendMaildir $displayname = Utils::Utf7_iconv_encode(Utils::Utf8_to_utf7($displayname)); if ($folderid == "0") { $newimapid = $displayname; } else { $imapid = $this->getImapIdFromFolderId($folderid); $newimapid = $imapid . $this->getServerDelimiter() . $displayname; } $csts = imap_createmailbox($this->mbox, $this->server . $newimapid); if ($csts) { imap_subscribe($this->mbox, $this->server . $newimapid); return $this->StatFolder($folderid . $this->getServerDelimiter() . $displayname); } else { ZLog::Write(LOGLEVEL_WARN, "BackendIMAP->ChangeFolder() : mailbox creation failed"); return false; } } }
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 } } }
function subscribe($_folderName, $_status) { #$this->mailPreferences['imapServerAddress'] #$this->mailPreferences['imapPort'], $folderName = $this->encodeFolderName($_folderName); $folderName = "{" . $this->mailPreferences['imapServerAddress'] . ":" . $this->mailPreferences['imapPort'] . "}" . $folderName; if ($_status == 'unsubscribe') { return imap_unsubscribe($this->mbox, $folderName); } else { return imap_subscribe($this->mbox, $folderName); } }
function create_mailbox_subfolders($login, $cleartext_password) { global $CONF; if (empty($login)) { trigger_error('In ' . __FUNCTION__ . ': empty $login', E_USER_ERROR); return FALSE; } if (!isset($CONF['create_mailbox_subdirs']) || empty($CONF['create_mailbox_subdirs'])) { return TRUE; } if (!is_array($CONF['create_mailbox_subdirs'])) { trigger_error('create_mailbox_subdirs must be an array', E_USER_ERROR); return FALSE; } if (!isset($CONF['create_mailbox_subdirs_host']) || empty($CONF['create_mailbox_subdirs_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_host = $CONF['create_mailbox_subdirs_host']; $s_options = ''; $s_port = ''; if (isset($CONF['create_mailbox_subdirs_hostoptions']) && !empty($CONF['create_mailbox_subdirs_hostoptions'])) { if (!is_array($CONF['create_mailbox_subdirs_hostoptions'])) { trigger_error('The $CONF["create_mailbox_subdirs_hostoptions"] parameter must be an array', E_USER_ERROR); return FALSE; } foreach ($CONF['create_mailbox_subdirs_hostoptions'] as $o) { $s_options .= '/' . $o; } } if (isset($CONF['create_mailbox_subdirs_hostport']) && !empty($CONF['create_mailbox_subdirs_hostport'])) { $s_port = $CONF['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, $login, $cleartext_password); if (FALSE == $i) { error_log('Could not log into IMAP/POP server: ' . imap_last_error()); return FALSE; } foreach ($CONF['create_mailbox_subdirs'] as $f) { $f = '{' . $s_host . '}INBOX.' . $f; $res = imap_createmailbox($i, $f); if (!$res) { @imap_close($i); return FALSE; } @imap_subscribe($i, $f); } @imap_close($i); return TRUE; }
public function subscribe($mailbox) { return imap_subscribe($this->stream, $mailbox); }
/** * Subscribe a mailbox * * @param string $subscribe * @return bool * @access public */ function subscribe($mailbox) { if ($this->protocol == 'POP3') { $this->errors[] = GM_NO_POP3_SUPPORT; return false; } if ($this->use_native) { $res = imap_subscribe($this->mailer, $mailbox); if (!$res) { $this->errors[] = imap_last_error(); return false; } } else { $res = $this->mailer->subscribeMailbox($mailbox); if ($res !== true) { //$this->errors[] = $res->getMessage(); return false; } } return true; }
public function createMailbox($mailbox) { $mailbox = trim($mailbox); if (!preg_match("/^[[:alnum:]-_[:blank:]]+\$/", $mailbox)) { $this->errMsg = _tr("Folder Name is Invalid"); return false; } $result = @imap_createmailbox($this->connection, @imap_utf7_encode($this->imap_ref . $mailbox)); if (!$result) { $this->errMsg = "Imap_createmailbox failed: " . @imap_last_error(); return false; } //procedemos a subscribir los mailboxs @imap_subscribe($this->connection, @imap_utf7_encode($this->imap_ref . $mailbox)); return true; }
/** * Create a full mailbox or just forward, depending on the given email address * If email matches the default domain, we create a full mailbox, otherwise we create a forward * * @param array $hookValues * @param string $action='create' * @return boolean true on success, false otherwise */ function addAccount($hookValues, $action = 'create') { //echo "<p>pleskimap::addAccount(".print_r($hookValues,true).")</p>\n"; $defaultDomain = $this->profileData['defaultDomain'] ? $this->profileData['defaultDomain'] : $GLOBALS['phpgw_info']['server']['mail_suffix']; $localEmail = $hookValues['account_lid'] . '@' . $defaultDomain; $aliases = $forwards = array(); // is the given email a local address from our default domain? if (substr($hookValues['account_email'], -1 - strlen($defaultDomain)) != '@' . $defaultDomain) { $forwards[] = $hookValues['account_email']; } elseif ($hookValues['account_email'] != $localEmail) { $aliases[] = $hookValues['account_email']; } // add a default alias with Firstname.Lastname if (!in_array($alias = $hookValues['account_firstname'] . '.' . $hookValues['account_lastname'], $aliases) && $this->is_email($alias)) { $aliases[] = $alias; } $info = $this->plesk_mail($action, $hookValues['account_lid'], $hookValues['account_passwd'], $action != 'create' && !$aliases ? null : $aliases, $forwards, $this->allways_create_mailbox); if (!$info['SUCCESS']) { return false; } if ($forwards && !$this->allways_create_mailbox) { return true; } // no mailbox created, only a forward // create Sent & Trash mailboxes and subscribe them if ($mbox = @imap_open($this->getMailboxString(), $localEmail, $hookValues['account_passwd'])) { $list = imap_getmailboxes($mbox, $this->getMailboxString(), 'INBOX'); $delimiter = isset($list[0]->delimiter) ? $list[0]->delimiter : '.'; imap_subscribe($mbox, $this->getMailboxString('INBOX')); foreach ($this->create_folders as $folder) { $mailBoxName = 'INBOX' . $delimiter . $folder; if (imap_createmailbox($mbox, imap_utf7_encode('{' . $this->profileData['imapServer'] . '}' . $mailBoxName))) { imap_subscribe($mbox, $this->getMailboxString($mailBoxName)); } } imap_close($mbox); } return true; }