Skip to content

Commit 9786bf4

Browse files
committed
trivial example fix; replace Message -> Mail in all code
migration: replace in called methods names Message -> Mail
1 parent 79fbeb7 commit 9786bf4

File tree

2 files changed

+68
-66
lines changed

2 files changed

+68
-66
lines changed

ImapMailbox.php

+57-57
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ protected function initImapStream() {
5656
protected function disconnect() {
5757
$imapStream = $this->getImapStream(false);
5858
if($imapStream) {
59-
$this->expungeDeletedMessages();
59+
$this->expungeDeletedMails();
6060
imap_close($imapStream);
6161
}
6262
}
@@ -68,8 +68,8 @@ protected function disconnect() {
6868
* Date - current system time formatted according to RFC2822
6969
* Driver - protocol used to access this mailbox: POP3, IMAP, NNTP
7070
* Mailbox - the mailbox name
71-
* Nmsgs - number of messages in the mailbox
72-
* Recent - number of recent messages in the mailbox
71+
* Nmsgs - number of mails in the mailbox
72+
* Recent - number of recent mails in the mailbox
7373
*
7474
* @return stdClass
7575
*/
@@ -79,35 +79,35 @@ public function checkMailbox() {
7979

8080
/*
8181
* This function performs a search on the mailbox currently opened in the given IMAP stream.
82-
* For example, to match all unanswered messages sent by Mom, you'd use: "UNANSWERED FROM mom".
82+
* For example, to match all unanswered mails sent by Mom, you'd use: "UNANSWERED FROM mom".
8383
* Searches appear to be case insensitive. This list of criteria is from a reading of the UW
8484
* c-client source code and may be incomplete or inaccurate (see also RFC2060, section 6.4.4).
8585
*
8686
* @param string $criteria String, delimited by spaces, in which the following keywords are allowed. Any multi-word arguments (e.g. FROM "joey smith") must be quoted. Results will match all criteria entries.
87-
* ALL - return all messages matching the rest of the criteria
88-
* ANSWERED - match messages with the \\ANSWERED flag set
89-
* BCC "string" - match messages with "string" in the Bcc: field
90-
* BEFORE "date" - match messages with Date: before "date"
91-
* BODY "string" - match messages with "string" in the body of the message
92-
* CC "string" - match messages with "string" in the Cc: field
93-
* DELETED - match deleted messages
94-
* FLAGGED - match messages with the \\FLAGGED (sometimes referred to as Important or Urgent) flag set
95-
* FROM "string" - match messages with "string" in the From: field
96-
* KEYWORD "string" - match messages with "string" as a keyword
97-
* NEW - match new messages
98-
* OLD - match old messages
99-
* ON "date" - match messages with Date: matching "date"
100-
* RECENT - match messages with the \\RECENT flag set
101-
* SEEN - match messages that have been read (the \\SEEN flag is set)
102-
* SINCE "date" - match messages with Date: after "date"
103-
* SUBJECT "string" - match messages with "string" in the Subject:
104-
* TEXT "string" - match messages with text "string"
105-
* TO "string" - match messages with "string" in the To:
106-
* UNANSWERED - match messages that have not been answered
107-
* UNDELETED - match messages that are not deleted
108-
* UNFLAGGED - match messages that are not flagged
109-
* UNKEYWORD "string" - match messages that do not have the keyword "string"
110-
* UNSEEN - match messages which have not been read yet
87+
* ALL - return all mails matching the rest of the criteria
88+
* ANSWERED - match mails with the \\ANSWERED flag set
89+
* BCC "string" - match mails with "string" in the Bcc: field
90+
* BEFORE "date" - match mails with Date: before "date"
91+
* BODY "string" - match mails with "string" in the body of the mail
92+
* CC "string" - match mails with "string" in the Cc: field
93+
* DELETED - match deleted mails
94+
* FLAGGED - match mails with the \\FLAGGED (sometimes referred to as Important or Urgent) flag set
95+
* FROM "string" - match mails with "string" in the From: field
96+
* KEYWORD "string" - match mails with "string" as a keyword
97+
* NEW - match new mails
98+
* OLD - match old mails
99+
* ON "date" - match mails with Date: matching "date"
100+
* RECENT - match mails with the \\RECENT flag set
101+
* SEEN - match mails that have been read (the \\SEEN flag is set)
102+
* SINCE "date" - match mails with Date: after "date"
103+
* SUBJECT "string" - match mails with "string" in the Subject:
104+
* TEXT "string" - match mails with text "string"
105+
* TO "string" - match mails with "string" in the To:
106+
* UNANSWERED - match mails that have not been answered
107+
* UNDELETED - match mails that are not deleted
108+
* UNFLAGGED - match mails that are not flagged
109+
* UNKEYWORD "string" - match mails that do not have the keyword "string"
110+
* UNSEEN - match mails which have not been read yet
111111
*
112112
* @return array Mails ids
113113
*/
@@ -117,35 +117,35 @@ public function searchMailbox($criteria = 'ALL') {
117117
}
118118

119119
/*
120-
* Marks messages listed in mailId for deletion.
120+
* Marks mails listed in mailId for deletion.
121121
* @return bool
122122
*/
123-
public function deleteMessage($mailId) {
123+
public function deleteMail($mailId) {
124124
return imap_delete($this->getImapStream(), $mailId, FT_UID);
125125
}
126126

127127
/*
128-
* Deletes all the messages marked for deletion by imap_delete(), imap_mail_move(), or imap_setflag_full().
128+
* Deletes all the mails marked for deletion by imap_delete(), imap_mail_move(), or imap_setflag_full().
129129
* @return bool
130130
*/
131-
public function expungeDeletedMessages() {
131+
public function expungeDeletedMails() {
132132
return imap_expunge($this->getImapStream());
133133
}
134134

135-
public function markMessageAsRead($mailId) {
135+
public function markMailAsRead($mailId) {
136136
$this->setFlag($mailId, '\\Seen');
137137
}
138138

139-
public function markMessageAsUnread($mailId) {
139+
public function markMailAsUnread($mailId) {
140140
$this->clearFlag($mailId, '\\Seen');
141141
}
142142

143-
public function markMessageAsImportant($mailId) {
143+
public function markMailAsImportant($mailId) {
144144
$this->setFlag($mailId, '\\Flagged');
145145
}
146146

147147
/*
148-
* Causes a store to add the specified flag to the flags set for the messages in the specified sequence.
148+
* Causes a store to add the specified flag to the flags set for the mails in the specified sequence.
149149
*
150150
* @param array $mailsIds
151151
* @param $flag Flags which you can set are \Seen, \Answered, \Flagged, \Deleted, and \Draft as defined by RFC2060.
@@ -156,7 +156,7 @@ public function setFlag(array $mailsIds, $flag) {
156156
}
157157

158158
/*
159-
* Cause a store to delete the specified flag to the flags set for the messages in the specified sequence.
159+
* Cause a store to delete the specified flag to the flags set for the mails in the specified sequence.
160160
*
161161
* @param array $mailsIds
162162
* @param $flag Flags which you can set are \Seen, \Answered, \Flagged, \Deleted, and \Draft as defined by RFC2060.
@@ -169,23 +169,23 @@ public function clearFlag(array $mailsIds, $flag) {
169169
/*
170170
* Fetch mail headers for listed mails ids
171171
*
172-
* Returns an array of objects describing one message header each. The object will only define a property if it exists. The possible properties are:
173-
* subject - the messages subject
172+
* Returns an array of objects describing one mail header each. The object will only define a property if it exists. The possible properties are:
173+
* subject - the mails subject
174174
* from - who sent it
175175
* to - recipient
176176
* date - when was it sent
177-
* message_id - Message-ID
178-
* references - is a reference to this message id
179-
* in_reply_to - is a reply to this message id
177+
* message_id - Mail-ID
178+
* references - is a reference to this mail id
179+
* in_reply_to - is a reply to this mail id
180180
* size - size in bytes
181-
* uid - UID the message has in the mailbox
182-
* msgno - message sequence number in the mailbox
183-
* recent - this message is flagged as recent
184-
* flagged - this message is flagged
185-
* answered - this message is flagged as answered
186-
* deleted - this message is flagged for deletion
187-
* seen - this message is flagged as already read
188-
* draft - this message is flagged as being a draft
181+
* uid - UID the mail has in the mailbox
182+
* msgno - mail sequence number in the mailbox
183+
* recent - this mail is flagged as recent
184+
* flagged - this mail is flagged
185+
* answered - this mail is flagged as answered
186+
* deleted - this mail is flagged for deletion
187+
* seen - this mail is flagged as already read
188+
* draft - this mail is flagged as being a draft
189189
*
190190
* @param array $mailsIds
191191
* @return array
@@ -195,30 +195,30 @@ public function getMailsInfo(array $mailsIds) {
195195
}
196196

197197
/**
198-
* Gets messages ids sorted by some criteria
198+
* Gets mails ids sorted by some criteria
199199
*
200200
* Criteria can be one (and only one) of the following constants:
201-
* SORTDATE - message Date
201+
* SORTDATE - mail Date
202202
* SORTARRIVAL - arrival date (default)
203203
* SORTFROM - mailbox in first From address
204-
* SORTSUBJECT - message subject
204+
* SORTSUBJECT - mail subject
205205
* SORTTO - mailbox in first To address
206206
* SORTCC - mailbox in first cc address
207-
* SORTSIZE - size of message in octets
207+
* SORTSIZE - size of mail in octets
208208
*
209209
* @param int $criteria
210210
* @param bool $reverse
211211
* @return array Mails ids
212212
*/
213-
public function sortMessages($criteria = SORTARRIVAL, $reverse = true) {
213+
public function sortMails($criteria = SORTARRIVAL, $reverse = true) {
214214
return imap_sort($this->getImapStream(), $criteria, $reverse, SE_UID);
215215
}
216216

217217
/**
218-
* Get messages count in mail box
218+
* Get mails count in mail box
219219
* @return int
220220
*/
221-
public function countMessages() {
221+
public function countMails() {
222222
return imap_num_msg($this->getImapStream());
223223
}
224224

example/index.php

+11-9
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,20 @@
44

55
// IMAP must be enabled in Google Mail Settings
66
define('GMAIL_EMAIL', '[email protected]');
7-
define('GMAIL_PASSWORD', 'somepassword');
7+
define('GMAIL_PASSWORD', '*********');
88
define('ATTACHMENTS_DIR', dirname(__FILE__) . '/attachments');
99

10-
$mailbox = new ImapMailbox('{imap.gmail.com:993/imap/novalidate-cert/ssl}INBOX', GMAIL_EMAIL, GMAIL_PASSWORD, ATTACHMENTS_DIR, 'utf-8');
10+
$mailbox = new ImapMailbox('{imap.gmail.com:993/imap/ssl}INBOX', GMAIL_EMAIL, GMAIL_PASSWORD, ATTACHMENTS_DIR, 'utf-8');
1111
$mails = array();
1212

13-
// Display all e-mail
14-
foreach($mailbox->searchMailBox('ALL') as $mailId) {
15-
$mail = $mailbox->getMail($mailId);
16-
// $mailbox->setMailAsSeen($mail->id);
17-
// $mailbox->deleteMail($mail->id);
18-
$mails[] = $mail;
13+
// Get some mail
14+
$mailsIds = $mailbox->searchMailBox('ALL');
15+
if(!$mailsIds) {
16+
die('Mailbox is empty');
1917
}
2018

21-
var_dump($mails);
19+
$mailId = reset($mailsIds);
20+
$mail = $mailbox->getMail($mailId);
21+
22+
var_dump($mail);
23+
var_dump($mail->getAttachments());

0 commit comments

Comments
 (0)