Skip to content

Commit 4fa65a6

Browse files
committed
Release 2.0 using namespace. See migration notes in README.md
1 parent f0e52f5 commit 4fa65a6

File tree

4 files changed

+36
-21
lines changed

4 files changed

+36
-21
lines changed

README.md

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,28 @@ ImapMailbox is PHP class to access mailbox by POP3/IMAP/NNTP using IMAP extensio
99
* Change email status (see [imap_setflag_full](http://php.net/imap_setflag_full))
1010
* Delete email
1111

12-
### [Usage example](https://github.com/barbushin/php-imap/blob/master/example/index.php)
13-
```php
14-
<?php
12+
### Installation by Composer
13+
14+
{
15+
"require": {
16+
"php-imap/php-imap": "2.*"
17+
}
18+
}
19+
20+
### Migration from `v1.*` to `v2.*`
1521

16-
require_once('../src/ImapMailbox.php');
22+
Just add following code in the head of your script:
1723

18-
// IMAP must be enabled in Google Mail Settings
19-
define('GMAIL_EMAIL', '[email protected]');
20-
define('GMAIL_PASSWORD', '*********');
21-
define('ATTACHMENTS_DIR', __DIR__);
24+
use PhpImap\Mailbox as ImapMailbox;
25+
use PhpImap\IncomingMail;
26+
use PhpImap\IncomingMailAttachment;
27+
28+
### [Usage example](https://github.com/barbushin/php-imap/blob/master/example/index.php)
29+
```php
2230

23-
$mailbox = new ImapMailbox('{imap.gmail.com:993/imap/ssl}INBOX', GMAIL_EMAIL, GMAIL_PASSWORD, ATTACHMENTS_DIR);
31+
$mailbox = new PhpImap\Mailbox('{imap.gmail.com:993/imap/ssl}INBOX', '[email protected]', '*********', __DIR__);
2432
$mails = array();
2533

26-
// Get some mail
2734
$mailsIds = $mailbox->searchMailBox('ALL');
2835
if(!$mailsIds) {
2936
die('Mailbox is empty');

composer.json

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
{
22
"name": "php-imap/php-imap",
33
"description": "PHP class to access mailbox by POP3/IMAP/NNTP using IMAP extension",
4-
"keywords": ["PHP", "IMAP", "mail"],
4+
"keywords": [
5+
"PHP",
6+
"IMAP",
7+
"mail"
8+
],
59
"homepage": "https://github.com/barbushin/php-imap",
610
"license": "BSD 3-Clause",
711
"type": "library",
@@ -16,7 +20,9 @@
1620
"php": ">=5.3.0"
1721
},
1822
"autoload": {
19-
"classmap": ["src/"]
23+
"psr-0": {
24+
"PhpImap": "src/"
25+
}
2026
},
21-
"minimum-stability": "dev"
27+
"minimum-stability": "stable"
2228
}

src/IncomingMail.php renamed to src/PhpImap/IncomingMail.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?php
1+
<?php namespace PhpImap;
22

33
/**
44
* @see https://github.com/barbushin/php-imap

src/ImapMailbox.php renamed to src/PhpImap/Mailbox.php

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
<?php
1+
<?php namespace PhpImap;
2+
3+
use stdClass;
24

35
/**
46
* @see https://github.com/barbushin/php-imap
57
* @author Barbushin Sergey http://linkedin.com/in/barbushin
68
*/
7-
class ImapMailbox {
9+
class Mailbox {
810

911
protected $imapPath;
1012
protected $imapLogin;
@@ -62,7 +64,7 @@ public function getImapStream($forceConnection = true) {
6264
protected function initImapStream() {
6365
$imapStream = @imap_open($this->imapPath, $this->imapLogin, $this->imapPassword, $this->imapOptions, $this->imapRetriesNum, $this->imapParams);
6466
if(!$imapStream) {
65-
throw new ImapMailboxException('Connection error: ' . imap_last_error());
67+
throw new Exception('Connection error: ' . imap_last_error());
6668
}
6769
return $imapStream;
6870
}
@@ -106,7 +108,7 @@ public function createMailbox() {
106108
* This function returns an object containing status information.
107109
* The object has the following properties: messages, recent, unseen, uidnext, and uidvalidity.
108110
*
109-
* @return stdClass | FALSE if the box doesn't exist
111+
* @return stdClass if the box doesn't exist
110112
*/
111113

112114
public function statusMailbox() {
@@ -253,7 +255,7 @@ public function markMailsAsImportant(array $mailId) {
253255
* Causes a store to add the specified flag to the flags set for the mails in the specified sequence.
254256
*
255257
* @param array $mailsIds
256-
* @param $flag Flags which you can set are \Seen, \Answered, \Flagged, \Deleted, and \Draft as defined by RFC2060.
258+
* @param string $flag which you can set are \Seen, \Answered, \Flagged, \Deleted, and \Draft as defined by RFC2060.
257259
* @return bool
258260
*/
259261
public function setFlag(array $mailsIds, $flag) {
@@ -264,7 +266,7 @@ public function setFlag(array $mailsIds, $flag) {
264266
* Cause a store to delete the specified flag to the flags set for the mails in the specified sequence.
265267
*
266268
* @param array $mailsIds
267-
* @param $flag Flags which you can set are \Seen, \Answered, \Flagged, \Deleted, and \Draft as defined by RFC2060.
269+
* @param string $flag which you can set are \Seen, \Answered, \Flagged, \Deleted, and \Draft as defined by RFC2060.
268270
* @return bool
269271
*/
270272
public function clearFlag(array $mailsIds, $flag) {
@@ -591,6 +593,6 @@ public function __destruct() {
591593
}
592594
}
593595

594-
class ImapMailboxException extends Exception {
596+
class Exception extends \Exception {
595597

596598
}

0 commit comments

Comments
 (0)