コード例 #1
0
function ws_pfemail_mailbox_test($params, &$service)
{
    global $conf;
    require_once PFEMAIL_PATH . 'include/ImapMailbox.php';
    try {
        $mailbox = new ImapMailbox($params['path'], $params['login'], $params['password'], $conf['upload_dir'] . '/buffer', 'utf-8');
        $info = $mailbox->checkMailbox();
    } catch (Exception $e) {
        return array('error' => $e->getMessage());
    }
    return $info;
}
コード例 #2
0
// Requirements
require_once 'classes/ImapMailbox.php';
require_once 'classes/pushbullet.class.php';
// E-mail settings
define('MAIL_PATH', '{localhost:143}INBOX');
// See classes/ImapMailbox.php for some examples
define('MAIL_EMAIL', '*****@*****.**');
// Your e-mail username
define('MAIL_PASSWORD', 'password');
// Your e-mail password
// PushBullet settings
$PushBullet_API_key = 'pushbullet_api_key_goes_here';
$deviceIds = array('device_id_1', 'device_id_2', 'device_id_3');
// Start readin the mailbox
$mailbox = new ImapMailbox(MAIL_PATH, MAIL_EMAIL, MAIL_PASSWORD, false, 'utf-8');
// Get all e-mails from the mailbox
$mailsIds = $mailbox->searchMailBox('ALL');
if ($mailsIds) {
    // Read each mail individually
    foreach ($mailsIds as $mailId) {
        $mail = $mailbox->getMail($mailId);
        // Send the PushBullet notifications
        try {
            $p = new PushBullet($PushBullet_API_key);
            // Send a notification to each device
            foreach ($deviceIds as $deviceId) {
                $p->pushNote($deviceId, $mail->subject, $mail->textPlain);
            }
            // Delete the mail from the folder
            $mailbox->deleteMail($mailId);
コード例 #3
0
ファイル: Mailbox.php プロジェクト: mglaman/mail
 public function __construct($imapPath, $login, $password, $attachmentsDir = null, $serverEncoding = 'utf-8')
 {
     parent::__construct($imapPath, $login, $password, $attachmentsDir, $serverEncoding);
 }
コード例 #4
0
ファイル: ImapMessage.php プロジェクト: ajaboa/crmpuan
 /**
  * Find's messages in a given mailbox
  * 
  * @param Account $account
  * @param string $mailbox
  * @param int $start
  * @param int $limit
  * @param sring $sortField See constants in \GO\Base\Mail\Imap::SORT_*
  * @param boolean $descending Sort descending
  * @param string $query
  * @param string $searchIn In what folder(s) are we searching ('current', 'all', 'recursive')
  * @return array
  */
 public function find(Account $account, $mailbox = "INBOX", $start = 0, $limit = 50, $sortField = \GO\Base\Mail\Imap::SORT_DATE, $descending = true, $query = 'ALL', $searchIn = 'current')
 {
     $results = array();
     if ($searchIn == "all") {
         foreach ($account->getRootMailboxes(false, true) as $mailbox) {
             //only search visable mailboxes not subscriptions
             if (!$mailbox->isVisible() || $mailbox->noselect) {
                 continue;
             }
             $results = array_merge($results, $this->find($account, $mailbox->name, $start, $limit, $sortField, $descending, $query, 'recursive'));
         }
         return $results;
     }
     /** @var $imap \GO\Base\Mail\Imap */
     $imap = $account->openImapConnection($mailbox);
     $headersSet = $imap->get_message_headers_set($start, $limit, $sortField, $descending, $query);
     foreach ($headersSet as $uid => $headers) {
         $message = ImapMessage::model()->createFromHeaders($account, $mailbox, $headers);
         $results[] = $message;
     }
     \GO::debug($mailbox);
     //find recursive in subfolders
     if ($searchIn === 'recursive') {
         $mailboxObj = new ImapMailbox($account, array('name' => $mailbox));
         $children = $mailboxObj->getChildren(true, false);
         foreach ($children as $child) {
             //only search visible mailboxes not subscriptions
             if (!$child->isVisible() || $child->noselect) {
                 continue;
             }
             $results = array_merge($results, $this->find($account, $child->name, $start, $limit, $sortField, $descending, $query, 'recursive'));
         }
     }
     return $results;
 }
コード例 #5
0
ファイル: ReadEmail.php プロジェクト: xepan/communication
 function fetch($mailbox_name, $conditions = null)
 {
     $imap_email_host = $this->email_setting['imap_email_host'];
     $imap_email_port = $this->email_setting['imap_email_port'];
     $imap_email_username = $this->email_setting['imap_email_username'];
     $imap_email_password = $this->email_setting['imap_email_password'];
     $imap_flags = $this->email_setting['imap_flags'];
     try {
         $mailbox = new ImapMailbox('{' . $imap_email_host . ':' . $imap_email_port . $imap_flags . '}' . $mailbox_name, $imap_email_username, $imap_email_password, "websites/" . $this->app->epan['name'] . "/upload", 'utf-8');
         if ($this->debug) {
             echo "Connected<br/>";
         }
         $return = [];
         $conditions = $conditions ?: 'UNSEEN';
         $mailsIds = $mailbox->searchMailBox($conditions);
         if (!$mailsIds) {
             $mailbox->disconnect();
             if ($this->debug) {
                 echo "<br/>NO {$conditions} found returning <br/>";
             }
             return $return;
         }
         if ($this->debug) {
             echo "has " . count($mailsIds) . " Emails<br/>";
         }
         $i = 1;
         $fetch_email_array = array();
         foreach ($mailsIds as $mailId) {
             if ($this->debug) {
                 echo "Getting email <br/>";
             }
             $fetched_mail = $mailbox->getMail($mailId);
             if ($this->debug) {
                 echo "got email <br/>";
             }
             $attach_email_files = [];
             //MAIL ATTACHME  NT
             $attachments = $fetched_mail->getAttachments();
             foreach ($attachments as $attach) {
                 $file = $this->add('xepan/filestore/Model_File', array('policy_add_new_type' => true, 'import_mode' => 'move', 'import_source' => $attach->filePath));
                 $file['filestore_volume_id'] = $file->getAvailableVolumeID();
                 $file['original_filename'] = $attach->name;
                 $file->save();
                 $attach_email_files[$attach->id] = ['file_id' => $file->id, 'path' => $file['url'], 'type' => 'attach'];
             }
             $mail_m = $this->add('xepan\\communication\\Model_Communication_Email_Received');
             $mail_m->addCondition('uid', $fetched_mail->id);
             $mail_m->addCondition('mailbox', $this->email_setting['imap_email_username'] . '#' . $mailbox_name);
             $mail_m->tryLoadAny();
             if ($mail_m->loaded()) {
                 if ($this->debug) {
                     echo "<br/> UID " . $fetched_mail->id . " found existed in " . $this->email_setting['imap_email_username'] . '#' . $mailbox_name . " continuing <br/>";
                 }
                 continue;
             }
             $mail_m->setFrom($fetched_mail->fromAddress, $fetched_mail->fromName);
             /*Fetch TO Email Array & Convert To array name or email format*/
             $to_email_arry = $fetched_mail->to;
             foreach ($to_email_arry as $email => $name) {
                 $mail_m->addTo($email, $name);
             }
             /*Fetch CC Email Array & Convert To array name or email format*/
             $cc_email_array = $fetched_mail->cc;
             foreach ($cc_email_array as $email => $name) {
                 $mail_m->addCc($email, $name);
             }
             if (isset($fetched_mail->bcc)) {
                 $bcc_email_array = $fetched_mail->bcc;
                 foreach ($bcc_email_array as $email => $name) {
                     $mail_m->addBcc($email, $name);
                 }
             }
             $email_content = $fetched_mail->textHtml ?: $fetched_mail->textPlain;
             foreach ($attach_email_files as $e_id => $detail) {
                 // var_dump($email_content);
                 if (strpos($email_content, 'cid:' . $e_id) != false) {
                     // echo 'cid:'.$e_id ." <br/> Path :   " . $detail['path'] ."<br/> <br/>";
                     $email_content = str_replace('cid:' . $e_id, $detail['path'], $email_content);
                     $attach_email_files[$e_id]['type'] = 'inline';
                 }
             }
             // echo "string" . $email_content;
             $mail_m['created_at'] = $fetched_mail->date;
             $mail_m['title'] = $fetched_mail->subject;
             $mail_m['description'] = $email_content;
             $mail_m['flags'] = $conditions;
             $mail_m->findContact('from');
             if ($this->debug) {
                 echo "Saving email <br/>";
             }
             $mail_m->save();
             if ($this->email_setting['auto_reply']) {
                 if ($this->debug) {
                     echo "Doing auto reply <br/>";
                 }
                 $mail_m->reply($this->email_setting);
             }
             $fetch_email_array[] = $mail_m->id;
             if (!isset($return['fetched_emails_from'])) {
                 $return['fetched_emails_from'] = $mail_m->id;
             }
             foreach ($attach_email_files as $eid => $detail) {
                 $mail_m->addAttachment($detail['file_id'], $detail['type']);
             }
             $mail_m->unload();
             $i++;
         }
     } catch (\Exception $e) {
         $mailbox->disconnect();
         echo $e->getMessage() . '<br/>';
     }
     $mailbox->disconnect();
     return $return;
 }
コード例 #6
0
ファイル: EmailReply.php プロジェクト: akhilrs/QuSolPMC
include_once '../Vendor/ElephantIO/Client.php';
define('LOG_PATH', '../tmp/logs/os-email.log');
$config = new DATABASE_CONFIG();
$settings = $config->{'default'};
/* Database  connection */
$cfg["db_host"] = $settings['host'];
$cfg["db_user"] = $settings['login'];
$cfg["db_pass"] = $settings['password'];
$cfg["db_name"] = $settings['database'];
/* Email server connection */
$username = FROM_EMAIL_NOTIFY;
$password = '******';
$hostname = '{imap.gmail.com:993/ssl}INBOX';
/* try to connect */
$inbox = imap_open($hostname, $username, $password) or die("Couldn't get your Emails: " . imap_last_error());
$mailbox = new ImapMailbox($hostname, $username, $password);
/* grab emails */
$emails = imap_search($inbox, 'UNSEEN');
/* if emails are returned, cycle through each… */
if ($emails) {
    $output = '';
    /* put the newest emails on top */
    rsort($emails);
    //echo "Number of email:".imap_num_msg($inbox);
    $mysql_pconnect = mysql_pconnect($cfg["db_host"], $cfg["db_user"], $cfg["db_pass"]);
    if (!$mysql_pconnect) {
        echo "Database Connection Failed";
        exit;
    }
    $db = mysql_select_db($cfg["db_name"], $mysql_pconnect);
    if (!$db) {
コード例 #7
0
 private function PHPParseEmails(&$_reload, $_delete, $_test)
 {
     $list = array();
     $starttime = time();
     $executiontime = Server::SetTimeLimit(CALLER_TIMEOUT - 10);
     try {
         $ssl = $this->Mailbox->SSL == 0 ? "" : ($this->Mailbox->SSL == 1 ? '/ssl' : '/tls');
         $service = $this->Mailbox->Type == "IMAP" ? "imap" : "pop3";
         $mailbox = new ImapMailbox('{' . $this->Mailbox->Host . ':' . $this->Mailbox->Port . '/' . $service . $ssl . '}INBOX', $this->Mailbox->Username, $this->Mailbox->Password, "./uploads/", 'utf-8');
         $mails = $mailbox->searchMailBox('ALL');
         if ($_test) {
             return count($mails);
         }
         if (empty($mails)) {
             return array();
         }
         $counter = 0;
         foreach ($mails as $mailId) {
             $subject = "";
             try {
                 $temail = new TicketEmail();
                 $message = $mailbox->getMail($mailId);
                 $subject = $temail->Subject = $message->subject;
                 //$temail->Id = $message->id;
                 $temail->Id = $message->message_id;
                 $temail->Name = $message->fromName;
                 if (empty($temail->Id)) {
                     $temail->Id = getId(32);
                 }
                 if ($_delete) {
                     $delete[$mailId] = $temail->Id;
                 }
                 $temail->Email = trim($message->fromAddress);
                 reset($message->to);
                 $temail->ReceiverEmail = key($message->to);
                 if (!empty($message->replyTo)) {
                     reset($message->replyTo);
                     $temail->ReplyTo = key($message->replyTo);
                 }
                 $temail->BodyHTML = $message->textHtml;
                 $temail->Body = $message->textPlain;
                 if (empty($temail->Body) && !empty($temail->BodyHTML)) {
                     $temail->Body = MailSystem::DownConvertHTML($temail->BodyHTML);
                 }
                 $atts = $message->getAttachments();
                 foreach ($atts as $att) {
                     $filename = $att->name;
                     $fileid = getId(32);
                     $filesid = Server::$Configuration->File["gl_lzid"] . "_" . $fileid;
                     $content = file_get_contents($att->filePath);
                     $temail->Attachments[$fileid] = array($filesid, $filename, $content);
                     @unlink($att->filePath);
                 }
                 $temail->Created = strtotime($message->date);
                 if (!is_numeric($temail->Created) || empty($temail->Created)) {
                     $temail->Created = time();
                 }
                 $list[] = $temail;
                 if (time() - $starttime >= $executiontime / 2 || $counter++ > DATA_ITEM_LOADS) {
                     $_reload = true;
                     break;
                 }
             } catch (Exception $e) {
                 if ($_test) {
                     throw $e;
                 } else {
                     handleError("115", "Email Error: " . $e->getMessage() . ", email: " . $subject, "functions.global.inc.php", 0);
                 }
             }
         }
         try {
             krsort($delete);
             foreach ($delete as $num => $id) {
                 $mailbox->deleteMail($num);
             }
         } catch (Exception $e) {
             if ($_test) {
                 throw $e;
             } else {
                 handleError("114", "Email delete error: " . $e->getMessage() . ", email: " . $subject, "functions.global.inc.php", 0);
             }
         }
     } catch (Exception $e) {
         if ($_test) {
             throw $e;
         } else {
             handleError("113", "Email Error: " . $e->getMessage() . ", email: " . $subject, "functions.global.inc.php", 0);
         }
     }
     return $list;
 }
コード例 #8
0
ファイル: Imap.php プロジェクト: rtsantos/mais
 /**
  * Remove uma mensagem da caixa postal
  *
  * @param string $mailId
  * @return bool
  * @throws Exception 
  */
 public function deleteMail($mailId)
 {
     @($result = parent::deleteMail($this->_getNumMessage($mailId)));
     if (!$result) {
         set_time_limit(3);
         throw new Exception('deleteMail Error: ' . imap_last_error());
     }
     return $result;
 }
コード例 #9
0
ファイル: CheckEmail.comp.php プロジェクト: carriercomm/jbs
    #-------------------------------------------------------------------------------
}
#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
$Server = SPrintF("{%s/%s/%s}INBOX", $ServerSettings['Address'], $ServerSettings['Params']['Method'], $ServerSettings['Protocol'] == 'ssl' ? 'ssl/novalidate-cert' : 'notls');
#-------------------------------------------------------------------------------
$attachmentsDir = SPrintF('%s/hosts/%s/tmp/imap', SYSTEM_PATH, HOST_ID);
#-------------------------------------------------------------------------------
if (!File_Exists($attachmentsDir)) {
    MkDir($attachmentsDir, 0700, true);
}
#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
try {
    #-------------------------------------------------------------------------------
    $mailbox = new ImapMailbox($Server, $ServerSettings['Login'], $ServerSettings['Password'], $attachmentsDir);
    #-------------------------------------------------------------------------------
} catch (Exception $e) {
    #-------------------------------------------------------------------------------
    Debug(SPrintF('[comp/Tasks/CheckEmail]: Exception = %s', $e->getMessage()));
    return 3600;
    #-------------------------------------------------------------------------------
}
#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
$GLOBALS['TaskReturnInfo'][] = SPrintF('%s messages', SizeOf($mailbox->searchMailbox()));
#-------------------------------------------------------------------------------
Debug(SPrintF('[comp/Tasks/CheckEmail]: сообщений = %s', SizeOf($mailbox->searchMailbox())));
#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
$Mails = $mailbox->searchMailbox();
コード例 #10
0
ファイル: check_fae_sdi.php プロジェクト: andreabia/gazie
echo ' ';
}
 

$admin_aziend=checkAdmin();
set_time_limit(3600);
global $gTables;
// IMAP  
$cemail = gaz_dbi_get_row($gTables['company_config'],'var','cemail');
$cpassword = gaz_dbi_get_row($gTables['company_config'],'var','cpassword');
$cfiltro = gaz_dbi_get_row($gTables['company_config'],'var','cfiltro');
$cpopimap = gaz_dbi_get_row($gTables['company_config'],'var','cpopimap');
$last_fae_email = gaz_dbi_get_row($gTables['company_config'],'var','last_fae_email');
define('CATTACHMENTS_DIR',  '../../data/files/ricevutesdi');

$mailbox = new ImapMailbox($cpopimap['val'], $cemail['val'], $cpassword['val'], CATTACHMENTS_DIR, 'utf-8');
$mails = array();

//se passato checkall verranno riscaricate tutte le email senza tener conto dell'eventule filtro: UNSEEN (solo non lette) 
if (isset($_GET['checkall'])) {
   $cfiltro['val'] = str_replace("UNSEEN","", $cfiltro['val']);
}


// Get some mail
$mailsIds = $mailbox->searchMailBox($cfiltro['val'] );
if(!$mailsIds) {
	echo('Nessuna nuova email con questo filtro: ' . $cfiltro['val']);
  die("<p align=\"center\"><a href=\"./report_fae_sdi.php\">Ritorna a report Fatture elettroniche</a></p>");
}