Skip to content

Commit

Permalink
Release 2.0 using namespace. See migration notes in README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
barbushin committed Apr 20, 2015
1 parent f0e52f5 commit 4fa65a6
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 21 deletions.
27 changes: 17 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,28 @@ ImapMailbox is PHP class to access mailbox by POP3/IMAP/NNTP using IMAP extensio
* Change email status (see [imap_setflag_full](http://php.net/imap_setflag_full))
* Delete email

### [Usage example](https://github.com/barbushin/php-imap/blob/master/example/index.php)
```php
<?php
### Installation by Composer

{
"require": {
"php-imap/php-imap": "2.*"
}
}

### Migration from `v1.*` to `v2.*`

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

// IMAP must be enabled in Google Mail Settings
define('GMAIL_EMAIL', '[email protected]');
define('GMAIL_PASSWORD', '*********');
define('ATTACHMENTS_DIR', __DIR__);
use PhpImap\Mailbox as ImapMailbox;
use PhpImap\IncomingMail;
use PhpImap\IncomingMailAttachment;

### [Usage example](https://github.com/barbushin/php-imap/blob/master/example/index.php)
```php

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

// Get some mail
$mailsIds = $mailbox->searchMailBox('ALL');
if(!$mailsIds) {
die('Mailbox is empty');
Expand Down
12 changes: 9 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
{
"name": "php-imap/php-imap",
"description": "PHP class to access mailbox by POP3/IMAP/NNTP using IMAP extension",
"keywords": ["PHP", "IMAP", "mail"],
"keywords": [
"PHP",
"IMAP",
"mail"
],
"homepage": "https://github.com/barbushin/php-imap",
"license": "BSD 3-Clause",
"type": "library",
Expand All @@ -16,7 +20,9 @@
"php": ">=5.3.0"
},
"autoload": {
"classmap": ["src/"]
"psr-0": {
"PhpImap": "src/"
}
},
"minimum-stability": "dev"
"minimum-stability": "stable"
}
2 changes: 1 addition & 1 deletion src/IncomingMail.php → src/PhpImap/IncomingMail.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php
<?php namespace PhpImap;

/**
* @see https://github.com/barbushin/php-imap
Expand Down
16 changes: 9 additions & 7 deletions src/ImapMailbox.php → src/PhpImap/Mailbox.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
<?php
<?php namespace PhpImap;

use stdClass;

/**
* @see https://github.com/barbushin/php-imap
* @author Barbushin Sergey http://linkedin.com/in/barbushin
*/
class ImapMailbox {
class Mailbox {

protected $imapPath;
protected $imapLogin;
Expand Down Expand Up @@ -62,7 +64,7 @@ public function getImapStream($forceConnection = true) {
protected function initImapStream() {
$imapStream = @imap_open($this->imapPath, $this->imapLogin, $this->imapPassword, $this->imapOptions, $this->imapRetriesNum, $this->imapParams);
if(!$imapStream) {
throw new ImapMailboxException('Connection error: ' . imap_last_error());
throw new Exception('Connection error: ' . imap_last_error());
}
return $imapStream;
}
Expand Down Expand Up @@ -106,7 +108,7 @@ public function createMailbox() {
* This function returns an object containing status information.
* The object has the following properties: messages, recent, unseen, uidnext, and uidvalidity.
*
* @return stdClass | FALSE if the box doesn't exist
* @return stdClass if the box doesn't exist
*/

public function statusMailbox() {
Expand Down Expand Up @@ -253,7 +255,7 @@ public function markMailsAsImportant(array $mailId) {
* Causes a store to add the specified flag to the flags set for the mails in the specified sequence.
*
* @param array $mailsIds
* @param $flag Flags which you can set are \Seen, \Answered, \Flagged, \Deleted, and \Draft as defined by RFC2060.
* @param string $flag which you can set are \Seen, \Answered, \Flagged, \Deleted, and \Draft as defined by RFC2060.
* @return bool
*/
public function setFlag(array $mailsIds, $flag) {
Expand All @@ -264,7 +266,7 @@ public function setFlag(array $mailsIds, $flag) {
* Cause a store to delete the specified flag to the flags set for the mails in the specified sequence.
*
* @param array $mailsIds
* @param $flag Flags which you can set are \Seen, \Answered, \Flagged, \Deleted, and \Draft as defined by RFC2060.
* @param string $flag which you can set are \Seen, \Answered, \Flagged, \Deleted, and \Draft as defined by RFC2060.
* @return bool
*/
public function clearFlag(array $mailsIds, $flag) {
Expand Down Expand Up @@ -591,6 +593,6 @@ public function __destruct() {
}
}

class ImapMailboxException extends Exception {
class Exception extends \Exception {

}

0 comments on commit 4fa65a6

Please sign in to comment.