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);
 }
示例#2
1
 public function fetchStructure()
 {
     $structure = imap_fetchstructure($this->stream, $this->number);
     if (FALSE === $structure) {
         throw new Exception('FetchStructure failed: ' . imap_last_error());
     }
     return $structure;
 }
示例#3
0
 public function connect()
 {
     if (empty($this->_connectionString)) {
         $this->_connectionType = $this->_config['type'];
         switch ($this->_config['type']) {
             case 'imap':
                 $this->_connectionString = sprintf('{%s:%s%s%s}%s', $this->_config['server'], $this->_config['port'], '/' . $this->_config['type'], @$this->_config['ssl'] ? '/ssl' : '', !empty($this->_config['mailbox']) ? $this->_config['mailbox'] : '');
                 break;
             case 'pop3':
                 $this->_connectionString = sprintf('{%s:%s/pop3%s}%s', $this->_config['server'], $this->_config['port'], @$this->_config['ssl'] ? '/ssl' : '', !empty($this->_config['mailbox']) ? $this->_config['mailbox'] : '');
                 break;
         }
     }
     try {
         $this->thread = null;
         $retries = 0;
         while ($retries++ < $this->_config['retry'] && !$this->thread) {
             $this->Stream = imap_open($this->_connectionString, $this->_config['username'], $this->_config['password']);
             $this->thread = @imap_thread($this->Stream);
         }
         if (!$this->thread) {
             throw new \Exception('Unable to get imap_thread');
         }
         if (!$this->Stream) {
             throw new \Exception('Connection error: ' . imap_last_error());
         }
     } catch (Exception $e) {
         debug($e->getMessage);
     }
     return $this->_isConnected = true;
 }
示例#4
0
文件: Mailbox.php 项目: hoanghd/tools
	protected function initImapStream() {
		$imapStream = @imap_open($this->imapPath, $this->imapLogin, $this->imapPassword, $this->imapOptions, $this->imapRetriesNum, $this->imapParams);
		if(!$imapStream) {
			throw new Exception('Connection error: ' . imap_last_error());
		}
		return $imapStream;
	}
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;
        }
    }
}
示例#6
0
 /**
  * @param $mail_id
  * @param string $folder
  */
 public function moveMailToFolder($mail_id, $folder = 'INBOX/Junk')
 {
     $imapresult = imap_mail_move($this->getImapStream(), $mail_id, $folder, CP_UID);
     if (!$imapresult) {
         echo imap_last_error();
     }
 }
示例#7
0
 function open($hostname, $username, $password)
 {
     $this->con = imap_open($hostname, $username, $password);
     if (!$this->con) {
         throw new \Exception("Unable to open connection to: " . $hostname . ' error: ' . imap_last_error());
     }
 }
 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;
 }
 protected function connect()
 {
     $this->mbox = @$this->imap_open($this->imapPath, $this->login, $this->password);
     if (!$this->mbox) {
         throw new ImapMailboxException('Connection error: ' . imap_last_error());
     }
 }
示例#10
0
文件: Imapx.php 项目: nahidz/imapx
 public function connect()
 {
     $this->stream = imap_open('{' . $this->hostname . $this->port . '/' . $this->driver . $this->ssl . $this->novalidate . '}INBOX', $this->username, $this->password) or die('Cannot connect to Server: ' . imap_last_error());
     if ($this->stream) {
         $this->isConnect = true;
     }
 }
示例#11
0
 public function index()
 {
     $this->template = "";
     $this->auto_render = FALSE;
     // First is IMAP PHP Library Installed?
     $modules = new Modulecheck();
     if ($modules->isLoaded('imap')) {
         // If SSL Enabled
         $ssl = Kohana::config('settings.email_ssl') == true ? "/ssl" : "";
         // Do not validate certificates (TLS/SSL server)
         //$novalidate = strtolower(Kohana::config('settings.email_servertype')) == "imap" ? "/novalidate-cert" : "";
         $novalidate = "/novalidate-cert";
         // If POP3 Disable TLS
         $notls = strtolower(Kohana::config('settings.email_servertype')) == "pop3" ? "/notls" : "";
         $service = "{" . Kohana::config('settings.email_host') . ":" . Kohana::config('settings.email_port') . "/" . Kohana::config('settings.email_servertype') . $notls . $ssl . $novalidate . "}";
         // Connected!
         if (@imap_open($service, Kohana::config('settings.email_username'), Kohana::config('settings.email_password'), 0, 1)) {
             echo json_encode(array("status" => "success", "message" => Kohana::lang('ui_main.success')));
         } else {
             echo json_encode(array("status" => "error", "message" => Kohana::lang('ui_main.error') . " - " . imap_last_error()));
         }
     } else {
         echo json_encode(array("status" => "error", "message" => Kohana::lang('ui_main.error') . " - " . Kohana::lang('ui_admin.error_imap')));
     }
 }
示例#12
0
 /**
  * @return array
  * @throws Exception
  */
 public function getEmails()
 {
     $emails = imap_search($this->imap, 'ALL', SE_UID);
     if ($emails === false) {
         throw new Exception('Cannot get emails: ' . imap_last_error());
     }
     return $emails;
 }
