Skip to content

Added methods for moving and copying multiple messages #160

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Sep 4, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 39 additions & 1 deletion src/Connection/Protocols/ImapProtocol.php
Original file line number Diff line number Diff line change
Expand Up @@ -824,6 +824,25 @@ public function copyMessage($folder, $from, $to = null, $uid = false) {
return $this->requestAndResponse($command, [$set, $this->escapeString($folder)], true);
}

/**
* Copy multiple messages to the target folder
*
* @param array<string> $messages List of message identifiers
* @param string $folder Destination folder
* @param bool $uid Set to true if you pass message unique identifiers instead of numbers
* @return array|bool Tokens if operation successful, false if an error occurred
*
* @throws RuntimeException
*/
public function copyManyMessages($messages, $folder, $uid = false) {
$command = $uid ? 'UID COPY' : 'COPY';

$set = implode(',', $messages);
$tokens = [$set, $this->escapeString($folder)];

return $this->requestAndResponse($command, $tokens, true);
}

/**
* Move a message set from current folder to an other folder
* @param string $folder destination folder
Expand All @@ -845,6 +864,25 @@ public function moveMessage($folder, $from, $to = null, $uid = false) {
return $this->requestAndResponse($command, [$set, $this->escapeString($folder)], true);
}

/**
* Move multiple messages to the target folder
*
* @param array<string> $messages List of message identifiers
* @param string $folder Destination folder
* @param bool $uid Set to true if you pass message unique identifiers instead of numbers
* @return array|bool Tokens if operation successful, false if an error occurred
*
* @throws RuntimeException
*/
public function moveManyMessages($messages, $folder, $uid = false) {
$command = $uid ? 'UID MOVE' : 'MOVE';

$set = implode(',', $messages);
$tokens = [$set, $this->escapeString($folder)];

return $this->requestAndResponse($command, $tokens, true);
}

/**
* Create a new folder (and parent folders if needed)
* @param string $folder folder name
Expand Down Expand Up @@ -1032,4 +1070,4 @@ public function enableDebug(){
public function disableDebug(){
$this->debug = false;
}
}
}