Esempio n. 1
0
function unreadMessages($messages)
{
    $mbox = getMbox();
    $messages = uidToSecuence($mbox, $messages);
    imap_clearflag_full($mbox, $messages, '\\Seen');
    imap_close($mbox);
}
Esempio n. 2
0
 public function unFlag($flag)
 {
     return imap_clearflag_full($this->ImapFolder->Imap->stream, $this->uid, $flag, ST_UID);
 }
Esempio n. 3
0
function processAllEmails($mailbox, $emails, $rucReceptor)
{
    $returnArray = array("status" => true, "html" => "");
    $handlerUserCore = new UserCore();
    rsort($emails);
    $returnArray["html"] .= '   <table class="table table-condensed table-striped">
                                    <thead>
                                        <tr>
                                            <th>ID</th>
                                            <th>Remitente</th>
                                            <th>Fecha</th>
                                            <th>Docs.</th>
                                            <th>Estado</th>
                                            <th>Proc.</th>
                                        </tr>
                                    </thead>
                                    <tbody>';
    foreach ($emails as $email_number) {
        $status = '';
        // Traer datos generales de e-mail
        $overview = imap_fetch_overview($mailbox, $email_number, 0);
        //$message = imap_fetchbody($mailbox, $email_number, 2);
        $structure = imap_fetchstructure($mailbox, $email_number);
        $attachments = getEmailAttachments($mailbox, $email_number, $structure);
        $returnArray["html"] .= '<tr>';
        $returnArray["html"] .= '<td style="font-size: 11px;">' . $email_number . '</td>';
        $returnArray["html"] .= '<td style="font-size: 11px;">' . $overview[0]->from . '</td>';
        $returnArray["html"] .= '<td style="font-size: 11px;">' . date("Y-m-d", strtotime($overview[0]->date)) . '</td>';
        $returnArray["html"] .= '<td style="font-size: 11px;">' . count($attachments) . '</td>';
        $status .= '<ul class="pointmark" style="margin: 0px;">';
        if (count($attachments) > 0) {
            // Leer cada adjunto XML y procesarlo
            foreach ($attachments as $attachment) {
                if (strtolower($attachment["xml_extension"]) == "xml") {
                    $validArray = processXmlString($attachment["xml_attachment"], $attachment["pdf_attachment"], $attachment["pdf_extension"], $rucReceptor, $attachment["xml_basename"]);
                    $processed = $validArray["status"];
                }
                if ($processed) {
                    $status .= "<li>Adjunto XML (" . $attachment["xml_basename"] . "): Procesado con éxito</li>";
                } else {
                    $status .= "<li>" . $validArray["html"] . "</li>";
                }
            }
        } else {
            $status .= "<li>E-mail no tiene adjuntos</li>";
            $processed = false;
            $usuarioDefault = FlowSettingsCore::get(FLOW_RECEPCIONDOCUMENTOS, "RDE_DEF_ASIGNACION");
            $usuarioData = $handlerUserCore->getUserData($usuarioDefault);
            $email = $usuarioData["user_email"];
            $html = 'Estimado usuario<br /><br />
                     Le informamos que tiene un nuevo documento electrónico descargable en el buzón. Por favor ingrese a revisarlo y darle tratamiento';
            MailController::sendGeneralMail([["email" => $email]], "Nuevo documento electrónico descargable", $html);
        }
        $status .= '</ul>';
        if (FlowSettingsCore::get(FLOW_RECEPCIONDOCUMENTOS, "RDE_MC_PRUEBAS") != "1") {
            setEmailRead($email_number, $rucReceptor);
        } else {
            imap_clearflag_full($mailbox, $email_number, "\\Seen");
        }
        $returnArray["html"] .= '<td style="font-size: 11px;">' . $status . '</td>';
        if ($processed) {
            $returnArray["html"] .= '<td><span class="awe-ok" style="color: #6b9b20;"></span></td>';
        } else {
            $returnArray["html"] .= '<td><span class="awe-remove" style="color: #d43f3f;"></span></td>';
        }
        $returnArray["html"] .= '</tr>';
    }
    $returnArray["html"] .= "</table>";
    return $returnArray;
}
Esempio n. 4
0
 function flagMessages($flag, $aMessagesUID)
 {
     if (empty($aMessagesUID)) {
         return false;
     }
     reset($aMessagesUID);
     $msglist = '';
     while (list($key, $value) = each($aMessagesUID)) {
         if (!empty($msglist)) {
             $msglist .= ",";
         }
         $msglist .= $value;
     }
     switch ($flag) {
         case "flagged":
             $result = imap_setflag_full($this->stream(), $msglist, "\\Flagged", ST_UID);
             break;
         case "read":
             $result = imap_setflag_full($this->stream(), $msglist, "\\Seen", ST_UID);
             break;
         case "answered":
             $result = imap_setflag_full($this->stream(), $msglist, "\\Answered", ST_UID);
             break;
         case "unflagged":
             $result = imap_clearflag_full($this->stream(), $msglist, "\\Flagged", ST_UID);
             break;
         case "unread":
             $result = imap_clearflag_full($this->stream(), $msglist, "\\Seen", ST_UID);
             $result = imap_clearflag_full($this->stream(), $msglist, "\\Answered", ST_UID);
             break;
     }
     return $result;
 }
