Skip to content

Commit c888a38

Browse files
committed
Protocol::moveMessage() method added Webklex#29
1 parent 4995a3e commit c888a38

File tree

4 files changed

+44
-1
lines changed

4 files changed

+44
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Updates should follow the [Keep a CHANGELOG](http://keepachangelog.com/) princip
1010
- Missing variable check added to prevent exception while parsing an address [webklex/laravel-imap #356](https://github.com/Webklex/laravel-imap/issues/356)
1111

1212
### Added
13-
- NaN
13+
- `Protocol::moveMessage()` method added #29
1414

1515
### Affected Classes
1616
- [Message::class](src/Message.php)

src/Connection/Protocols/ImapProtocol.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -805,6 +805,25 @@ public function copyMessage($folder, $from, $to = null) {
805805
return $this->requestAndResponse('COPY', [$set, $this->escapeString($folder)], true);
806806
}
807807

808+
/**
809+
* Move a message set from current folder to an other folder
810+
* @param string $folder destination folder
811+
* @param $from
812+
* @param int|null $to if null only one message ($from) is fetched, else it's the
813+
* last message, INF means last message available
814+
*
815+
* @return bool success
816+
* @throws RuntimeException
817+
*/
818+
public function moveMessage($folder, $from, $to = null) {
819+
$set = (int)$from;
820+
if ($to !== null) {
821+
$set .= ':' . ($to == INF ? '*' : (int)$to);
822+
}
823+
824+
return $this->requestAndResponse('MOVE', [$set, $this->escapeString($folder)], true);
825+
}
826+
808827
/**
809828
* Create a new folder (and parent folders if needed)
810829
* @param string $folder folder name

src/Connection/Protocols/LegacyProtocol.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,19 @@ public function copyMessage($folder, $from, $to = null) {
357357
return \imap_mail_copy($this->stream, $from, $folder, IMAP::CP_UID);
358358
}
359359

360+
/**
361+
* Move a message set from current folder to an other folder
362+
* @param string $folder destination folder
363+
* @param $from
364+
* @param int|null $to if null only one message ($from) is fetched, else it's the
365+
* last message, INF means last message available
366+
*
367+
* @return bool success
368+
*/
369+
public function moveMessage($folder, $from, $to = null) {
370+
return \imap_mail_move($this->stream, $from, $folder, IMAP::CP_UID);
371+
}
372+
360373
/**
361374
* Create a new folder (and parent folders if needed)
362375
* @param string $folder folder name

src/Connection/Protocols/ProtocolInterface.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,17 @@ public function appendMessage($folder, $message, $flags = null, $date = null);
184184
*/
185185
public function copyMessage($folder, $from, $to = null);
186186

187+
/**
188+
* Move a message set from current folder to an other folder
189+
* @param string $folder destination folder
190+
* @param $from
191+
* @param int|null $to if null only one message ($from) is fetched, else it's the
192+
* last message, INF means last message available
193+
*
194+
* @return bool success
195+
*/
196+
public function moveMessage($folder, $from, $to = null);
197+
187198
/**
188199
* Create a new folder
189200
*

0 commit comments

Comments
 (0)