/** * Copys mails listed in mailId into new mailbox * @return bool */ public function copyMail($mailId, $mailBox) { return imap_mail_copy($this->getImapStream(), $mailId, $mailBox, CP_UID) && $this->expungeDeletedMails(); }
/** * moves emails from folder to folder * @param string $fromIe I-E id * @param string $fromFolder IMAP path to folder in which the email lives * @param string $toIe I-E id * @param string $toFolder * @param string $uids UIDs of emails to move, either Sugar GUIDS or IMAP * UIDs * @param bool $copy Default false * @return bool True on successful execution */ function moveEmails($fromIe, $fromFolder, $toIe, $toFolder, $uids, $copy = false) { global $app_strings; global $current_user; // same I-E server if ($fromIe == $toIe) { $GLOBALS['log']->debug("********* SUGARFOLDER - moveEmails() moving email from I-E to I-E"); //$exDestFolder = explode("::", $toFolder); //preserve $this->mailbox if (isset($this->mailbox)) { $oldMailbox = $this->mailbox; } $this->retrieve($fromIe); $this->mailbox = $fromFolder; $this->connectMailserver(); $exUids = explode('::;::', $uids); $uids = implode(",", $exUids); // imap_mail_move accepts comma-delimited lists of UIDs if ($copy) { if (imap_mail_copy($this->conn, $uids, $toFolder, CP_UID)) { $this->mailbox = $toFolder; $this->connectMailserver(); $newOverviews = imap_fetch_overview($this->conn, $uids, FT_UID); $this->updateOverviewCacheFile($newOverviews, 'append'); if (isset($oldMailbox)) { $this->mailbox = $oldMailbox; } return true; } else { $GLOBALS['log']->debug("INBOUNDEMAIL: could not imap_mail_copy() [ {$uids} ] to folder [ {$toFolder} ] from folder [ {$fromFolder} ]"); } } else { if (imap_mail_move($this->conn, $uids, $toFolder, CP_UID)) { $GLOBALS['log']->info("INBOUNDEMAIL: imap_mail_move() [ {$uids} ] to folder [ {$toFolder} ] from folder [ {$fromFolder} ]"); imap_expunge($this->conn); // hard deletes moved messages // update cache on fromFolder $newOverviews = $this->getOverviewsFromCacheFile($uids, $fromFolder, true); $this->deleteCachedMessages($uids, $fromFolder); // update cache on toFolder $this->checkEmailOneMailbox($toFolder, true, true); if (isset($oldMailbox)) { $this->mailbox = $oldMailbox; } return true; } else { $GLOBALS['log']->debug("INBOUNDEMAIL: could not imap_mail_move() [ {$uids} ] to folder [ {$toFolder} ] from folder [ {$fromFolder} ]"); } } } elseif ($toIe == 'folder' && $fromFolder == 'sugar::Emails') { $GLOBALS['log']->debug("********* SUGARFOLDER - moveEmails() moving email from SugarFolder to SugarFolder"); // move from sugar folder to sugar folder require_once "include/SugarFolders/SugarFolders.php"; $sugarFolder = new SugarFolder(); $exUids = explode($app_strings['LBL_EMAIL_DELIMITER'], $uids); foreach ($exUids as $id) { if ($copy) { $sugarFolder->copyBean($fromIe, $toFolder, $id, "Emails"); } else { $fromSugarFolder = new SugarFolder(); $fromSugarFolder->retrieve($fromIe); $toSugarFolder = new SugarFolder(); $toSugarFolder->retrieve($toFolder); $email = new Email(); $email->retrieve($id); $email->status = 'unread'; // when you move from My Emails to Group Folder, Assign To field for the Email should become null if ($fromSugarFolder->is_dynamic && $toSugarFolder->is_group) { $email->assigned_user_id = ""; $email->save(); if (!$toSugarFolder->checkEmailExistForFolder($id)) { $fromSugarFolder->deleteEmailFromAllFolder($id); $toSugarFolder->addBean($email); } } elseif ($fromSugarFolder->is_group && $toSugarFolder->is_dynamic) { $fromSugarFolder->deleteEmailFromAllFolder($id); $email->assigned_user_id = $current_user->id; $email->save(); } else { // If you are moving something from personal folder then delete an entry from all folder if (!$fromSugarFolder->is_dynamic && !$fromSugarFolder->is_group) { $fromSugarFolder->deleteEmailFromAllFolder($id); } // if if ($fromSugarFolder->is_dynamic && !$toSugarFolder->is_dynamic && !$toSugarFolder->is_group) { $email->assigned_user_id = ""; $toSugarFolder->addBean($email); } // if if (!$toSugarFolder->checkEmailExistForFolder($id)) { if (!$toSugarFolder->is_dynamic) { $fromSugarFolder->deleteEmailFromAllFolder($id); $toSugarFolder->addBean($email); } else { $fromSugarFolder->deleteEmailFromAllFolder($id); $email->assigned_user_id = $current_user->id; } } else { $sugarFolder->move($fromIe, $toFolder, $id); } // else $email->save(); } // else } } return true; } elseif ($toIe == 'folder') { $GLOBALS['log']->debug("********* SUGARFOLDER - moveEmails() moving email from I-E to SugarFolder"); // move to Sugar folder require_once "include/SugarFolders/SugarFolders.php"; $sugarFolder = new SugarFolder(); $sugarFolder->retrieve($toFolder); //Show the import form if we don't have the required info if (!isset($_REQUEST['delete'])) { $json = getJSONobj(); if ($sugarFolder->is_group) { $_REQUEST['showTeam'] = false; $_REQUEST['showAssignTo'] = false; } $ret = $this->email->et->getImportForm($_REQUEST, $this->email); $ret['move'] = true; $ret['srcFolder'] = $fromFolder; $ret['srcIeId'] = $fromIe; $ret['dstFolder'] = $toFolder; $ret['dstIeId'] = $toIe; $out = trim($json->encode($ret, false)); echo $out; return true; } // import to Sugar $this->retrieve($fromIe); $this->mailbox = $fromFolder; $this->connectMailserver(); // If its a group folder the team should be of the folder team if ($sugarFolder->is_group) { $_REQUEST['team_id'] = $sugarFolder->team_id; $_REQUEST['team_set_id'] = $sugarFolder->team_set_id; } else { // TODO - set team_id, team_set for new UI } // else $exUids = explode($app_strings['LBL_EMAIL_DELIMITER'], $uids); if (!empty($sugarFolder->id)) { $count = 1; $return = array(); $json = getJSONobj(); foreach ($exUids as $k => $uid) { $msgNo = $uid; if ($this->isPop3Protocol()) { $msgNo = $this->getCorrectMessageNoForPop3($uid); } else { $msgNo = imap_msgno($this->conn, $uid); } if (!empty($msgNo)) { $importStatus = $this->importOneEmail($msgNo, $uid); // add to folder if ($importStatus) { $sugarFolder->addBean($this->email); if (!$copy && isset($_REQUEST['delete']) && $_REQUEST['delete'] == "true" && $importStatus) { $GLOBALS['log']->error("********* delete from mailserver [ {explode(", ", {$uids})} ]"); // delete from mailserver $this->deleteMessageOnMailServer($uid); $this->deleteMessageFromCache($uid); } // if } $return[] = $app_strings['LBL_EMAIL_MESSAGE_NO'] . " " . $count . ", " . $app_strings['LBL_STATUS'] . " " . ($importStatus ? $app_strings['LBL_EMAIL_IMPORT_SUCCESS'] : $app_strings['LBL_EMAIL_IMPORT_FAIL']); $count++; } // if } // foreach echo $json->encode($return); return true; } else { $GLOBALS['log']->error("********* SUGARFOLDER - failed to retrieve folder ID [ {$toFolder} ]"); } } else { $GLOBALS['log']->debug("********* SUGARFOLDER - moveEmails() called with no passing criteria"); } return false; }
/** * This function is used to move a mail to the given mailbox. * * @param $mailbox * * @return bool */ public function moveToMailBox($mailbox) { $currentBox = $this->imapConnection->getMailBox(); $this->imapConnection->setMailBox($this->mailbox); $returnValue = imap_mail_copy($this->imapStream, $this->uid, $mailbox, CP_UID | CP_MOVE); imap_expunge($this->imapStream); $this->mailbox = $mailbox; $this->imapConnection->setMailBox($currentBox); return $returnValue; }
/** * kopiert die Nachricht mit der gegebenen uid in die gegebene Mailbox *auf dem selben Server* * @param integer $uid * @param string $dest_mbox * @return boolean */ public function imapMailCopy($uid, $dest_mbox) { if ($this->imap === null) { throw new IMAPException(__METHOD__ . ' not connected'); } $this->imapPing(true); return imap_mail_copy($this->imap, $uid, $dest_mbox, CP_UID); }
<?php /* Prototype : bool imap_mail_copy ( resource $imap_stream , string $msglist , string $mailbox [, int $options = 0 ] ) * Description: Copies mail messages specified by msglist to specified mailbox. * Source code: ext/imap/php_imap.c */ echo "*** Testing imap_mail_copy() : basic functionality ***\n"; require_once dirname(__FILE__) . '/imap_include.inc'; echo "Create a new mailbox for test\n"; $imap_stream = setup_test_mailbox("", 1); if (!is_resource($imap_stream)) { exit("TEST FAILED: Unable to create test mailbox\n"); } $check = imap_check($imap_stream); echo "Msg Count in new mailbox: " . $check->Nmsgs . "\n"; var_dump(imap_mail_copy($imap_stream, '1', 'INBOX.' . $mailbox_prefix)); imap_close($imap_stream); ?> ===Done=== <?php require_once 'clean.inc';
} /* output the email header information */ $subject = $overview[0]->subject; $to = $header->to[0]->mailbox . '@' . $header->to[0]->host; $from = $overview[0]->from; $date = $overview[0]->date; $msgid = $header->message_id; $message = new xmlrpcmsg('support.request', array(new xmlrpcval($subject, 'string'), new xmlrpcval($from, 'string'), new xmlrpcval($body, 'struct'), new xmlrpcval($to, 'string'))); //$server->setdebug(1); $result = $server->send($message); // Process the response. if (!$result) { echo "Could not connect to HTTP server.\n"; } elseif ($result->faultCode()) { echo "XML-RPC Fault #" . $result->faultCode() . ": " . $result->faultString() . "\n"; } else { $struct = $result->value(); $result = $struct->structmem('result'); $response = $struct->structmem('response'); echo $result->scalarval() . ':' . $response->scalarval() . "\n"; if ($result->scalarval() == 'SUCCESS') { imap_mail_copy($inbox, $email_number, 'processed'); imap_delete($inbox, $email_number); } } } imap_expunge($inbox); } /* close the connection */ imap_close($inbox); // End of xmlrpc_mail_client
function ExecuteAction($rule, $aResults) { $this->output->say(" - Executing action: " . $rule['action'], 0); if (!empty($rule['destination'])) { $this->output->say("-->" . $rule['destination'] . ":"); } else { $this->output->say(":"); } foreach ($aResults as $key => $uid) { $this->output->say(" - Message id " . $uid . "...", 0); if ($rule['action'] == "MOVE") { if ($this->CheckAndCreateMailbox($rule['destination'])) { $success = imap_mail_move($this->conn, $uid, $rule['destination'], CP_UID); } } elseif ($rule['action'] == "COPY") { if ($this->CheckAndCreateMailbox($rule['destination'])) { $success = imap_mail_copy($this->conn, $uid, $rule['destination'], CP_UID); } } elseif ($rule['action'] == "DELETE") { $success = imap_delete($this->conn, $uid, FT_UID); } if ($success) { $this->output->say("OK"); } else { $this->output->say("FAIL"); } } }
/** * Método que aplica a ação do filtro nas mensagens da caixa de entrada * * @license http://www.gnu.org/copyleft/gpl.html GPL * @author Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br) * @sponsor Caixa Econômica Federal * @author Airton Bordin Junior <*****@*****.**> * @author Gustavo Pereira dos Santos <*****@*****.**> * @param <Array> <$msgs> <Mensagens da caixa de entrada> * @param <Array> <$proc> <ações do filtro> * @return <Regras do usuário em Array> * @access public */ function apliSieveFilter($msgs, $proc) { $ret = array(); foreach ($msgs as $i => $msg) { switch ($proc['type']) { case 'fileinto': $imap = $this->open_mbox('INBOX'); if ($proc['keep'] === true) { $ret[$msg][] = imap_mail_copy($imap, $msg, $proc['value'], CP_UID); } else { /* Está sempre copiando a mensagem para a pasta destino */ //$ret[$msg][] = imap_mail_move($imap,$msg,$proc['parameter'], CP_UID); $ret[$msg][] = imap_mail_move($imap, $msg, $proc['parameter'], CP_UID); imap_expunge($imap); } break; case 'redirect': foreach ($msgs as $msg) { $info = $this->get_info_msg(array('msg_folder' => 'INBOX', 'msg_number' => $msg)); Controller::create(array('service' => 'SMTP'), array('body' => $info['body'], 'isHtml' => true, 'subject' => $info['subject'], 'from' => $info['from']['full'], 'to' => $proc['parameter'])); if ($proc['keep'] !== true) { $this->delete_msgs(array('msgs_number' => $msg, 'folder' => 'INBOX')); } } break; case 'setflag': foreach ($msgs as $msg) { $ret[$msg][] = $this->set_messages_flag(array('folder' => 'INBOX', 'msgs_to_set' => $msg, 'flag' => $proc['parameter'])); } break; } } return $ret; }
<?php echo "Checking with no parameters\n"; imap_mail_copy(); echo "Checking with incorrect parameter type\n"; imap_mail_copy(''); imap_mail_copy(false); // more tests require_once dirname(__FILE__) . '/imap_include.inc'; echo "Test with IMAP server\n"; $stream_id = imap_open($default_mailbox, $username, $password) or die("Cannot connect to mailbox {$default_mailbox}: " . imap_last_error()); var_dump(imap_mail_copy($stream_id)); var_dump(imap_mail_copy($stream_id, -1)); var_dump(imap_mail_copy($stream_id, '')); imap_close($stream_id); ?> ===Done===
/** * Copy a mail message to another folder * * @param int $num * @param string $newfolder * @return * @access public */ function copymail($num, $newfolder) { if ($this->protocol == 'POP3') { //POP3 does not support folders so just return false $this->errors[] = GM_NO_POP3_SUPPORT; return false; } //if (strtoupper($newfolder) != 'INBOX') // $folder = "INBOX.$newfolder"; if ($this->use_native) { $status = imap_mail_copy($this->mailer, $num, $newfolder); if (!$status) { $this->errors[] = imap_last_error(); return false; } return true; } else { $status = $this->mailer->copyMessages($num, $newfolder); if ($status !== true) { $this->errors[] = $status->getMessage(); return false; } return true; } }
function mailcopy($stream, $msg_list, $mailbox, $flags = 0) { // do we force use of msg UID's if ($this->force_msg_uids == True && !($flags & CP_UID)) { $flags |= CP_UID; } $mailbox = $this->utf7_encode($mailbox); return imap_mail_copy($stream, $msg_list, $mailbox, $flags); }
/** * Copies mail to another mailbox * @param int $mailId * @param string $toMailbox * @throws DriverException */ public function copyMail($mailId, $toMailbox) { if (!imap_mail_copy($this->resource, $mailId, $this->server . $this->encodeMailboxName($toMailbox), CP_UID)) { throw new DriverException("Cannot copy mail to mailbox '{$toMailbox}': " . imap_last_error()); } }
public function mail_copy($sequence, $dest) { return imap_mail_copy($this->imapStream, $sequence, $dest, CP_UID); }
/** * Copy specified messages to a mailbox. * * @link http://php.net/manual/en/function.imap-mail-copy.php * * @param resource $stream * @param string $msglist <p> * <i>msglist</i> is a range not just message * numbers (as described in RFC2060). * </p> * @param string $mailbox <p> * The mailbox name, see <b>imap_open</b> for more * information * </p> * @param int $options [optional] <p> * <i>options</i> is a bitmask of one or more of * <b>CP_UID</b> - the sequence numbers contain UIDS * * @throws \RuntimeException If operation fail */ public function mailCopy($stream, $msglist, $mailbox, $options = 0) { $result = imap_mail_copy($stream, $msglist, $mailbox, $options); if (empty($result)) { throw new \RuntimeException(imap_last_error()); } }
/** * Copy specified messages to a mailbox. * * @param int $uniqueId * @param string $mailBoxName * @return bool */ public function copyMail($uniqueId, $mailBoxName) { return imap_mail_copy($this->ressource, $uniqueId, $mailBoxName, FT_UID); }