Esempio n. 5
0
 /**
  * This function is used to enable or disable one or more flags on the imap message.
  *
  * @param  string|array              $flag   Flagged, Answered, Deleted, Seen, Draft
  * @param  bool                      $enable
  * @throws \InvalidArgumentException
  * @return bool
  */
 public function setFlag($flag, $enable = true)
 {
     $flags = is_array($flag) ? $flag : array($flag);
     foreach ($flags as $i => $flag) {
         $flag = ltrim(strtolower($flag), '\\');
         if (!in_array($flag, self::$flagTypes) || $flag == self::FLAG_RECENT) {
             throw new \InvalidArgumentException('Unable to set invalid flag "' . $flag . '"');
         }
         if ($enable) {
             $this->status[$flag] = true;
         } else {
             unset($this->status[$flag]);
         }
         $flags[$i] = $flag;
     }
     $imapifiedFlag = '\\' . implode(' \\', array_map('ucfirst', $flags));
     if ($enable === true) {
         return imap_setflag_full($this->imapStream, $this->uid, $imapifiedFlag, ST_UID);
     } else {
         return imap_clearflag_full($this->imapStream, $this->uid, $imapifiedFlag, ST_UID);
     }
 }
Esempio n. 6
0
function mailcwp_mark_unread_callback()
{
    $mailcwp_session = mailcwp_get_session();
    if (!isset($mailcwp_session) || empty($mailcwp_session)) {
        return;
    }
    $account = $mailcwp_session["account"];
    //$from = $account["email"];
    $folder = $mailcwp_session["folder"];
    $messages = $_POST["messages"];
    $mbox = mailcwp_imap_connect($account, 0, $folder);
    imap_clearflag_full($mbox, $messages, "\\Seen");
    //mailcwp_get_unseen_messages($account);
    //write_log(print_r(imap_errors(), true));
    echo json_encode(array("result" => "OK"));
    die;
}
Esempio n. 7
0
 /**
  * Marks the mail as Unread
  * @param <String> $msgno - Message Number
  */
 function markMailUnread($msgno)
 {
     imap_clearflag_full($this->mBox, $msgno, '\\Seen');
     $this->mModified = true;
 }
Esempio n. 8
0
 /**
  * Called when the user moves an item on the PDA from one folder to another
  *
  * @param string              $folderid            id of the source folder
  * @param string              $id                  id of the message
  * @param string              $newfolderid         id of the destination folder
  * @param ContentParameters   $contentparameters
  *
  * @access public
  * @return boolean                      status of the operation
  * @throws StatusException              could throw specific SYNC_MOVEITEMSSTATUS_* exceptions
  */
 public function MoveMessage($folderid, $id, $newfolderid, $contentparameters)
 {
     ZLog::Write(LOGLEVEL_DEBUG, sprintf("BackendIMAP->MoveMessage('%s','%s','%s')", $folderid, $id, $newfolderid));
     $folderImapid = $this->getImapIdFromFolderId($folderid);
     $newfolderImapid = $this->getImapIdFromFolderId($newfolderid);
     if ($folderImapid == $newfolderImapid) {
         throw new StatusException(sprintf("BackendIMAP->MoveMessage('%s','%s','%s'): Error, destination folder is source folder. Canceling the move.", $folderid, $id, $newfolderid), SYNC_MOVEITEMSSTATUS_SAMESOURCEANDDEST);
     }
     $this->imap_reopen_folder($folderImapid);
     if ($this->imap_inside_cutoffdate(Utils::GetCutOffDate($contentparameters->GetFilterType()), $id)) {
         // read message flags
         $overview = @imap_fetch_overview($this->mbox, $id, FT_UID);
         if (!is_array($overview)) {
             throw new StatusException(sprintf("BackendIMAP->MoveMessage('%s','%s','%s'): Error, unable to retrieve overview of source message: %s", $folderid, $id, $newfolderid, imap_last_error()), SYNC_MOVEITEMSSTATUS_INVALIDSOURCEID);
         } else {
             // get next UID for destination folder
             // when moving a message we have to announce through ActiveSync the new messageID in the
             // destination folder. This is a "guessing" mechanism as IMAP does not inform that value.
             // when lots of simultaneous operations happen in the destination folder this could fail.
             // in the worst case the moved message is displayed twice on the mobile.
             $destStatus = imap_status($this->mbox, $this->server . $newfolderImapid, SA_ALL);
             if (!$destStatus) {
                 throw new StatusException(sprintf("BackendIMAP->MoveMessage('%s','%s','%s'): Error, unable to open destination folder: %s", $folderid, $id, $newfolderid, imap_last_error()), SYNC_MOVEITEMSSTATUS_INVALIDDESTID);
             }
             $newid = $destStatus->uidnext;
             // move message
             $s1 = imap_mail_move($this->mbox, $id, $newfolderImapid, CP_UID);
             if (!$s1) {
                 throw new StatusException(sprintf("BackendIMAP->MoveMessage('%s','%s','%s'): Error, copy to destination folder failed: %s", $folderid, $id, $newfolderid, imap_last_error()), SYNC_MOVEITEMSSTATUS_CANNOTMOVE);
             }
             // delete message in from-folder
             $s2 = imap_expunge($this->mbox);
             // open new folder
             $stat = $this->imap_reopen_folder($newfolderImapid);
             if (!$stat) {
                 throw new StatusException(sprintf("BackendIMAP->MoveMessage('%s','%s','%s'): Error, opening the destination folder: %s", $folderid, $id, $newfolderid, imap_last_error()), SYNC_MOVEITEMSSTATUS_CANNOTMOVE);
             }
             // remove all flags
             $s3 = @imap_clearflag_full($this->mbox, $newid, "\\Seen \\Answered \\Flagged \\Deleted \\Draft", FT_UID);
             $newflags = "";
             $move_to_trash = strcasecmp($newfolderImapid, $this->create_name_folder(IMAP_FOLDER_TRASH)) == 0;
             if ($overview[0]->seen || $move_to_trash && defined('IMAP_AUTOSEEN_ON_DELETE') && IMAP_AUTOSEEN_ON_DELETE == true) {
                 $newflags .= "\\Seen";
             }
             if ($overview[0]->flagged) {
                 $newflags .= " \\Flagged";
             }
             if ($overview[0]->answered) {
                 $newflags .= " \\Answered";
             }
             $s4 = @imap_setflag_full($this->mbox, $newid, $newflags, FT_UID);
             ZLog::Write(LOGLEVEL_DEBUG, sprintf("BackendIMAP->MoveMessage('%s','%s','%s'): result s-move: '%s' s-expunge: '%s' unset-Flags: '%s' set-Flags: '%s'", $folderid, $id, $newfolderid, Utils::PrintAsString($s1), Utils::PrintAsString($s2), Utils::PrintAsString($s3), Utils::PrintAsString($s4)));
             // return the new id "as string"
             return $newid . "";
         }
     } else {
         throw new StatusException(sprintf("BackendIMAP->MoveMessage(): Message is outside the sync range"), SYNC_MOVEITEMSSTATUS_INVALIDSOURCEID);
     }
 }