示例#13
0
 public function moveMail($mailId)
 {
     $imapresult = imap_mail_move($this->getImapStream(), $mailId, 'INBOX.Archive') && $this->expungeDeletedMails();
     if ($imapresult == false) {
         error_log(imap_last_error());
     }
     return $imapresult;
 }
示例#14
0
 protected function initImapStream()
 {
     $imapStream = @imap_open($this->imapPath, $this->login, $this->password);
     if (!$imapStream) {
         throw new ImapMailboxException('Connection error: ' . imap_last_error());
     }
     return $imapStream;
 }
示例#15
0
 protected function _init_imap_stream()
 {
     $imap_stream = @imap_open($this->_full_imap_path(), $this->imap_user, $this->imap_pass);
     if (!$imap_stream) {
         throw new Exception('Connection error: ' . imap_last_error());
     }
     return $imap_stream;
 }
示例#16
0
 private function connectionopen($config)
 {
     $mbox = @imap_open('{' . $config['server'] . ':' . $config['port'] . '/' . $config['conntyp'] . '/' . $config['extras'] . '}' . $config['ordner'], $config['username'], $config['password']);
     if (!$mbox) {
         $mbox = imap_last_error();
         $this->setfehler($mbox);
     }
     return $mbox;
 }
示例#17
0
 public function connect()
 {
     $conf = Kohana::config('gmail');
     FB::log($conf, "conf");
     //{server.example.com:143/novalidate-cert}INBOX
     $this->inbox = imap_open($conf['connection']['hostname'], $conf['connection']['username'], $conf['connection']['password']) or die('Cannot connect to Gmail: ' . imap_last_error());
     FB::log($this->inbox);
     return $this;
 }
 /**
  * Destructs the connection, make sure all connections are closed
  * @return null
  */
 public function __destruct()
 {
     if (!$this->stream) {
         return;
     }
     if (!imap_close($this->stream)) {
         throw new MailException('Could not disconnect ' . $this->reference . ': ' . imap_last_error());
     }
 }
示例#19
0
 /**
  * Get information about the current mailbox
  *
  * @return object|bool
  */
 public function mailInfo()
 {
     $this->_mailInfo = imap_mailboxmsginfo($this->_connection);
     if (!$this->_mailInfo) {
         echo "get mailInfo failed: " . imap_last_error();
         return false;
     }
     return $this->_mailInfo;
 }
示例#20
0
    public function __construct($mailbox, $username, $password, $code = null, $previous = null) {
        $this->mailbox = $mailbox;
        $this->username = $username;
        $this->password = $password;
        $this->imapErrors = \imap_errors();

        $message = 'Error connecting to: '.$mailbox.' with user: '******' ['.  \imap_last_error().']';
        parent::__construct($message, $code, $previous);
    }
示例#21
0
 public function __construct($message = null, $code = 0, \Exception $previous = null)
 {
     if (null === $message) {
         $message = 'Error communicating with the IMAP server';
         if (function_exists('imap_last_error')) {
             $message .= ': ' . imap_last_error();
         }
     }
     parent::__construct($message, $code, $previous);
 }
function check_error($conn, $check_errorion, $message, $code)
{
    if (!$check_errorion) {
        fputs(STDERR, "\n{$message}\n" . imap_last_error() . "\n");
        if ($conn) {
            imap_close($conn);
        }
        exit($code);
    }
}
示例#23
0
 private function getImapConnection($username, $password, $label)
 {
     if ($inbox = imap_open(self::$hostname . $label, $username, $password)) {
         error_log("error: " . imap_last_error());
         return $inbox;
     } else {
         Logger::log("IMAP ERROR: " . imap_last_error());
         throw new Exception("");
     }
 }
示例#24
0
 /**
  * Opens an IMAP stream
  */
 public function __construct($config = array())
 {
     // Use default imap configuration when none is provided
     $config = !empty($config) ? $config : Kohana::config('imap');
     $imap_stream = imap_open($config['service'], $config['email_address'], $config['password']);
     if (!$imap_stream) {
         throw new Kohana_Exception('imap.imap_stream_not_opened', imap_last_error());
     }
     $this->imap_stream = $imap_stream;
 }
