Skip to content

Commit b5416f5

Browse files
committed
Messag class extended
1 parent bdea94a commit b5416f5

File tree

4 files changed

+173
-4
lines changed

4 files changed

+173
-4
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ All notable changes to `webklex/laravel-imap` will be documented in this file.
55
Updates should follow the [Keep a CHANGELOG](http://keepachangelog.com/) principles.
66

77
## [UNRELEASED]
8+
-Code commented
9+
-A whole bunch of functions and features added. To many to mention all of them ;)
10+
-Readme file extened
811

12+
## 0.0.1 - 2017-03-04
913
### Added
1014
- new laravel-imap package

README.md

Lines changed: 54 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ or you can publish groups individually.
5757
php artisan vendor:publish --provider="Webklex\IMAP\Providers\LaravelServiceProvider" --tag="config"
5858
```
5959

60-
Access the IMAP Client by its Facade (Webklex\IMAP\Facades\Client).
60+
Access the IMAP Client by its Facade `\Webklex\IMAP\Facades\Client`.
6161
Therefor you might want to add an alias to the aliases array within the `config/app.php` file.
6262

6363
``` php
@@ -113,7 +113,7 @@ foreach($aMailboxes as $oMailbox){
113113
}
114114
```
115115

116-
If you use the Facade ('Webklex\IMAP\Facades\Client') please select an account first:
116+
If you use the Facade `\Webklex\IMAP\Facades\Client` please select an account first:
117117

118118
``` php
119119
use Webklex\IMAP\Facades\Client;
@@ -122,7 +122,7 @@ $oClient = Webklex\IMAP\Facades\Client::account('default');
122122
$oClient->connect();
123123
```
124124

125-
You can define your accounts inside the config/imap.php file:
125+
You can define your accounts inside the `config/imap.php` file:
126126
```
127127
'accounts' => [
128128
'default' => [
@@ -137,6 +137,57 @@ You can define your accounts inside the config/imap.php file:
137137
]
138138
```
139139

140+
## Documentation
141+
### \Webklex\IMAP\Client
142+
| Method | Arguments | Return | Description |
143+
| --------------------- | :---------------------------------------------------: | :---------------: | ----------------------------------------------------------------------------------------------------------------------------: |
144+
| setConfig | array $config | self | Set the Client configuration. Take a look at `config/imap.php` for more inspiration. |
145+
| setReadOnly | bool $readOnly | self | Set read only property and reconnect if it's necessary. |
146+
| isReadOnly | | bool | Determine if connection is in read only mode. |
147+
| isConnected | | bool | Determine if connection was established. |
148+
| checkConnection | | | Determine if connection was established and connect if not. |
149+
| connect | int $attempts | | Connect to server. |
150+
| disconnect | | | Disconnect from server. |
151+
| getFolders | bool $hierarchical, string or null $parent_folder | array | Get folders list. If hierarchical order is set to true, it will make a tree of folders, otherwise it will return flat array. |
152+
| openFolder | \Webklex\IMAP\Folder $folder | | Open a given folder. |
153+
| createFolder | string $name | | Create a new folder. |
154+
| getMessages | \Webklex\IMAP\Folder $folder, string $criteria | array | Get messages from folder. |
155+
| getQuota | | array | Retrieve the quota level settings, and usage statics per mailbox |
156+
| getQuotaRoot | string $quota_root | array | Retrieve the quota settings per user |
157+
| countMessages | | int | Gets the number of messages in the current mailbox |
158+
| countRecentMessages | | int | Gets the number of recent messages in current mailbox |
159+
| getAlerts | | array | Returns all IMAP alert messages that have occurred |
160+
| getErrors | | array | Returns all of the IMAP errors that have occurred |
161+
| getLastError | | string | Gets the last IMAP error that occurred during this page request |
162+
| expunge | | bool | Delete all messages marked for deletion |
163+
| checkCurrentMailbox | | object | Check current mailbox |
164+
165+
### \Webklex\IMAP\Message
166+
| Method | Arguments | Return | Description |
167+
| --------------------- | :---------------------------------------------------: | :---------------: | ---------------------------------------: |
168+
| delete | | | Delete the current Message |
169+
| restore | | | Restore a deleted Message |
170+
| copy | string $mailbox, int $options | | Copy the current Messages to a mailbox |
171+
| move | string $mailbox, int $options | | Move the current Messages to a mailbox |
172+
| moveToFolder | string $mailbox | | Move the Message into an other Folder |
173+
| hasTextBody | | | Check if the Message has a text body |
174+
| hasHTMLBody | | | Check if the Message has a html body |
175+
| getTextBody | | | Get the Message text body |
176+
| getHTMLBody | | | Get the Message html body |
177+
178+
### \Webklex\IMAP\Folder
179+
| Method | Arguments | Return | Description |
180+
| --------------------- | :-------------------------------------------------------: | :---------------: | ------------------------------------------------: |
181+
| hasChildren | | bool | Determine if folder has children. |
182+
| setChildren | array $children | self | Set children. |
183+
| getMessages | string $criteria | array | Get messages. |
184+
| delete | | | Delete the current Mailbox |
185+
| move | string $mailbox | | Move or Rename the current Mailbox |
186+
| getStatus | integer $options | object | Returns status information on a mailbox |
187+
| appendMessage | string $message, string $options, string $internal_date | bool | Append a string message to the current mailbox |
188+
189+
190+
140191
## Change log
141192

142193
Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently.

src/IMAP/Folder.php

Lines changed: 63 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ class Folder {
9999
*
100100
* @param \Webklex\IMAP\Client $client
101101
*
102-
* @param $folder
102+
* @param object $folder
103103
*/
104104
public function __construct(Client $client, $folder) {
105105
$this->client = $client;
@@ -125,9 +125,13 @@ public function hasChildren() {
125125
* Set children.
126126
*
127127
* @param array $children
128+
*
129+
* @return self
128130
*/
129131
public function setChildren($children = []) {
130132
$this->children = $children;
133+
134+
return $this;
131135
}
132136

133137
/**
@@ -180,4 +184,62 @@ protected function parseAttributes($attributes) {
180184
$this->referal = ($attributes & LATT_REFERRAL) ? true : false;
181185
$this->has_children = ($attributes & LATT_HASCHILDREN) ? true : false;
182186
}
187+
188+
/**
189+
* Delete the current Mailbox
190+
*
191+
* @return bool
192+
*/
193+
public function delete(){
194+
$status = imap_deletemailbox($this->client->connection, $this->path);
195+
$this->client->expunge();
196+
197+
return $status;
198+
}
199+
200+
/**
201+
* Move or Rename the current Mailbox
202+
*
203+
* @param string $target_mailbox
204+
*
205+
* @return bool
206+
*/
207+
public function move($target_mailbox){
208+
$status = imap_renamemailbox($this->client->connection, $this->path, $target_mailbox);
209+
$this->client->expunge();
210+
211+
return $status;
212+
}
213+
214+
/**
215+
* Returns status information on a mailbox
216+
*
217+
* @param string $options
218+
* SA_MESSAGES - set $status->messages to the number of messages in the mailbox
219+
* SA_RECENT - set $status->recent to the number of recent messages in the mailbox
220+
* SA_UNSEEN - set $status->unseen to the number of unseen (new) messages in the mailbox
221+
* SA_UIDNEXT - set $status->uidnext to the next uid to be used in the mailbox
222+
* SA_UIDVALIDITY - set $status->uidvalidity to a constant that changes when uids for the mailbox may no longer be valid
223+
* SA_ALL - set all of the above
224+
*
225+
* @return object
226+
*/
227+
public function getStatus($options){
228+
return imap_status($this->client->connection, $this->path, $options);
229+
}
230+
231+
232+
233+
/**
234+
* Append a string message to the current mailbox
235+
*
236+
* @param string $message
237+
* @param string $options
238+
* @param string $internal_date
239+
*
240+
* @return bool
241+
*/
242+
public function appendMessage($message, $options = null, $internal_date = null){
243+
return imap_append($this->client->connection, $this->path, $message, $options, $internal_date);
244+
}
183245
}

src/IMAP/Message.php

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ class Message {
9090
* @const integer ENC_BASE64
9191
* @const integer ENC_QUOTED_PRINTABLE
9292
* @const integer ENC_OTHER
93+
*
94+
* @const integer FT_UID
9395
*/
9496
const TYPE_TEXT = 0;
9597
const TYPE_MULTIPART = 1;
@@ -108,6 +110,8 @@ class Message {
108110
const ENC_QUOTED_PRINTABLE = 4;
109111
const ENC_OTHER = 5;
110112

113+
const FT_UID = 1;
114+
111115
/**
112116
* Message constructor.
113117
*
@@ -124,6 +128,30 @@ public function __construct($uid, $msglist, Client $client) {
124128
$this->parseBody();
125129
}
126130

131+
/**
132+
* Copy the current Messages to a mailbox
133+
*
134+
* @param $mailbox
135+
* @param int $options
136+
*
137+
* @return bool
138+
*/
139+
public function copy($mailbox, $options = 0){
140+
return imap_mail_copy($this->client->connection, $this->msglist, $mailbox, $options);
141+
}
142+
143+
/**
144+
* Move the current Messages to a mailbox
145+
*
146+
* @param $mailbox
147+
* @param int $options
148+
*
149+
* @return bool
150+
*/
151+
public function move($mailbox, $options = 0){
152+
return imap_mail_move($this->client->connection, $this->msglist, $mailbox, $options);
153+
}
154+
127155
/**
128156
* Check if the Message has a text body
129157
*
@@ -466,4 +494,28 @@ public function moveToFolder($mailbox = 'INBOX'){
466494
}
467495
return false;
468496
}
497+
498+
/**
499+
* Delete the current Message
500+
*
501+
* @return bool
502+
*/
503+
public function delete(){
504+
$status = imap_delete($this->client->connection, $this->uid, self::FT_UID);
505+
$this->client->expunge();
506+
507+
$this->parseHeader();
508+
$this->parseBody();
509+
510+
return $status;
511+
}
512+
513+
/**
514+
* Restore a deleted Message
515+
*
516+
* @return bool
517+
*/
518+
public function restore(){
519+
return imap_undelete($this->client->connection, $this->message_no);
520+
}
469521
}

0 commit comments

Comments
 (0)