@@ -1141,7 +1141,25 @@ public function moveMessage(string $folder, $from, ?int $to = null, int|string $
1141
1141
$ set = $ this ->buildSet ($ from , $ to );
1142
1142
$ command = $ this ->buildUIDCommand ("MOVE " , $ uid );
1143
1143
1144
- return $ this ->requestAndResponse ($ command , [$ set , $ this ->escapeString ($ folder )], true );
1144
+ $ result = $ this ->requestAndResponse ($ command , [$ set , $ this ->escapeString ($ folder )], true );
1145
+ // RFC4315 fallback to COPY, STORE and EXPUNGE.
1146
+ // Required for cases where MOVE isn't supported by the server. So we copy the message to the target folder,
1147
+ // mark the original message as deleted and expunge the mailbox.
1148
+ // See the following links for more information:
1149
+ // - https://github.com/freescout-help-desk/freescout/issues/4313
1150
+ // - https://github.com/Webklex/php-imap/issues/123
1151
+ if (!$ result ->boolean ()) {
1152
+ $ result = $ this ->copyMessage ($ folder , $ from , $ to , $ uid );
1153
+ if (!$ result ->boolean ()) {
1154
+ return $ result ;
1155
+ }
1156
+ $ result = $ this ->store (['\Deleted ' ], $ from , $ to , null , true , $ uid );
1157
+ if (!$ result ->boolean ()) {
1158
+ return $ result ;
1159
+ }
1160
+ return $ this ->expunge ();
1161
+ }
1162
+ return $ result ;
1145
1163
}
1146
1164
1147
1165
/**
@@ -1163,7 +1181,27 @@ public function moveManyMessages(array $messages, string $folder, int|string $ui
1163
1181
$ set = implode (', ' , $ messages );
1164
1182
$ tokens = [$ set , $ this ->escapeString ($ folder )];
1165
1183
1166
- return $ this ->requestAndResponse ($ command , $ tokens , true );
1184
+ $ result = $ this ->requestAndResponse ($ command , $ tokens , true );
1185
+ // RFC4315 fallback to COPY, STORE and EXPUNGE.
1186
+ // Required for cases where MOVE isn't supported by the server. So we copy the message to the target folder,
1187
+ // mark the original message as deleted and expunge the mailbox.
1188
+ // See the following links for more information:
1189
+ // - https://github.com/freescout-help-desk/freescout/issues/4313
1190
+ // - https://github.com/Webklex/php-imap/issues/123
1191
+ if (!$ result ->boolean ()) {
1192
+ $ result = $ this ->copyManyMessages ($ messages , $ folder , $ uid );
1193
+ if (!$ result ->boolean ()) {
1194
+ return $ result ;
1195
+ }
1196
+ foreach ($ messages as $ message ) {
1197
+ $ result = $ this ->store (['\Deleted ' ], $ message , $ message , null , true , $ uid );
1198
+ if (!$ result ->boolean ()) {
1199
+ return $ result ;
1200
+ }
1201
+ }
1202
+ return $ this ->expunge ();
1203
+ }
1204
+ return $ result ;
1167
1205
}
1168
1206
1169
1207
/**
0 commit comments