示例#25
0
function CheckMail()
{
    echo "===========================\n";
    echo " CHECK MAIL\n";
    echo "===========================\n";
    global $rawDIR, $nowGradeFile, $now;
    // 	$outFile=fopen($nowGradeFile,"w");
    $hostname = '{imap.gmail.com:993/imap/ssl}INBOX';
    $username = "******";
    $password = '******';
    /* try to connect */
    $inbox = imap_open($hostname, $username, $password) or die('Cannot connect to Gmail: ' . imap_last_error());
    /* grab emails */
    // 	$emails = imap_search($inbox, 'ALL', '*****@*****.**');
    $emails = imap_search($inbox, 'FROM noreply@wcasd.net');
    /* if emails are returned, cycle through each... */
    if ($emails) {
        /* begin output var */
        $output = '';
        /* put the newest emails on top */
        // 		rsort($emails);
        /* for every email... */
        foreach ($emails as $email_number) {
            /* get information specific to this email */
            $overview = imap_fetch_overview($inbox, $email_number, 0);
            // 			if ( $overview[0]->from == "*****@*****.**" && $overview[0]->seen == 0 ) {
            // 			if ( $overview[0]->from == "*****@*****.**" ) {
            $output .= "Number: {$email_number}\n";
            $output .= "From: " . $overview[0]->from . "\n";
            $output .= "Subject: " . $overview[0]->subject . "\n";
            $output .= "Seen: " . $overview[0]->seen . "\n";
            $output .= "Date: " . $overview[0]->date . "\n";
            $message = imap_fetchbody($inbox, $email_number, 1);
            // 				$message = imap_body($inbox, $email_number, 'FT_PEEK');
            // 				echo "MESSAGE: ". $message;
            $outFile = fopen($nowGradeFile, "w");
            fwrite($outFile, $message);
            fclose($outFile);
            if (file_exists($nowGradeFile)) {
                echo "Wrote {$nowGradeFile}.\n";
            } else {
                echo "Failed to write {$nowGradeFile}.\n";
            }
            // 				imap_setflag_full($inbox, $email_number, 'unseen');
            // 				imap_mail_move($inbox, "$email_number", 'School');
            // 				break;
            // 			}
        }
    }
    /* close the connection */
    imap_close($inbox);
    echo "{$output}\n";
    exit;
}
示例#26
0
文件: mail.php 项目: dapepe/tymio
 public function __construct($mailbox, $username, $password, $timeout = 30)
 {
     imap_timeout(IMAP_OPENTIMEOUT, $timeout);
     imap_timeout(IMAP_READTIMEOUT, $timeout);
     imap_timeout(IMAP_WRITETIMEOUT, $timeout);
     try {
         $this->count = imap_num_msg($this->imap = imap_open(\Zeyon\convert($mailbox, 'UTF7-IMAP'), \Zeyon\convert($username, 'UTF7-IMAP'), \Zeyon\convert($password, 'UTF7-IMAP'), OP_SILENT, 1));
     } catch (\Exception $e) {
         throw new \Exception('IMAP: ' . (($error = imap_last_error()) === false ? $e->getMessage() : $error));
     }
 }
示例#27
0
 /**
  * @param string $criteria
  * @param int $options
  * @param int $charset
  * @return IMAPMessage[]
  * @throws Exception
  */
 public function search($criteria, $options = NULL, $charset = NULL)
 {
     $emails = imap_search($this->stream, $criteria);
     if (FALSE === $emails) {
         throw new Exception('Search failed: ' . imap_last_error());
     }
     foreach ($emails as &$email) {
         $email = $this->getMessageByNumber($email);
     }
     return $emails;
 }
示例#28
0
 public function Open()
 {
     $resp = true;
     //'{imap.gmail.com:993/imap/ssl}INBOX'
     $imapServ = '{' . $this->imapServer . ':' . $this->portNumber . self::EMAILURLDEFAULT . "}" . 'INBOX';
     $this->imap_client = imap_open($imapServ, $this->mailUser, $this->mailPass);
     if (!$this->imap_client) {
         $resp = false;
         $this->lastError = imap_last_error();
     }
     return $resp;
 }
示例#29
0
function getMbox()
{
    $imap_user = $_SESSION['email'];
    $imap_password = $_SESSION['password'];
    try {
        $service_string = getServiceString();
        $mbox = @imap_open($service_string, $imap_user, $imap_password) or die(imap_last_error() . "<br>Connection Faliure!");
    } catch (Exception $e) {
        error_log($e);
    }
    return $mbox;
}
示例#30
-1
 /**
  * Gets the mail from the inbox
  * Reads all the messages there, and adds posts based on them. Then it deletes the entire mailbox.
  */
 function getMail()
 {
     $config = Config::current();
     if (time() - 60 * $config->emailblog_minutes >= $config->emailblog_mail_checked) {
         $hostname = '{' . $config->emailblog_server . '}INBOX';
         # this isn't working well on localhost
         $username = $config->emailblog_address;
         $password = $config->emailblog_pass;
         $subjpass = $config->emailblog_subjpass;
         $inbox = imap_open($hostname, $username, $password) or exit("Cannot connect to Gmail: " . imap_last_error());
         $emails = imap_search($inbox, 'SUBJECT "' . $subjpass . '"');
         if ($emails) {
             rsort($emails);
             foreach ($emails as $email_number) {
                 $message = imap_body($inbox, $email_number);
                 $overview = imap_headerinfo($inbox, $email_number);
                 imap_delete($inbox, $email_number);
                 $title = htmlspecialchars($overview->Subject);
                 $title = preg_replace($subjpass, "", $title);
                 $clean = strtolower($title);
                 $body = htmlspecialchars($message);
                 # The subject of the email is used as the post title
                 # the content of the email is used as the body
                 # not sure about compatibility with images or audio feathers
                 Post::add(array("title" => $title, "body" => $message), $clean, Post::check_url($clean), "text");
             }
         }
         # close the connection
         imap_close($inbox, CL_EXPUNGE);
         $config->set("emailblog_mail_checked", time());
     }
 }