Exemple #1
0
 function Logoff()
 {
     if ($this->_mbox) {
         imap_close($this->_mbox);
         debugLog("IMAP connection closed");
     }
 }
Exemple #2
0
 protected function closeImap($inbox = null)
 {
     if (!$inbox) {
         $inbox = $this->inbox;
     }
     imap_close($inbox);
 }
 /**
  * Authenticates user
  * @param string $username
  * @param string $password
  * @return boolean
  */
 function authUser($username, $password)
 {
     // Returns true if the username and password work
     // and false if they are wrong or don't exist.
     $this->imapUsername = $username;
     foreach ($this->imapHosts as $host) {
         // Try each host in turn
         $host = trim($host);
         switch ($this->imapType) {
             case "imapssl":
                 $host = '{' . $host . "/imap/ssl}INBOX";
                 break;
             case "imapcert":
                 $host = '{' . $host . "/imap/ssl/novalidate-cert}INBOX";
                 break;
             case "imaptls":
                 $host = '{' . $host . "/imap/notls}INBOX";
                 break;
             default:
                 $host = '{' . $host . '}INBOX';
         }
         //error_reporting(0);
         $connection = imap_open($host, $username, $password, OP_HALFOPEN);
         if ($connection) {
             imap_close($connection);
             return true;
         }
     }
     $this->err_msg = translate('IMAP Authentication: no match');
     return false;
     // No match
 }
Exemple #4
0
 /**
  * Gets IMAP content
  *
  * @param string $imapHost
  * @param string $imapUser
  * @param string $imapPassword
  * @param \Swiftriver\Core\ObjectModel\Channel $channel
  *
  * @return $contentItems[]
  */
 private function GetIMAPContent($imapHost, $imapUser, $imapPassword, $channel)
 {
     $imapResource = imap_open("{" . $imapHost . "}INBOX", $imapUser, $imapPassword);
     //Open up unseen messages
     $imapEmails = imap_search($imapResource, strtoupper($channel->subType));
     $contentItems = array();
     if ($imapEmails) {
         //Put newest emails on top
         rsort($imapEmails);
         foreach ($imapEmails as $Email) {
             //Loop through each email and return the content
             $email_overview = imap_fetch_overview($imapResource, $Email, 0);
             $email_message = imap_fetchbody($imapResource, $Email, 2);
             $source_name = $imapUser;
             $source = \Swiftriver\Core\ObjectModel\ObjectFactories\SourceFactory::CreateSourceFromIdentifier($source_name);
             $source->name = $source_name;
             $source->parent = $channel->id;
             $source->type = $channel->type;
             $source->subType = $channel->subType;
             $item = \Swiftriver\Core\ObjectModel\ObjectFactories\ContentFactory::CreateContent($source);
             $item->text[] = new \Swiftriver\Core\ObjectModel\LanguageSpecificText(null, $email_overview[0]->subject, array($email_message));
             //the message
             $item->link = null;
             $item->date = $email_overview[0]->date;
             $contentItems[] = $item;
         }
         imap_close($imapResource);
         return $contentItems;
     }
     imap_close($imapResource);
     return null;
 }
 public static function emailDeliverFailBySubject($subject)
 {
     $mailcnf = "outlook.office365.com:993/imap/ssl/novalidate-cert";
     $username = MAILACCOUNT;
     $pw = MAILPASSWORD;
     $conn_str = "{" . $mailcnf . "}INBOX";
     $inbox = imap_open($conn_str, $username, $pw) or die('Cannot connect to mail: ' . imap_last_error());
     /* grab emails */
     $emails = imap_search($inbox, 'SUBJECT "Undeliverable: ' . $subject . '"');
     $failedInfo = [];
     /* if emails are returned, cycle through each... */
     if ($emails) {
         /* for every email... */
         foreach ($emails as $email_number) {
             /* get information specific to this email */
             $body = imap_fetchbody($inbox, $email_number, 2);
             $list = split('; ', $body);
             $sender = $list[2];
             $sender_email = explode("\n", $sender)[0];
             array_push($failedInfo, trim($sender_email));
         }
     }
     /* close the connection */
     imap_close($inbox);
     return $failedInfo;
 }
