@@ -291,6 +291,48 @@ public static function make(int $uid, ?int $msglist, Client $client, string $raw
291
291
return $ instance ;
292
292
}
293
293
294
+ /**
295
+ * Create a new message instance by reading and loading a file or remote location
296
+ *
297
+ * @throws RuntimeException
298
+ * @throws MessageContentFetchingException
299
+ * @throws ResponseException
300
+ * @throws ImapBadRequestException
301
+ * @throws InvalidMessageDateException
302
+ * @throws ConnectionFailedException
303
+ * @throws ImapServerErrorException
304
+ * @throws ReflectionException
305
+ * @throws AuthFailedException
306
+ * @throws MaskNotFoundException
307
+ */
308
+ public static function fromFile ($ filename ): Message {
309
+ $ reflection = new ReflectionClass (self ::class);
310
+ /** @var Message $instance */
311
+ $ instance = $ reflection ->newInstanceWithoutConstructor ();
312
+ $ instance ->boot ();
313
+
314
+ $ default_mask = ClientManager::getMask ("message " );
315
+ if ($ default_mask != "" ){
316
+ $ instance ->setMask ($ default_mask );
317
+ }else {
318
+ throw new MaskNotFoundException ("Unknown message mask provided " );
319
+ }
320
+
321
+ $ email = file_get_contents ($ filename );
322
+ if (!str_contains ($ email , "\r\n" )){
323
+ $ email = str_replace ("\n" , "\r\n" , $ email );
324
+ }
325
+ $ raw_header = substr ($ email , 0 , strpos ($ email , "\r\n\r\n" ));
326
+ $ raw_body = substr ($ email , strlen ($ raw_header )+8 );
327
+
328
+ $ instance ->parseRawHeader ($ raw_header );
329
+ $ instance ->parseRawBody ($ raw_body );
330
+
331
+ $ instance ->setUid (0 );
332
+
333
+ return $ instance ;
334
+ }
335
+
294
336
/**
295
337
* Boot a new instance
296
338
*/
0 commit comments