Skip to content

Commit

Permalink
AS16 - Imap Drafts functions
Browse files Browse the repository at this point in the history
  • Loading branch information
matidau committed Dec 7, 2024
1 parent d0b66e2 commit 25ad8e7
Showing 1 changed file with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions src/backend/imap/imap.php
Original file line number Diff line number Diff line change
Expand Up @@ -3231,4 +3231,57 @@ public function getRecentDraft() {
return $id;
}

/**
* Saves a copy of a message in the Draft folder
*
* @access public
* @param $finalHeaders Array of headers
* @param $finalBody Body part
* @return boolean If the message is saved
*/
private function saveDraftMessage($finalHeaders, $finalBody) {
ZLog::Write(LOGLEVEL_DEBUG, sprintf("BackendIMAP->saveDraftMessage(): saving message in Draft Items folder"));

$headers = "";
foreach ($finalHeaders as $k => $v) {
if (strlen($headers) > 0) {
$headers .= "\n";
}
$headers .= "$k: $v";
}

if ($this->draftID === false) {
$this->draftID = $this->getFolderIdFromImapId($this->create_name_folder(IMAP_FOLDER_DRAFT), false);
}

$saved = false;
if ($this->draftID) {
$imapid = $this->getImapIdFromFolderId($this->draftID);
$saved = $this->addDraftMessage($imapid, $headers, $finalBody);
ZLog::Write(LOGLEVEL_DEBUG, sprintf("BackendIMAP->saveDraftMessage(): Outgoing mail saved in 'Draft' folder '%s' ['%s']", $imapid, $this->draftID));
}
else {
ZLog::Write(LOGLEVEL_ERROR, "BackendIMAP->saveDraftMessage(): The email could not be saved to Draft Items folder. Check your configuration.");
}
unset($headers);

return $saved;
}

/**
* Adds a message with draft and seen flag to a specified folder (used for saving draft items)
*
* @param string $folderid id of the folder
* @param string $header header of the message
* @param long $body body of the message
*
* @access protected
* @return boolean status
*/
protected function addDraftMessage($folderid, $header, $body) {
$header_body = str_replace("\n", "\r\n", str_replace("\r", "", $header . "\n\n" . $body));

return @imap_append($this->mbox, $this->server . $folderid, $header_body, "\\Seen\\Draft");
}

};

0 comments on commit 25ad8e7

Please sign in to comment.