Exemple #6
0
 /**
  * Close the connection to the mail server
  *
  * @param bool $empty_trash (default true) whether to empty the trash upon exit
  *
  */
 function Close($empty_trash = true)
 {
     if ($this->do_delete && $empty_trash) {
         imap_expunge($this->mbox);
     }
     imap_close($this->mbox);
 }
 protected function disconnect()
 {
     $imapStream = $this->getImapStream(false);
     if ($imapStream && is_resource($imapStream)) {
         imap_close($imapStream, $this->expungeOnDisconnect ? CL_EXPUNGE : 0);
     }
 }
 public static function closeStreamFunc()
 {
     if (self::$currentStream) {
         AJXP_Logger::debug("Closing stream now!");
         imap_close(self::$currentStream);
     }
 }
function authenticate_imap($user, $pass)
{
    global $LOGIN_IMAP_CONNECTION;
    global $AUTH_ERR;
    if (hostname() == 'tauceti') {
        $server = '{localhost:143/imap/tls/novalidate-cert}';
    } elseif (hostname() == 'Daneel.dynamic.wondermill.com') {
        $server = '{localhost:143/imap/notls}';
    } else {
        $server = '{localhost:143/imap/tls/novalidate-cert}';
    }
    if ($c = imap_open($server, $user, $pass, OP_HALFOPEN)) {
        if (LOGIN_IMAP_KEEPCONNECTION) {
            $LOGIN_IMAP_CONNECTION =& $c;
        } else {
            //debug('Closing connection');
            imap_close($c);
        }
        return AUTH_SUCCESS;
    } else {
        if ($AUTH_ERR = imap_last_error()) {
            return AUTH_SERVFAIL;
        } else {
            return AUTH_DENY;
        }
    }
}
function readImapStatus($config, $savedStatus, $db)
{
    $mbox = imap_open($config["imap_server"], $config["imap_user"], $config["imap_password"]);
    $imapStatus = imap_status($mbox, $config["imap_server"], SA_ALL);
    // Read message IDs of UNSEEN mails
    $unseen = [];
    if ($imapStatus->unseen > 0) {
        $messages = imap_search($mbox, "UNSEEN");
        foreach ($messages as $msgID) {
            $msg = imap_headerinfo($mbox, $msgID);
            $unseen[] = $msg->message_id;
        }
    }
    imap_close($mbox);
    //
    $last_unseen = json_decode($savedStatus->unseen);
    $new_message_found = false;
    foreach ($unseen as $key => $value) {
        // Does 'unseen' contain msgID we haven't seen before?
        if (array_search($value, $last_unseen) === FALSE) {
            $new_message_found = true;
        }
    }
    // Current unseen list doesn't match saved one
    if (count($unseen) != count($last_unseen) || $new_message_found) {
        saveStatusToSqlite($db, "unseen", json_encode($unseen));
    }
    return $new_message_found;
}
Exemple #11
0
 public function disconnect()
 {
     $imapStream = $this->getImapStream(false);
     if ($imapStream && is_resource($imapStream)) {
         imap_close($imapStream, CL_EXPUNGE);
     }
 }
 function authenticate($username, $passwd)
 {
     error_reporting(error_reporting() - 2);
     if ($GLOBALS['phpgw_info']['server']['mail_login_type'] == 'vmailmgr') {
         $username = $username . '@' . $GLOBALS['phpgw_info']['server']['mail_suffix'];
     }
     if ($GLOBALS['phpgw_info']['server']['mail_server_type'] == 'imap') {
         $GLOBALS['phpgw_info']['server']['mail_port'] = '143';
     } elseif ($GLOBALS['phpgw_info']['server']['mail_server_type'] == 'pop3') {
         $GLOBALS['phpgw_info']['server']['mail_port'] = '110';
     } elseif ($GLOBALS['phpgw_info']['server']['mail_server_type'] == 'imaps') {
         $GLOBALS['phpgw_info']['server']['mail_port'] = '993';
     } elseif ($GLOBALS['phpgw_info']['server']['mail_server_type'] == 'pop3s') {
         $GLOBALS['phpgw_info']['server']['mail_port'] = '995';
     }
     if ($GLOBALS['phpgw_info']['server']['mail_server_type'] == 'pop3') {
         $mailauth = imap_open('{' . $GLOBALS['phpgw_info']['server']['mail_server'] . '/pop3' . ':' . $GLOBALS['phpgw_info']['server']['mail_port'] . '}INBOX', $username, $passwd);
     } elseif ($GLOBALS['phpgw_info']['server']['mail_server_type'] == 'imaps') {
         // IMAPS support:
         $mailauth = imap_open('{' . $GLOBALS['phpgw_info']['server']['mail_server'] . "/ssl/novalidate-cert" . ':993}INBOX', $username, $passwd);
     } elseif ($GLOBALS['phpgw_info']['server']['mail_server_type'] == 'pop3s') {
         // POP3S support:
         $mailauth = imap_open('{' . $GLOBALS['phpgw_info']['server']['mail_server'] . "/ssl/novalidate-cert" . ':995}INBOX', $username, $passwd);
     } else {
         /* assume imap */
         $mailauth = imap_open('{' . $GLOBALS['phpgw_info']['server']['mail_server'] . ':' . $GLOBALS['phpgw_info']['server']['mail_port'] . '}INBOX', $username, $passwd);
     }
     error_reporting(error_reporting() + 2);
     if ($mailauth == False) {
         return False;
     } else {
         imap_close($mailauth);
         return True;
     }
 }
