You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Once you retrieve messages from a folder using methods like `$inbox->messages()->get()`, you'll receive instances of the `Message` class.
265
+
266
+
This class offers a rich set of helper methods for interacting with individual emails, making it easy to inspect, modify, and manipulate messages.
267
+
268
+
##### Retrieving Message Information
269
+
270
+
The `Message` class provides several methods to access basic properties:
271
+
272
+
-**UID and Flags**
273
+
-`uid()`: Returns the unique identifier (UID) of the message.
274
+
-`flags()`: Returns an array of flags currently set on the message.
275
+
276
+
-**Headers and Contents**
277
+
-`headers()`: Returns the raw headers as a string.
278
+
-`contents()`: Returns the raw message content.
279
+
-`hasHeaders()` / `hasContents()`: Determine whether the message has headers or contents.
280
+
281
+
-**Metadata**
282
+
-`subject()`: Returns the subject of the message.
283
+
-`date()`: Returns the message’s date as a Carbon instance (if available).
284
+
-`messageId()`: Retrieves the Message-ID header (globally unique identifier for the message).
285
+
286
+
##### Address Handling
287
+
288
+
To conveniently work with email addresses, the `Message` class includes methods that return addresses as instances of the `Address` class:
289
+
290
+
-`from()`: The sender’s address.
291
+
-`sender()`: The actual sender (if different from "from").
292
+
-`replyTo()`: The reply-to address.
293
+
-`inReplyTo()`: The In-Reply-To address.
294
+
-`to()`: An array of recipient addresses.
295
+
-`cc()`: An array of CC addresses.
296
+
-`bcc()`: An array of BCC addresses.
297
+
298
+
##### Content Retrieval
299
+
300
+
For accessing the message content in different formats:
301
+
302
+
-`html()`: Returns the HTML version of the message (if available).
303
+
-`text()`: Returns the plain text version of the message (if available).
304
+
305
+
##### Attachment Handling
306
+
307
+
Messages that include attachments can be inspected with:
308
+
309
+
-`attachments()`: Returns an array of `Attachment` objects.
310
+
-`hasAttachments()`: Checks if the message contains any attachments.
311
+
-`attachmentCount()`: Returns the number of attachments in the message.
312
+
313
+
##### Flag Operations
314
+
315
+
The class also provides methods to modify message flags, which help you manage the state of a message:
316
+
317
+
-**Marking as Seen/Unseen**
318
+
-`markSeen($expunge = true)`: Marks the message as read.
319
+
-`unmarkSeen($expunge = true)`: Marks the message as unread.
320
+
-*Aliases:*`markRead()` and `markUnread()`.
321
+
322
+
-**Other Flags**
323
+
-`markAnswered()` / `unmarkAnswered()`
324
+
-`markFlagged()` / `unmarkFlagged()`
325
+
-`markDeleted()` / `unmarkDeleted()`
326
+
-`markDraft()` / `unmarkDraft()`
327
+
-`markRecent()` / `unmarkRecent()`
328
+
329
+
All these methods work by invoking the underlying IMAP `STORE` command (with the appropriate flag and operation), and optionally expunging the folder afterward.
330
+
331
+
##### Message Manipulation
332
+
333
+
Beyond just flagging, you can move or copy messages between folders, or even delete them:
334
+
335
+
-`copy(string $folder, bool $expunge = true)`: Copies the message to the specified folder.
336
+
-`move(string $folder, bool $expunge = true)`: Moves the message to the specified folder.
337
+
-`delete(bool $expunge = true)`: Marks the message as deleted and, if desired, expunges it from the folder.
338
+
339
+
##### Parsing and String Conversion
340
+
341
+
-`parse()`: Parses the raw message data into a `MailMimeMessage` instance for deeper inspection (e.g., extracting structured content, attachments, etc.).
342
+
> **Note:** An exception is thrown if both headers and contents are empty.
343
+
-`__toString()`: Converts the message back to its full raw string (headers and contents combined), which is useful for logging or re-sending the email.
344
+
345
+
---
346
+
347
+
##### Example: Interacting with a Retrieved Message
0 commit comments