Skip to content

Commit cba7924

Browse files
committed
Update readme.md
1 parent 466405e commit cba7924

File tree

1 file changed

+67
-17
lines changed

1 file changed

+67
-17
lines changed

readme.md

Lines changed: 67 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@
2222
- [Retrieving Folders](#retrieving-folders)
2323
- [Retrieving Messages](#retrieving-messages)
2424
- [Interacting With Messages](#interacting-with-messages)
25-
- [Real Time Monitoring](#idling-on-folders)
25+
- [Creating Draft Messages](#creating-draft-messages)
26+
- [Real Time Monitoring](#idling-on-folders-real-time-monitoring)
2627

2728
## Requirements
2829

@@ -103,7 +104,7 @@ $mailbox = new Mailbox([
103104

104105
#### Debugging
105106

106-
The `debug` configuration option controls the logging behavior during the IMAP connection process. It accepts the following values:
107+
The `debug` configuration option controls logging behavior for the mailbox. It accepts the following values:
107108

108109
**Boolean:**
109110
- `false` – (Default) Disables debugging output
@@ -375,18 +376,32 @@ This class offers a rich set of helper methods for interacting with individual e
375376
The `Message` class provides several methods to access basic properties:
376377

377378
**UID and Flags**
378-
- `uid()`: Returns the unique identifier (UID) of the message.
379-
- `flags()`: Returns an array of flags currently set on the message.
379+
- `$message->uid()`: Returns the unique identifier (UID) of the message.
380+
- `$message->flags()`: Returns an array of flags currently set on the message.
380381

381382
**Headers and Contents**
382-
- `headers()`: Returns the raw headers as a string.
383-
- `contents()`: Returns the raw message content.
384-
- `hasHeaders()` / `hasContents()`: Determine whether the message has headers or contents.
383+
- `$message->headers()`: Returns the raw headers as a string.
384+
- `$message->contents()`: Returns the raw message content.
385+
- `$message->hasHeaders()` / `hasContents()`: Determine whether the message has headers or contents.
385386

386387
**Metadata**
387-
- `subject()`: Returns the subject of the message.
388-
- `date()`: Returns the message’s date as a Carbon instance (if available).
389-
- `messageId()`: Retrieves the Message-ID header (globally unique identifier for the message).
388+
- `$message->subject()`: Returns the subject of the message.
389+
- `$message->date()`: Returns the message’s date as a Carbon instance (if available).
390+
- `$message->messageId()`: Retrieves the Message-ID header (globally unique identifier for the message).
391+
392+
#### Additional Message Details
393+
394+
In addition to the methods shown above, the `Message` class provides several additional helpers:
395+
396+
**Flag Checking**
397+
Quickly check whether a message has a specific flag:
398+
399+
- `$message->isSeen()`: Determine if the message marked as `\Seen`
400+
- `$message->isDraft()`: Determine if the message marked as `\Draft`
401+
- `$message->isRecent()`: Determine if the message marked as `\Recent`
402+
- `$message->isFlagged()`: Determine if the message marked as `\Flagged`
403+
- `$message->isDeleted()`: Determine if the message marked as `\Deleted`
404+
- `$message->isAnswered()`: Determine if the message marked as `\Answered`
390405

391406
#### Address Handling
392407

@@ -420,8 +435,8 @@ Messages that include attachments can be inspected with:
420435
The class also provides methods to modify message flags, which help you manage the state of a message:
421436

422437
**Marking as Seen/Unseen**
423-
- `markSeen($expunge = true)`: Marks the message as read.
424-
- `unmarkSeen($expunge = true)`: Marks the message as unread.
438+
- `markSeen()`: Marks the message as read.
439+
- `unmarkSeen()`: Marks the message as unread.
425440
- *Aliases:* `markRead()` and `markUnread()`.
426441

427442
**Other Flags**
@@ -431,15 +446,16 @@ The class also provides methods to modify message flags, which help you manage t
431446
- `markDraft()` / `unmarkDraft()`
432447
- `markRecent()` / `unmarkRecent()`
433448

434-
All these methods work by invoking the underlying IMAP `STORE` command (with the appropriate flag and operation), and optionally expunging the folder afterward.
449+
All these methods work by invoking the underlying IMAP `STORE` command (with the appropriate flag and operation).
435450

436451
#### Message Manipulation
437452

438-
Beyond just flagging, you can move or copy messages between folders, or even delete them:
453+
Beyond just flagging, you can move or copy messages between folders, as well as delete them:
439454

440-
- `copy(string $folder, bool $expunge = true)`: Copies the message to the specified folder.
441-
- `move(string $folder, bool $expunge = true)`: Moves the message to the specified folder.
442-
- `delete(bool $expunge = true)`: Marks the message as deleted and, if desired, expunges it from the folder.
455+
- `copy(string $folder)`: Copies the message to the specified folder.
456+
- `move(string $folder, bool $expunge = false)`: Moves the message to the specified folder.
457+
- `restore()`: Restores the message from the trash.
458+
- `delete(bool $expunge = false)`: Marks the message as deleted and, if desired, expunges it from the folder.
443459

444460
#### Example: Interacting with a Retrieved Message
445461

@@ -487,6 +503,40 @@ $message->move('Archive');
487503
$message->delete();
488504
```
489505

506+
### Creating Draft Messages
507+
508+
ImapEngine allows you to create draft messages and save them to the server for later editing or sending.
509+
510+
To create a new draft message, you may use the `append()` method on a folder instance:
511+
512+
```php
513+
use DirectoryTree\ImapEngine\DraftMessage;
514+
515+
$uid = $inbox->messages()->append(
516+
new DraftMessage(
517+
from: = '[email protected]',
518+
519+
subject: = 'Hello World'
520+
text: = 'This is the message body.',
521+
html: = '<p>This is the message body.</p>',
522+
)
523+
);
524+
```
525+
526+
Draft messages also accept attachments:
527+
528+
```php
529+
$inbox->messages()->append(
530+
new DraftMessage(
531+
// ...
532+
attachments: [
533+
'/path/to/attachment.pdf',
534+
'/path/to/another-attachment.jpg',
535+
]
536+
)
537+
);
538+
````
539+
490540
### Idling on Folders (Real Time Monitoring)
491541

492542
ImapEngine supports real-time monitoring of folders via the IMAP IDLE command.

0 commit comments

Comments
 (0)