Exemple #13
0
 function imapclose()
 {
     if (!$this->mbox) {
         return false;
     }
     @imap_close($this->mbox);
 }
Exemple #14
0
 public function check($touch = false)
 {
     $mbox = $this->connection();
     #echo "<h1>Nachrichten in INBOX</h1><div style=\"overflow:auto;max-height:400px;\"><pre>";
     $MC = imap_check($mbox);
     $T = new HTMLTable(1, $touch ? "Mails" : "");
     $T->setTableStyle("font-size:11px;");
     $T->useForSelection();
     $start = $MC->Nmsgs - 10;
     if ($start < 1) {
         $start = 1;
     }
     $result = imap_fetch_overview($mbox, "{$start}:{$MC->Nmsgs}", 0);
     $result = array_reverse($result);
     foreach ($result as $overview) {
         #print_r($overview);
         $T->addRow(array("\n\t\t\t\t<small style=\"color:grey;float:right;\">" . Util::CLDateParser($overview->udate) . "</small>\n\t\t\t\t" . str_replace("\"", "", $this->decodeBlubb($overview->from)) . "<br />\n\t\t\t\t<small style=\"color:grey;\">" . substr($this->decodeBlubb($overview->subject), 0, 50) . "</small>"));
         $T->addCellEvent(1, "click", "\$j('#MailFrame').attr('src', './interface/rme.php?class=MailCheck&constructor=" . $this->getID() . "&method=showMailBody&parameters=\\'{$overview->uid}\\'');");
     }
     imap_close($mbox);
     #echo "</pre></div>";
     $BC = "";
     if ($touch) {
         $BC = new Button("Fenster\nschließen", "stop");
         $BC->style("float:right;margin:10px;");
         $BC->onclick(OnEvent::closePopup("MailCheck"));
     }
     echo "<div style=\"float:right;width:300px;\">";
     echo $BC;
     echo "<p>{$MC->Nmsgs} Nachricht" . ($MC->Nmsgs == 1 ? "" : "en") . "</p><div style=\"clear:both;\"></div>";
     echo $T;
     echo "</div>";
     echo "\n\t\t\t<div style=\"border-right-style:solid;border-right-width:1px;width:699px;\" class=\"borderColor1\">\n\t\t\t\t<iframe id=\"MailFrame\" style=\"border:0px;width:699px;height:520px;\" src=\"./fheME/MailCheck/Home/index.html\"></iframe>\n\t\t\t</div>";
     echo "<div style=\"clear:both;\"></div>";
 }