Esempio n. 9
0
 /**
  * This function is used to enable or disable a flag on the imap message.
  *
  * @param string $flag Flagged, Answered, Deleted, Seen, Draft
  * @param bool $enable
  * @return bool
  */
 public function set_flag($flag, $enable = TRUE)
 {
     if (!in_array($flag, self::$flag_types) or $flag == 'recent') {
         throw new Imap_Exception('Unable to set invalid flag "' . $flag . '"');
     }
     $flag = '\\' . ucfirst($flag);
     if ($enable) {
         return imap_setflag_full($this->imap_stream, $this->uid, $flag, ST_UID);
     } else {
         return imap_clearflag_full($this->imap_stream, $this->uid, $flag, ST_UID);
     }
 }
 function flagMessages($_flag, $_messageUID)
 {
     reset($_messageUID);
     while (list($key, $value) = each($_messageUID)) {
         if (!empty($msglist)) {
             $msglist .= ",";
         }
         $msglist .= $value;
     }
     switch ($_flag) {
         case "flagged":
             $result = imap_setflag_full($this->mbox, $msglist, "\\Flagged", ST_UID);
             break;
         case "read":
             $result = imap_setflag_full($this->mbox, $msglist, "\\Seen", ST_UID);
             break;
         case "answered":
             $result = imap_setflag_full($this->mbox, $msglist, "\\Answered", ST_UID);
             break;
         case "unflagged":
             $result = imap_clearflag_full($this->mbox, $msglist, "\\Flagged", ST_UID);
             break;
         case "unread":
             $result = imap_clearflag_full($this->mbox, $msglist, "\\Seen", ST_UID);
             $result = imap_clearflag_full($this->mbox, $msglist, "\\Answered", ST_UID);
             break;
     }
     #print "Result: $result<br>";
 }
