/** * Marks emails with the passed flag type. This will be applied to local * cache files as well as remote emails. * @param string $type Flag type * @param string $ieId * @param string $folder IMAP folder structure or SugarFolder GUID * @param string $uids Comma sep list of UIDs or GUIDs */ function markEmails($type, $ieId, $folder, $uids) { global $app_strings; $uids = $this->_cleanUIDList($uids); $exUids = explode($app_strings['LBL_EMAIL_DELIMITER'], $uids); if (strpos($folder, 'sugar::') !== false) { // Collect message IDs for deleting mails from server $messageUIDs = array(); // dealing with a sugar email object, uids are GUIDs foreach ($exUids as $id) { $email = BeanFactory::getBean('Emails', $id); // BUG FIX BEGIN // Bug 50973 - marking unread in group inbox removes message if (empty($email->assigned_user_id)) { $email->setFieldNullable('assigned_user_id'); } // BUG FIX END switch ($type) { case "unread": $email->status = 'unread'; $email->save(); break; case "read": $email->status = 'read'; $email->save(); break; case "deleted": if (!empty($email->message_uid)) { $messageUIDs[] = $email->message_uid; } $email->delete(); break; case "flagged": $email->flagged = 1; $email->save(); break; case "unflagged": $email->flagged = 0; $email->save(); break; } // BUG FIX BEGIN // Bug 50973 - reset assigned_user_id field defs if (empty($email->assigned_user_id)) { $email->revertFieldNullable('assigned_user_id'); } // BUG FIX END } // Do only Mail server call, since we have an array of UIDs switch ($type) { case "deleted": $ieX = new InboundEmail(); $ieX->retrieve_by_string_fields(array('groupfolder_id' => $ieId, 'deleted' => 0)); if (!empty($ieX->id) && !$ieX->is_personal) { // function retrieve_by_string_fields doesn't decrypt email_password -> call retrieve to do it $ieX->retrieve($ieX->id); $ieX->deleteMessageOnMailServer(implode($app_strings['LBL_EMAIL_DELIMITER'], $messageUIDs)); } break; default: break; } } else { /* dealing with IMAP email, uids are IMAP uids */ global $ie; // provided by EmailUIAjax.php if (empty($ie)) { $ie = BeanFactory::getBean('InboundEmail'); $ie->disable_row_level_security = true; } $ie->retrieve($ieId); $ie->mailbox = $folder; $ie->connectMailserver(); // mark cache files if ($type == 'deleted') { $ie->deleteMessageOnMailServer($uids); $ie->deleteMessageFromCache($uids); } else { $overviews = $ie->getCacheValueForUIDs($ie->mailbox, $exUids); $manipulated = array(); foreach ($overviews['retArr'] as $k => $overview) { if (in_array($overview->uid, $exUids)) { switch ($type) { case "unread": $overview->seen = 0; break; case "read": $overview->seen = 1; break; case "flagged": $overview->flagged = 1; break; case "unflagged": $overview->flagged = 0; break; } $manipulated[] = $overview; } } if (!empty($manipulated)) { $ie->setCacheValue($ie->mailbox, array(), $manipulated); /* now mark emails on email server */ $ie->markEmails(implode(",", explode($app_strings['LBL_EMAIL_DELIMITER'], $uids)), $type); } } // end not type == deleted } }
function doAssignment($distributeMethod, $ieid, $folder, $uids, $users) { global $app_strings; $users = explode(",", $users); $emailIds = explode($app_strings['LBL_EMAIL_DELIMITER'], $uids); $out = ""; if ($folder != 'sugar::Emails') { $emailIds = array(); $uids = explode($app_strings['LBL_EMAIL_DELIMITER'], $uids); $ie = new InboundEmail(); $ie->retrieve($ieid); $messageIndex = 1; // dealing with an inbound email data so we need to import an email and then foreach ($uids as $uid) { $ie->mailbox = $folder; $ie->connectMailserver(); $msgNo = $uid; if (!$ie->isPop3Protocol()) { $msgNo = imap_msgno($ie->conn, $uid); } else { $msgNo = $ie->getCorrectMessageNoForPop3($uid); } if (!empty($msgNo)) { if ($ie->importOneEmail($msgNo, $uid)) { $emailIds[] = $ie->email->id; $ie->deleteMessageOnMailServer($uid); //$ie->retrieve($ieid); //$ie->connectMailserver(); $ie->mailbox = $folder; $ie->deleteMessageFromCache($uids[] = $uid); } else { $out = $out . "Message No : " . $messageIndex . " failed. Reason : Message already imported \r\n"; } } $messageIndex++; } // for } // if if (count($emailIds) > 0) { $this->doDistributionWithMethod($users, $emailIds, $distributeMethod); } // if return $out; }
public function testdeleteMessageOnMailServer() { $inboundEmail = new InboundEmail(); $result = $inboundEmail->deleteMessageOnMailServer('1'); $this->assertEquals(false, $result); }