Exemple #15
0
 function handleJSON_getContent($smarty, $module_name, $appletlist)
 {
     $respuesta = array('status' => 'success', 'message' => '(no message)');
     // Leer credenciales a partir del usuario y el perfil asociado
     global $arrConf;
     $dbAcl = new paloDB($arrConf["elastix_dsn"]["acl"]);
     $pACL = new paloACL($dbAcl);
     $userId = $pACL->getIdUser($_SESSION['elastix_user']);
     $mailCred = $this->leerPropiedadesWebmail($dbAcl, $userId);
     if (count($mailCred) <= 0) {
         $respuesta['status'] = 'error';
         $respuesta['message'] = _tr("You don't have a webmail account");
     } elseif (!$this->_checkEmailPassword("{$mailCred['login']}@{$mailCred['domain']}", isset($mailCred['password']) ? $mailCred['password'] : '')) {
         $respuesta['status'] = 'error';
         $respuesta['message'] = "{$mailCred['login']}@{$mailCred['domain']} " . _tr("does not exist locally or password is incorrect");
     } else {
         $imap = @imap_open("{localhost:143/notls}", "{$mailCred['login']}@{$mailCred['domain']}", isset($mailCred['password']) ? $mailCred['password'] : '');
         if (!$imap) {
             $respuesta['status'] = 'error';
             $respuesta['message'] = _tr('Imap: Connection error');
         } else {
             $this->leerInformacionImap($smarty, $module_name, $imap, $respuesta);
             imap_close($imap);
         }
     }
     $json = new Services_JSON();
     Header('Content-Type: application/json');
     return $json->encode($respuesta);
 }
Exemple #16
0
 function __destruct()
 {
     // You will have iMap errors, even if there are no
     // mails on the server.  This suppresses that error.
     imap_errors();
     imap_close($this->connection);
 }
Exemple #17
0
 public function close()
 {
     if ($this->isOpen()) {
         imap_close($this->_imapStream, CL_EXPUNGE);
         $this->_open = false;
     }
 }
Exemple #18
0
 public function __destruct()
 {
     if (!$this->resource) {
         return;
     }
     imap_close($this->resource);
 }
Exemple #19
0
 /**
  * Gets IMAP content
  *
  * @param string $imapHost
  * @param string $imapUser
  * @param string $imapPassword
  * @param \Swiftriver\Core\ObjectModel\Channel $channel
  *
  * @return $contentItems[]
  */
 private function GetIMAPContent($imapHost, $imapUser, $imapPassword, $channel)
 {
     $imapResource = imap_open("{" . $imapHost . "}INBOX", $imapUser, $imapPassword);
     //Open up unseen messages
     $search = $channel->lastSuccess == null ? "UNSEEN" : "UNSEEN SINCE " . \date("Y-m-d", $channel->lastSuccess);
     $imapEmails = imap_search($imapResource, $search);
     $contentItems = array();
     if ($imapEmails) {
         //Put newest emails on top
         rsort($imapEmails);
         foreach ($imapEmails as $Email) {
             //Loop through each email and return the content
             $email_overview = imap_fetch_overview($imapResource, $Email, 0);
             if (strtotime(reset($email_overview)->date) < $channel->lastSuccess) {
                 continue;
             }
             $email_header_info = imap_header($imapResource, $Email);
             $email_message = imap_fetchbody($imapResource, $Email, 1);
             $source_name = \reset($email_overview)->from;
             $source = \Swiftriver\Core\ObjectModel\ObjectFactories\SourceFactory::CreateSourceFromIdentifier($source_name);
             $source->name = $source_name;
             $source->parent = $channel->id;
             $source->type = $channel->type;
             $source->subType = $channel->subType;
             $item = \Swiftriver\Core\ObjectModel\ObjectFactories\ContentFactory::CreateContent($source);
             $item->text[] = new \Swiftriver\Core\ObjectModel\LanguageSpecificText(null, $email_overview[0]->subject, array($email_message));
             //the message
             $item->link = null;
             $item->date = $email_header_info->udate;
             $contentItems[] = $item;
         }
     }
     imap_close($imapResource);
     return $contentItems;
 }