Esempio n. 11
0
    /*
    print $seq;
    print $_POST["moveto"];
    print $res;
    */
} else {
    if ($act == "flags") {
        if (isset($_POST["msgmark"])) {
            $seq = join(",", array_keys($_POST["msgmark"]));
        }
        $flag = $_POST["flag"];
        if ("read" == $flag) {
            imap_setflag_full($mbox, $seq, "\\Seen", ST_UID);
        }
        if ("unread" == $flag) {
            imap_clearflag_full($mbox, $seq, "\\Seen", ST_UID);
        }
        print "[\n";
        if (isset($_REQUEST["msgids"])) {
            $ovr = imap_fetch_overview($mbox, $_REQUEST["msgids"], FT_UID);
            foreach ($ovr as $mkey => $msgobj) {
                printf("{'type': 'mflag', 'msgid': '%d', 'seen': %d, 'answered': %d},\n", $msgobj->uid, $msgobj->seen, $msgobj->answered);
            }
        }
        $mboxinf = imap_status($mbox, $mboxspec, SA_ALL);
        $msg_total = $mboxinf->messages;
        $msg_unread = $mboxinf->unseen;
        printf("{'type': 'mbox', 'caption': '%s', 'name': '%s', 'total': %d, 'unread': %d},\n", get_folder_caption($mailbox), $mailbox, $msg_total, $msg_unread);
        print "];";
        // edasi .. see asi peab tagastama packeti iga mailboxis olnud kirja kohta, sest mõni neist võib olla
        // muutunud loetuks mõnel muul moel .. s.t. siis query_server peab tagastama kõik kirjad,
Esempio n. 12
0
 /**
  * Wrapper function for {@link imap_setflag_full}.  Sets various message flags.
  * Accepts an array of message ids and an array of flags to be set.
  *
  * The flags which you can set are "\\Seen", "\\Answered", "\\Flagged",
  * "\\Deleted", and "\\Draft" (as defined by RFC2060).
  *
  * Warning: POP3 mailboxes do not remember flag settings from connection to connection.
  *
  * @param    array  $mids        Array of message ids to set flags on.
  * @param    array  $flags       Array of flags to set on messages.
  * @param    int    $action      Flag operation toggle one of MAIL_IMAP_SET_FLAGS (default) or
  *                               MAIL_IMAP_CLEAR_FLAGS.
  * @param    int    $options
  *   (optional) sets the forth argument of {@link imap_setflag_full} or {@imap_clearflag_full}.
  *
  * @return   BOOL|PEAR_Error
  * @throws   Message IDs and Flags are to be supplied as arrays.  Remedy: place message ids
  *           and flags in arrays.
  * @access   public
  * @see      imap_setflag_full
  * @see      imap_clearflag_full
  */
 function setFlags($mids, $flags, $action = 3, $options = NULL)
 {
     if (is_array($mids) && is_array($flags)) {
         if ($action == MAIL_IMAP_SET_FLAGS) {
             if (isset($this->option['setflag_full'])) {
                 $options = $this->option['setflag_full'];
             }
             return @imap_setflag_full($this->mailbox, implode(',', $mids), implode(' ', $flags), $options);
         } else {
             if (isset($this->option['clearflag_full'])) {
                 $options = $this->option['clearflag_full'];
             }
             return @imap_clearflag_full($this->mailbox, implode(',', $mids), implode(' ', $flags), $options);
         }
     } else {
         return PEAR::raiseError('Mail_IMAP::setFlags: First and second arguments must be arrays.');
     }
 }
Esempio n. 13
0
function mail_SetFlag($conn, $mail, $flag)
{
    switch ($flag) {
        case 'Seen':
            return @imap_setflag_full($conn, $mail, "\\Seen", SE_UID);
            break;
        case 'Unseen':
            return @imap_clearflag_full($conn, $mail, "\\Seen", SE_UID);
            break;
        case 'Flagged':
            return @imap_setflag_full($conn, $mail, "\\Flagged", SE_UID);
            break;
        case 'Unflagged':
            return @imap_clearflag_full($conn, $mail, "\\Flagged", SE_UID);
            break;
        case 'Delete':
            mail_dele($conn, $mail);
            break;
        case 'Draft':
            return @imap_setflag_full($conn, $mail, "\\Draft", SE_UID);
            break;
        case 'Answerd':
            return @imap_setflag_full($conn, $mail, "\\Answered", SE_UID);
            break;
        default:
            return false;
    }
}
Esempio n. 14
0
 public function clearFLag($str, $list)
 {
     if (empty($list) || gettype($list) != 'array') {
         return 'Nieprawidłowy format danych wejsciowych';
     }
     $xy = implode(",", $list);
     imap_clearflag_full($this->mbox, $xy, $str, ST_UID);
 }
 /**
  * Remove a flag que caracteriza uma mensagem como alertada por Filtro por Remetente.
  * se houver o parametro msg_number, então remove a flag de uma msg especifica
  * se não houver o parametro msg_number, mas sim o from, então remove a flag de todas as msgs da pasta (parametro from),
  * e que o remetente for o from.
  */
 function removeFlagMessagesFilter($params)
 {
     $message_number = $params['msg_number'];
     $folder = $params['folder'];
     if (isset($message_number)) {
         if (isset($folder)) {
             $message_number = explode(',', $message_number);
             $this->mbox = $this->open_mbox($folder);
             foreach ($message_number as $k => $m) {
                 imap_clearflag_full($this->mbox, $m, '$FilteredMessage', ST_UID);
             }
         }
     } else {
         $from = $params['from'];
         if (isset($folder) && isset($from)) {
             $this->mbox = $this->open_mbox($folder);
             $messages = imap_search($this->mbox, 'UNDELETED UNSEEN KEYWORD "$FilteredMessage"', SE_UID);
         }
         if (is_array($messages)) {
             foreach ($messages as $k => $m) {
                 $headers = imap_fetch_overview($this->mbox, $m, FT_UID);
                 if (strpos($headers[0]->from, $from) > 0) {
                     imap_clearflag_full($this->mbox, $m, '$FilteredMessage', ST_UID);
                 }
             }
         }
     }
     return array('status' => "success");
 }
Esempio n. 16
0
 function getBody($msg_number)
 {
     $header = imap_headerinfo($this->mbox_stream, imap_msgno($this->mbox_stream, $msg_number), 80, 255);
     $body = imap_body($this->mbox_stream, $msg_number, FT_UID);
     if ($header->Unseen == 'U' || $header->Recent == 'N') {
         imap_clearflag_full($this->mbox_stream, $msg_number, "\\Seen", ST_UID);
     }
     return $body;
 }
Esempio n. 17
0
 /**
  * Called when the user moves an item on the PDA from one folder to another
  *
  * @param string              $folderid            id of the source folder
  * @param string              $id                  id of the message
  * @param string              $newfolderid         id of the destination folder
  * @param ContentParameters   $contentparameters
  *
  * @access public
  * @return boolean                      status of the operation
  * @throws StatusException              could throw specific SYNC_MOVEITEMSSTATUS_* exceptions
  */
 public function MoveMessage($folderid, $id, $newfolderid, $contentparameters)
 {
     ZLog::Write(LOGLEVEL_DEBUG, sprintf("BackendIMAP->MoveMessage('%s','%s','%s')", $folderid, $id, $newfolderid));
     $folderImapid = $this->getImapIdFromFolderId($folderid);
     // SDB: When iOS is configured to "Archive Message" (instead of Delete Message), it will send a "MoveItems"
     // command to the Exchange server and attempt to move it to a folder called "0/Archive". Instead, we trap that
     // and send it to "[Gmail]/All Mail" folder instead. Note, that when on iOS device and you trigger a move from
     // folder A to B, it will correctly move that email, including to all folders with "[Gmail]...".
     if ($newfolderid == "0/Archive") {
         $newfolderImapid = "[Gmail]/All Mail";
     } else {
         $newfolderImapid = $this->getImapIdFromFolderId($newfolderid);
     }
     if ($folderImapid == $newfolderImapid) {
         throw new StatusException(sprintf("BackendIMAP->MoveMessage('%s','%s','%s'): Error, destination folder is source folder. Canceling the move.", $folderid, $id, $newfolderid), SYNC_MOVEITEMSSTATUS_SAMESOURCEANDDEST);
     }
     $this->imap_reopen_folder($folderImapid);
     if ($this->imap_inside_cutoffdate(Utils::GetCutOffDate($contentparameters->GetFilterType()), $id)) {
         // read message flags
         $overview = @imap_fetch_overview($this->mbox, $id, FT_UID);
         if (!is_array($overview)) {
             throw new StatusException(sprintf("BackendIMAP->MoveMessage('%s','%s','%s'): Error, unable to retrieve overview of source message: %s", $folderid, $id, $newfolderid, imap_last_error()), SYNC_MOVEITEMSSTATUS_INVALIDSOURCEID);
         } else {
             // get next UID for destination folder
             // when moving a message we have to announce through ActiveSync the new messageID in the
             // destination folder. This is a "guessing" mechanism as IMAP does not inform that value.
             // when lots of simultaneous operations happen in the destination folder this could fail.
             // in the worst case the moved message is displayed twice on the mobile.
             $destStatus = imap_status($this->mbox, $this->server . $newfolderImapid, SA_ALL);
             if (!$destStatus) {
                 throw new StatusException(sprintf("BackendIMAP->MoveMessage('%s','%s','%s'): Error, unable to open destination folder: %s", $folderid, $id, $newfolderid, imap_last_error()), SYNC_MOVEITEMSSTATUS_INVALIDDESTID);
             }
             $newid = $destStatus->uidnext;
             // move message
             $s1 = imap_mail_move($this->mbox, $id, $newfolderImapid, CP_UID);
             if (!$s1) {
                 throw new StatusException(sprintf("BackendIMAP->MoveMessage('%s','%s','%s'): Error, copy to destination folder failed: %s", $folderid, $id, $newfolderid, imap_last_error()), SYNC_MOVEITEMSSTATUS_CANNOTMOVE);
             }
             // delete message in from-folder
             $s2 = imap_expunge($this->mbox);
             // open new folder
             $stat = $this->imap_reopen_folder($newfolderImapid);
             if (!$s1) {
                 throw new StatusException(sprintf("BackendIMAP->MoveMessage('%s','%s','%s'): Error, opening the destination folder: %s", $folderid, $id, $newfolderid, imap_last_error()), SYNC_MOVEITEMSSTATUS_CANNOTMOVE);
             }
             // remove all flags
             $s3 = @imap_clearflag_full($this->mbox, $newid, "\\Seen \\Answered \\Flagged \\Deleted \\Draft", FT_UID);
             $newflags = "";
             if ($overview[0]->seen) {
                 $newflags .= "\\Seen";
             }
             if ($overview[0]->flagged) {
                 $newflags .= " \\Flagged";
             }
             if ($overview[0]->answered) {
                 $newflags .= " \\Answered";
             }
             $s4 = @imap_setflag_full($this->mbox, $newid, $newflags, FT_UID);
             ZLog::Write(LOGLEVEL_DEBUG, sprintf("BackendIMAP->MoveMessage('%s','%s','%s'): result s-move: '%s' s-expunge: '%s' unset-Flags: '%s' set-Flags: '%s'", $folderid, $id, $newfolderid, Utils::PrintAsString($s1), Utils::PrintAsString($s2), Utils::PrintAsString($s3), Utils::PrintAsString($s4)));
             // return the new id "as string"
             return $newid . "";
         }
     } else {
         throw new StatusException(sprintf("BackendIMAP->MoveMessage(): Message is outside the sync range"), SYNC_MOVEITEMSSTATUS_INVALIDSOURCEID);
     }
 }
Esempio n. 18
0
/**
 * Marks an email Unread
 * @param array $action Array of options and criteria for the action current being processed
 * @param string $ieId ID of InboundEmail instance fully retrieved
 * @param string $uid UID of email
 */
function mark_unread($action, $bean, $ie)
{
    return imap_clearflag_full($ie->conn, $bean->uid, '\\Seen', ST_UID);
}
Esempio n. 19
0
 /**
  * Called when the user moves an item on the PDA from one folder to another
  *
  * @param string        $folderid       id of the source folder
  * @param string        $id             id of the message
  * @param string        $newfolderid    id of the destination folder
  *
  * @access public
  * @return boolean                      status of the operation
  * @throws StatusException              could throw specific SYNC_MOVEITEMSSTATUS_* exceptions
  */
 public function MoveMessage($folderid, $id, $newfolderid)
 {
     ZLog::Write(LOGLEVEL_DEBUG, sprintf("BackendIMAP->MoveMessage('%s','%s','%s')", $folderid, $id, $newfolderid));
     $folderImapid = $this->getImapIdFromFolderId($folderid);
     $newfolderImapid = $this->getImapIdFromFolderId($newfolderid);
     $this->imap_reopenFolder($folderImapid);
     // TODO this should throw a StatusExceptions on errors like SYNC_MOVEITEMSSTATUS_SAMESOURCEANDDEST,SYNC_MOVEITEMSSTATUS_INVALIDSOURCEID,SYNC_MOVEITEMSSTATUS_CANNOTMOVE
     // read message flags
     $overview = @imap_fetch_overview($this->mbox, $id, FT_UID);
     if (!$overview) {
         throw new StatusException(sprintf("BackendIMAP->MoveMessage('%s','%s','%s'): Error, unable to retrieve overview of source message: %s", $folderid, $id, $newfolderid, imap_last_error()), SYNC_MOVEITEMSSTATUS_INVALIDSOURCEID);
     } else {
         // get next UID for destination folder
         // when moving a message we have to announce through ActiveSync the new messageID in the
         // destination folder. This is a "guessing" mechanism as IMAP does not inform that value.
         // when lots of simultaneous operations happen in the destination folder this could fail.
         // in the worst case the moved message is displayed twice on the mobile.
         $destStatus = imap_status($this->mbox, $this->server . $newfolderImapid, SA_ALL);
         if (!$destStatus) {
             throw new StatusException(sprintf("BackendIMAP->MoveMessage('%s','%s','%s'): Error, unable to open destination folder: %s", $folderid, $id, $newfolderid, imap_last_error()), SYNC_MOVEITEMSSTATUS_INVALIDDESTID);
         }
         $newid = $destStatus->uidnext;
         // move message
         $s1 = imap_mail_move($this->mbox, $id, $newfolderImapid, CP_UID);
         if (!$s1) {
             throw new StatusException(sprintf("BackendIMAP->MoveMessage('%s','%s','%s'): Error, copy to destination folder failed: %s", $folderid, $id, $newfolderid, imap_last_error()), SYNC_MOVEITEMSSTATUS_CANNOTMOVE);
         }
         // delete message in from-folder
         $s2 = imap_expunge($this->mbox);
         // open new folder
         $stat = $this->imap_reopenFolder($newfolderImapid);
         if (!$s1) {
             throw new StatusException(sprintf("BackendIMAP->MoveMessage('%s','%s','%s'): Error, openeing the destination folder: %s", $folderid, $id, $newfolderid, imap_last_error()), SYNC_MOVEITEMSSTATUS_CANNOTMOVE);
         }
         // remove all flags
         $s3 = @imap_clearflag_full($this->mbox, $newid, "\\Seen \\Answered \\Flagged \\Deleted \\Draft", FT_UID);
         $newflags = "";
         if ($overview[0]->seen) {
             $newflags .= "\\Seen";
         }
         if ($overview[0]->flagged) {
             $newflags .= " \\Flagged";
         }
         if ($overview[0]->answered) {
             $newflags .= " \\Answered";
         }
         $s4 = @imap_setflag_full($this->mbox, $newid, $newflags, FT_UID);
         ZLog::Write(LOGLEVEL_DEBUG, sprintf("BackendIMAP->MoveMessage('%s','%s','%s'): result s-move: '%s' s-expunge: '%s' unset-Flags: '%s' set-Flags: '%s'", $folderid, $id, $newfolderid, Utils::PrintAsString($s1), Utils::PrintAsString($s2), Utils::PrintAsString($s3), Utils::PrintAsString($s4)));
         // return the new id "as string""
         return $newid . "";
     }
 }
Esempio n. 20
0
 /**
  * Mark the message in the mailbox.
  */
 function markMessage($messageid, $flags = null)
 {
     $markas = $this->_scannerinfo->markas;
     if ($this->_imap) {
         if ($markas) {
             if (strtoupper($markas) == 'SEEN') {
                 $markas = "\\Seen";
                 imap_setflag_full($this->_imap, $messageid, $markas);
             } else {
                 if ($flags['Unseen'] == 'U') {
                     imap_clearflag_full($this->_imap, $messageid, "\\Seen");
                 }
             }
         } else {
             if ($flags['Unseen'] == 'U') {
                 imap_clearflag_full($this->_imap, $messageid, "\\Seen");
             }
         }
     }
 }
Esempio n. 21
0
 /**
  * Update the email setting flags
  *
  */
 public function update(Model $model, $fields = NULL, $values = NULL, $conditions = NULL)
 {
     if (empty($model->id)) {
         return $this->err($model, 'Cannot update a record without id');
     }
     $flags = array('recent', 'seen', 'flagged', 'answered', 'draft', 'deleted');
     $data = array_combine($fields, $values);
     foreach ($data as $field => $value) {
         if (!in_array($field, $flags)) {
             continue;
         }
         $flag = '\\' . ucfirst($field);
         if ($value === true || $value === 1 || $value === '1') {
             if (!imap_setflag_full($this->Stream, $model->id, $flag, ST_UID)) {
                 $this->err($model, 'Unable to mark email %s as %s', $model->id, $flag);
             }
         } else {
             if (!imap_clearflag_full($this->Stream, $model->id, $flag, ST_UID)) {
                 $this->err($model, 'Unable to unmark email %s as %s', $model->id, $flag);
             }
         }
     }
     return true;
 }
Esempio n. 22
0
 /**
  * mark message as read
  *
  * @return bool success or not
  * @param $id of the message
  * @param $seen true = message is read, false = message is unread
  */
 public function setUnseenMessage($id, $seen = true)
 {
     $header = $this->getMessageHeader($id);
     if ($header == false) {
         return false;
     }
     $flags = "";
     $flags .= strlen(trim($header->Answered)) > 0 ? "\\Answered " : '';
     $flags .= strlen(trim($header->Flagged)) > 0 ? "\\Flagged " : '';
     $flags .= strlen(trim($header->Deleted)) > 0 ? "\\Deleted " : '';
     $flags .= strlen(trim($header->Draft)) > 0 ? "\\Draft " : '';
     $flags .= $seen == true ? '\\Seen ' : ' ';
     //echo "\n<br />".$id.": ".$flags;
     imap_clearflag_full($this->imap, $id, '\\Seen', ST_UID);
     return imap_setflag_full($this->imap, $id, trim($flags), ST_UID);
 }
Esempio n. 23
0
 function MoveMessage($folderid, $id, $newfolderid)
 {
     debugLog("IMAP-MoveMessage: (sfid: '{$folderid}'  id: '{$id}'  dfid: '{$newfolderid}' )");
     $this->imap_reopenFolder($folderid);
     // read message flags
     $overview = @imap_fetch_overview($this->_mbox, $id, FT_UID);
     if (!$overview) {
         debugLog("IMAP-MoveMessage: Failed to retrieve overview");
         return false;
     } else {
         // move message
         $s1 = imap_mail_move($this->_mbox, $id, str_replace(".", $this->_serverdelimiter, $newfolderid), FT_UID);
         // delete message in from-folder
         $s2 = imap_expunge($this->_mbox);
         // open new folder
         $this->imap_reopenFolder($newfolderid);
         // remove all flags
         $s3 = @imap_clearflag_full($this->_mbox, $id, "\\Seen \\Answered \\Flagged \\Deleted \\Draft", FT_UID);
         $newflags = "";
         if ($overview[0]->seen) {
             $newflags .= "\\Seen";
         }
         if ($overview[0]->flagged) {
             $newflags .= " \\Flagged";
         }
         if ($overview[0]->answered) {
             $newflags .= " \\Answered";
         }
         $s4 = @imap_setflag_full($this->_mbox, $id, $newflags, FT_UID);
         debugLog("MoveMessage: (" . $folderid . "->" . $newfolderid . ") s-move: {$s1}   s-expunge: {$s2}    unset-Flags: {$s3}    set-Flags: {$s4}");
         return $s1 && $s2 && $s3 && $s4;
     }
 }
Esempio n. 24
0
 function MoveMessage($folderid, $id, $newfolderid)
 {
     debugLog("IMAP-MoveMessage: (sfid: '{$folderid}'  id: '{$id}'  dfid: '{$newfolderid}' )");
     $this->imap_reopenFolder($folderid);
     // read message flags
     $overview = @imap_fetch_overview($this->_mbox, $id, FT_UID);
     if (!$overview) {
         debugLog("IMAP-MoveMessage: Failed to retrieve overview");
         return false;
     } else {
         // get next UID for destination folder
         // when moving a message we have to announce through ActiveSync the new messageID in the
         // destination folder. This is a "guessing" mechanism as IMAP does not inform that value.
         // when lots of simultaneous operations happen in the destination folder this could fail.
         // in the worst case the moved message is displayed twice on the mobile.
         $destStatus = imap_status($this->_mbox, $this->_server . $newfolderid, SA_ALL);
         $newid = $destStatus->uidnext;
         // move message
         $s1 = imap_mail_move($this->_mbox, $id, $newfolderid, CP_UID);
         // delete message in from-folder
         $s2 = imap_expunge($this->_mbox);
         // open new folder
         $this->imap_reopenFolder($newfolderid);
         // remove all flags
         $s3 = @imap_clearflag_full($this->_mbox, $newid, "\\Seen \\Answered \\Flagged \\Deleted \\Draft", FT_UID);
         $newflags = "";
         if ($overview[0]->seen) {
             $newflags .= "\\Seen";
         }
         if ($overview[0]->flagged) {
             $newflags .= " \\Flagged";
         }
         if ($overview[0]->answered) {
             $newflags .= " \\Answered";
         }
         $s4 = @imap_setflag_full($this->_mbox, $newid, $newflags, FT_UID);
         debugLog("MoveMessage: (" . $folderid . "->" . $newfolderid . ":" . $newid . ") s-move: {$s1}   s-expunge: {$s2}    unset-Flags: {$s3}    set-Flags: {$s4}");
         // return the new id "as string""
         return $newid . "";
     }
 }
Esempio n. 25
0
 /**
  * This function is used to enable or disable a flag on the imap message.
  *
  * @param  string $flag   Flagged, Answered, Deleted, Seen, Draft
  * @param  bool   $enable
  * @return bool
  */
 public function setFlag($flag, $enable = true)
 {
     if (!in_array($flag, self::$flagTypes) || $flag == 'recent') {
         throw new \InvalidArgumentException('Unable to set invalid flag "' . $flag . '"');
     }
     $flag = '\\' . ucfirst($flag);
     if ($enable) {
         return imap_setflag_full($this->imapStream, $this->uid, $flag, ST_UID);
     } else {
         return imap_clearflag_full($this->imapStream, $this->uid, $flag, ST_UID);
     }
 }
Esempio n. 26
0
 public function clearFlag(array $msgs, $flag)
 {
     return imap_clearflag_full($this->connection, implode(',', $msgs), $flag, ST_UID);
 }
Esempio n. 27
0
 /**
  * Cause a store to delete the specified flag to the flags set for the mails in the specified sequence.
  *
  * @param array $mailsIds
  * @param string $flag which you can set are \Seen, \Answered, \Flagged, \Deleted, and \Draft as defined by RFC2060.
  * @return bool
  */
 public function clearFlag(array $mailsIds, $flag)
 {
     return imap_clearflag_full($this->getImapStream(), implode(',', $mailsIds), $flag, ST_UID);
 }
Esempio n. 28
0
 /**
  * flag or unflag the message
  * wraps the imap_setflag_full() and 
  * the imap_clearflag_full() functions
  * TODO: error checking on input
  */
 public function flag_mail($id_or_range, $flag_string, $set_flag = TRUE)
 {
     if ($set_flag) {
         $bool = imap_setflag_full($this->resource, $id_or_range, $flag_string);
         $this->log_state('Flagged message: ' . $id_or_range . ' as ' . $flag_string);
     } else {
         $bool = imap_clearflag_full($this->resource, $id_or_range, $flag_string);
         $this->log_state('Unflagged message: ' . $id_or_range . ' as ' . $flag_string);
     }
 }
Esempio n. 29
0
 /**
  * Sets flags on emails.  Assumes that connection is live, correct folder is
  * set.
  * @param string $uids Sequence of UIDs, comma separated
  * @param string $type Flag to mark
  */
 function markEmails($uids, $type)
 {
     switch ($type) {
         case 'unread':
             $result = imap_clearflag_full($this->conn, $uids, '\\SEEN', ST_UID);
             break;
         case 'read':
             $result = imap_setflag_full($this->conn, $uids, '\\SEEN', ST_UID);
             break;
         case 'flagged':
             $result = imap_setflag_full($this->conn, $uids, '\\FLAGGED', ST_UID);
             break;
         case 'unflagged':
             $result = imap_clearflag_full($this->conn, $uids, '\\FLAGGED', ST_UID);
             break;
         case 'answered':
             $result = imap_setflag_full($this->conn, $uids, '\\Answered', ST_UID);
             break;
     }
 }
Esempio n. 30
0
 public function delete($URI, $justthese = false, $criteria = false)
 {
     switch ($URI['concept']) {
         case 'labeled':
             list($messageId, $labelId) = explode('#', $URI['id']);
             $folderName = dirname($messageId);
             $messageNumber = basename($messageId);
             if ($folderName && $messageNumber && $labelId) {
                 $this->mbox = $this->open_mbox($folderName);
                 imap_clearflag_full($this->mbox, $messageNumber, '$Label' . $labelId, ST_UID);
             }
         case 'followupflagged':
             $map = array('folderName' => array(), 'messageNumber' => array(), 'messageId' => array());
             self::parseFilter($criteria["filter"], $map);
             if (!$map['folderName']) {
                 $folders = array();
                 $folder_list = $this->get_folders_list();
                 foreach ($folder_list as $folder) {
                     if (isset($folder['folder_id'])) {
                         $folders[] = $folder['folder_id'];
                     }
                 }
                 $map['folderName'] = $folders;
             }
             $messagesIds = $map['messageId'];
             foreach ($map['folderName'] as $folder) {
                 $messages = array();
                 $this->mbox = $this->open_mbox($folder);
                 /**
                  * Se é uma busca por messageId
                  */
                 if (!empty($map['messageId'])) {
                     foreach ($messagesIds as $k => $v) {
                         $r = imap_search($this->mbox, 'ALL KEYWORD "$Followupflagged" TEXT "Message-Id: ' . $v . '"', SE_UID);
                         if ($r) {
                             $messages = $messages + $r;
                             unset($messagesIds[$k]);
                         }
                     }
                     /**
                      * Se é uma busca por messageNumber.
                      * Lembrando que, neste caso, só deve ser suportada uma única pasta no filtro.
                      */
                 } else {
                     $messages = imap_search($this->mbox, 'ALL KEYWORD "$Followupflagged"', SE_UID);
                 }
                 /**
                  * Se é uma busca por messageId, deve ser comparado com os messageNumbers 
                  * passados no filtro, se houverem.
                  */
                 if (!empty($map['messageNumber'])) {
                     foreach ($messages as $k => $m) {
                         if (!in_array($m, $map['messageNumber'])) {
                             unset($messages[$k]);
                         }
                     }
                 }
                 $s = true;
                 foreach ($messages as $k => $m) {
                     $s = imap_clearflag_full($this->mbox, $m, '$Followupflagged', ST_UID) && $s;
                 }
                 /**
                  * Se é uma busca por messageId e todos os messageIds foram econstrados:
                  * Stop searching in all folders
                  */
                 if (!empty($map['messageId']) && empty($messagesIds)) {
                     break;
                 }
             }
             return $s;
     }
     //TODO - return
 }