Exemple #20
0
 /**
  * Authenticate user/password
  *
  * @access  public
  * @param   string  $user       User's name or email
  * @param   string  $password   User's password
  * @return  mixed   Array of user's information otherwise Jaws_Error
  */
 function Auth($user, $password)
 {
     if (!function_exists('imap_open')) {
         return Jaws_Error::raiseError('Undefined function imap_open()', __FUNCTION__);
     }
     $mbox = @imap_open('{' . $this->_Server . ':' . $this->_Port . ($this->_SSL ? '/imap/ssl' : '') . '}INBOX', $user, $password);
     if ($mbox) {
         @imap_close($mbox);
         $result = array();
         $result['id'] = strtolower('imap:' . $user);
         $result['internal'] = false;
         $result['username'] = $user;
         $result['superadmin'] = false;
         $result['internal'] = false;
         $result['groups'] = array();
         $result['nickname'] = $user;
         $result['concurrents'] = 0;
         $result['email'] = '';
         $result['url'] = '';
         $result['avatar'] = 'gadgets/Users/Resources/images/photo48px.png';
         $result['language'] = '';
         $result['theme'] = '';
         $result['editor'] = '';
         $result['timezone'] = null;
         return $result;
     }
     return Jaws_Error::raiseError(_t('GLOBAL_ERROR_LOGIN_WRONG'), __FUNCTION__);
 }
Exemple #21
0
 public function close()
 {
     if (!$this->isConnect) {
         return false;
     }
     imap_close($this->stream);
 }
 public function disconnect()
 {
     if (!$this->box) {
         return false;
     }
     imap_close($this->box, CL_EXPUNGE);
 }
Exemple #23
0
 public function __construct($email_addr, $host, $user, $pass, $exitifnoemails = 1)
 {
     error_reporting(0);
     if (!function_exists('imap_mail')) {
         echo '<p class="error">IMAP MAIL EXTENSION IS NOT AVAILABLE ON THIS SERVER!</p>';
         //exit;
         return false;
         # No need to exit entire page as other things might be there.
     }
     // End function.
     //$this->conn = imap_open ("{{$host}:143/notls}Inbox", $email_addr, $pass);
     $this->conn = imap_open("{{$host}:143/notls}Inbox", $user, $pass);
     //$this->conn = imap_open ("{{$host}:143}", $user, $pass);
     if (!$this->conn) {
         // Error occurred while try to connect:
         echo '<p class="error">Could not access mailbox</p>';
         //var_dump(imap_errors());
         imap_close($this->conn);
         exit;
     }
     // End if.
     // Get the number of mails on the server:
     $this->num_emails = imap_num_msg($this->conn);
     if ($this->num_emails == 0) {
         echo '<p class="error">No emails in mailbox</p>';
         imap_close($this->conn);
         if ($exitifnoemails) {
             exit;
         }
     }
     // End if.
 }
Exemple #24
0
 /**
  * Check if the password is correct without logging in the user
  *
  * @param string $uid      The username
  * @param string $password The password
  *
  * @return true/false
  */
 public function checkPassword($uid, $password)
 {
     if (!function_exists('imap_open')) {
         OCP\Util::writeLog('user_external', 'ERROR: PHP imap extension is not installed', OCP\Util::ERROR);
         return false;
     }
     // Check if we only want logins from ONE domain and strip the domain part from UID
     if ($this->domain != '') {
         $pieces = explode('@', $uid);
         if (count($pieces) == 1) {
             $username = $uid . "@" . $this->domain;
         } elseif (count($pieces) == 2 and $pieces[1] == $this->domain) {
             $username = $uid;
             $uid = $pieces[0];
         } else {
             return false;
         }
     } else {
         $username = $uid;
     }
     $mbox = @imap_open($this->mailbox, $username, $password, OP_HALFOPEN, 1);
     imap_errors();
     imap_alerts();
     if ($mbox !== FALSE) {
         imap_close($mbox);
         $uid = mb_strtolower($uid);
         $this->storeUser($uid);
         return $uid;
     } else {
         return false;
     }
 }
Exemple #25
0
function imap_test_connect($host,$user,$pass,$timeout=-1,$protocol="imap",$port=-1,$ssl=false,$debug=false)
{
global $NATS;
if ($timeout>0) $timeout=$timeout; // use specific for test if set
else
	{
	// otherwise use system if available
	if (isset($NATS)) $timeout=$NATS->Cfg->Get("test.imap.timeout",0);
	if ($timeout<=0) $timeout=0; // unset specifically or in environment
	}
	
if ($timeout>0) imap_timeout(IMAP_OPENTIMEOUT,$timeout);

if ($port<=0)
	{
	$port=143; // default
	if ( ($protocol=="imap") && ($ssl) ) $port=993;
	else if ($protocol=="pop3")
		{
		if ($ssl) $port=995;
		else $port=110;
		}
	}

$mailbox="{".$host.":".$port."/service=".$protocol;
if ($ssl) $mailbox.="/ssl";
$mailbox.="/novalidate-cert";
$mailbox.="}INBOX";
if ($debug) echo $user.":".$pass."@".$mailbox."\n";
$imap=@imap_open($mailbox,$user,$pass);
if ($imap===false) return 0;

@imap_close($imap);
return 1;
}
Exemple #26
0
 public function closeMailServerConnection()
 {
     if (!isset(self::$_mailServerConnection)) {
         imap_close(self::$_mailServerConnection);
         self::$_mailServerConnection = null;
     }
 }
 public function disconnect()
 {
     if ($this->connection != false) {
         imap_close($this->connection);
     }
     return $this;
 }
 public function fetch(MailCriteria $criteria, $callback)
 {
     $mailbox = @imap_open('{' . $this->host . ':' . $this->port . '}INBOX', $this->username, $this->password);
     if (!$mailbox) {
         throw new ImapException("Cannot connect to imap server: {$this->host}:{$this->port}'");
     }
     $this->checkProcessedFolder($mailbox);
     $emails = $this->fetchEmails($mailbox, $criteria);
     if ($emails) {
         foreach ($emails as $emailIndex) {
             $overview = imap_fetch_overview($mailbox, $emailIndex, 0);
             $message = imap_body($mailbox, $emailIndex);
             $email = new Email($overview, $message);
             $processed = $callback($email);
             if ($processed) {
                 $res = imap_mail_move($mailbox, $emailIndex, $this->processedFolder);
                 if (!$res) {
                     throw new \Exception("Unexpected error: Cannot move email to ");
                     break;
                 }
             }
         }
     }
     @imap_close($mailbox);
 }
Exemple #29
-1
 public function getMailBox()
 {
     $mailboxes = array('label' => 'Gmail', 'enable' => true, 'mailbox' => '{imap.gmail.com:993/ssl}[Gmail]/Sent Mail', 'username' => '*****@*****.**', 'password' => '4N?@vwJn@resijt');
     $stream = imap_open($mailboxes['mailbox'], $mailboxes['username'], $mailboxes['password']);
     if (!$stream) {
         return 'err1';
         //return Redirect::back()->withInput()->withErrors('An error occured. Please try again.');
     }
     $emails = imap_search($stream, 'ALL');
     if (!$emails) {
         return 'err2';
     } else {
         rsort($emails);
     }
     $emailList = array();
     $count = 0;
     foreach ($emails as $item) {
         $overview = imap_fetch_overview($stream, $item, 0);
         $emailList[$count] = $overview;
         $emailList[$count]['agoTime'] = Carbon::createFromTimestampUTC(strtotime($overview[0]->date))->diffForHumans();
         $count++;
     }
     imap_close($stream);
     return $emailList;
 }
Exemple #30
-4
    function validate($user, $pass, $challenge, $response)
    {
        parent::validate($user, $pass, $challenge, $response);
        $mailbox = '{' . $this->mConfig['server'];
        if ($this->mConfig["ssl"]) {
            $mailbox .= "/ssl";
            if ($this->mConfig["sslvalidate"]) {
                $mailbox .= "/validate-cert";
            } else {
                $mailbox .= "/novalidate-cert";
            }
        }
        $mailbox .= ':' . $this->mConfig["port"] . '}INBOX';
        $imapauth = @imap_open($mailbox, $user, $pass);
        if (!$imapauth) {
            $this->mErrors['login'] = imap_errors();
            $ret = USER_NOT_FOUND;
        } else {
            $ret = USER_VALID;
            $this->mInfo["real_name"] = $user;
            if (empty($this->mConfig["email"])) {
                $this->mInfo["email"] = $user;
            } else {
                $info = array('login' => $user);
                $replace_func = create_function('$matches', '$info = ' . var_export($info, true) . ';
							$m = $matches[0];
							$m = substr($m,1,strlen($m)-2);
							if(empty($info[$m])) return "";
							return strtolower($info[$m]);');
                $this->mInfo["email"] = preg_replace_callback('/%.*?%/', $replace_func, $this->mConfig["email"]);
            }
            imap_close($imapauth);
        }
        return $ret;
    }