Skip to content

Commit

Permalink
complete refactoring v2.0, see changelog.md
Browse files Browse the repository at this point in the history
  • Loading branch information
jjaffeux committed Apr 25, 2012
1 parent 348d6a2 commit 076cbe9
Show file tree
Hide file tree
Showing 22 changed files with 608 additions and 2,700 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
@@ -1,5 +1,5 @@
language: php
script: make test
script: phpunit

php:
- 5.3
Expand Down
22 changes: 22 additions & 0 deletions CHANGELOG.md
@@ -0,0 +1,22 @@
CHANGELOG
=========

v 2.0
-----

Complete refactoring
- Travis
- Enhance -> Phpunit
- Autoload
- Composer
- Consitent API
- New Postmark JSON fields


v 1.0
-----

Initial release
- Features
- Tests
- Examples
27 changes: 0 additions & 27 deletions DBAD_license.txt

This file was deleted.

21 changes: 21 additions & 0 deletions LICENSE
@@ -0,0 +1,21 @@
The MIT License

Copyright (c) 2010 Joffrey Jaffeux

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
2 changes: 0 additions & 2 deletions Makefile

This file was deleted.

151 changes: 69 additions & 82 deletions README.md
Expand Up @@ -6,92 +6,79 @@ This is a simple API wrapper for Postmark Inbound Hook (http://developer.postmar
[![Build Status](https://secure.travis-ci.org/jjaffeux/postmark-inbound-php.png?branch=master)](http://travis-ci.org/jjaffeux/postmark-inbound-php)


Usage
Setup
-----

``` php
include 'lib/postmark_inbound.php';

//load json
$inbound = New PostmarkInbound(file_get_contents('php://input'));
// or test with $inbound = New PostmarkInbound(file_get_contents(dirname(__FILE__).'/tests/fixtures/valid_http_post.json'));

/* Content */
$inbound->from(); // Bob Bobson <bob@bob.com>
$inbound->from_name(); // Bob Bobson if not set return false
$inbound->from_email(); // <bob@bob.com>

$recipients = $inbound->to();

foreach($recipients as $recipient) {
echo $recipient->name; //if not set return false
echo $recipient->email;
}

$undisclosed_recipients = $inbound->cc();

foreach($undisclosed_recipients as $undisclosed_recipient) {
echo $undisclosed_recipient->name; //if not set return false
echo $undisclosed_recipient->email;
}

$inbound->bcc();
$inbound->tag();
$inbound->message_id();
$inbound->mailbox_hash();
$inbound->reply_to();
$inbound->html_body();
$inbound->text_body();
$inbound->date();

/* Headers */
$inbound->headers(); //default to get Date
$inbound->headers('MIME-Version');
$inbound->headers('Received-SPF');
$inbound->headers('Date');

/* Spam */
$inbound->spam(); //default to get status
$inbound->spam('X-Spam-Checker-Version');
$inbound->spam('X-Spam-Score');
$inbound->spam('X-Spam-Tests');
$inbound->spam('X-Spam-Status');

/* Attachments */
$inbound->has_attachments(); //boolean
$attachments = $inbound->attachments();

$first_attachment = $attachments->get(0);
$first_attachment->name();

$second_attachment = $attachments->get(1);
$second_attachment->content_length();

$third_attachment = $attachments->get(2); // will return FALSE if it doesn't exist

foreach($attachments as $a) {
$a->name();
$a->content_type();
$a->content_length();

$options = array(
'directory' => dirname(__FILE__).'/tests/fixtures/',
'allowed_content_types' => array('image/png', 'text/html', 'text/plain'), //optionnal
'max_content_length' => 10000 //optionnal
);

$a->download($options);
}

/* Get raw data */
$inbound::json();
$inbound::source();
require_once '../lib/Postmark/Autoloader.php';
\Postmark\Autoloader::register();

// this file should be the target of the callback you set in your postmark account
$inbound = new \Postmark\Inbound(file_get_contents('php://input'));
```

General Usage
-------------

``` php
$inbound->Subject();
$inbound->FromEmail();
$inbound->FromFull();
$inbound->FromName();
$inbound->Date();
$inbound->ReplyTo();
$inbound->MailboxHash();
$inbound->Tag();
$inbound->MessageID();
$inbound->Subject();
$inbound->TextBody();
$inbound->HtmlBody();
```

Headers
-------

``` php
$inbound->Headers(); //default to spam status
$inbound->Headers('X-Spam-Status');
$inbound->Headers('X-Spam-Checker-Version');
$inbound->Headers('X-Spam-Score');
$inbound->Headers('X-Spam-Tests');
$inbound->Headers('Received-SPF');
$inbound->Headers('MIME-Version');
$inbound->Headers('Received-SPF');
$inbound->Headers('Message-ID');
```

FAQ
---

* Using the library with codeigniter : https://github.com/jjaffeux/postmark-inbound-php/issues/1
Recipients and Undisclosed Recipients
-------------------------------------

``` php
foreach($inbound->Recipients() as $recipient) {
$recipient->Name;
$recipient->Email;
}

foreach($inbound->UndisclosedRecipients() as $undisclosedRecipient) {
$undisclosedRecipient->Name;
$undisclosedRecipient->Email;
}
```

Attachments
-------------------------------------

``` php
foreach($inbound->Attachments() as $attachment) {
$attachment->Name;
$attachment->ContentType;
$attachment->ContentLength;
$attachment->Download('/'); //takes directory as first argument
}

$inbound->HasAttachments();
```


Bug tracker
Expand All @@ -104,7 +91,7 @@ Contributions
-------------

* Fork
* Write tests (using enhance http://www.enhance-php.com/Content/Documentation/, just open test.php in your browser to launch tests)
* Write tests (phpunit in the directory to run the tests)
* Write Code
* Pull request

Expand Down Expand Up @@ -139,4 +126,4 @@ Other libraries
License
---------------------

DON'T BE A DICK PUBLIC LICENSE
MIT License
22 changes: 22 additions & 0 deletions composer.json
@@ -0,0 +1,22 @@
{
"name": "jjaffeux/postmark-inbound-php",
"type": "library",
"description": "Postmark Inbound PHP Wrapper",
"version": "2.0",
"homepage": "https://github.com/jjaffeux/postmark-inbound-php",
"keywords": ["postmark", "inbound", "wrapper", "api", "mails"],
"license": "MIT",
"authors": [
{
"name": "Joffrey Jaffeux",
"email": "j.jaffeux@gmail.com",
"homepage": "http://www.twitter.com/joffreyjaffeux"
}
],
"require": {
"php": ">=5.2"
},
"autoload": {
"psr-0": { "Postmark_": "lib/" }
}
}
10 changes: 10 additions & 0 deletions example/index.php
@@ -0,0 +1,10 @@
<?php

require_once '../lib/Postmark/Autoloader.php';
\Postmark\Autoloader::register();

// this file should be the target of the callback you set in your postmark account
//$inbound = new \Postmark\Inbound(file_get_contents('php://input'));
$inbound = new \Postmark\Inbound(file_get_contents('../fixtures/inbound.json'));

echo $inbound->Subject();
85 changes: 85 additions & 0 deletions fixtures/inbound.json
@@ -0,0 +1,85 @@
{
"From": "myUser@theirDomain.com",
"FromFull": {
"Email": "myUser@theirDomain.com",
"Name": "John Doe"
},
"To": "451d9b70cf9364d23ff6f9d51d870251569e+ahoy@inbound.postmarkapp.com",
"ToFull": [
{
"Email": "451d9b70cf9364d23ff6f9d51d870251569e+ahoy@inbound.postmarkapp.com",
"Name": ""
},
{
"Email": "451d9b70cf9364d23ff025154f870251569e+ahoy@inbound.postmarkapp.com",
"Name": "Ian Tofull"
}
],
"Cc": "\"Full name\" , \"Another Cc\" ",
"CcFull": [
{
"Email": "sample.cc@emailDomain.com",
"Name": "Full name"
},
{
"Email": "another.cc@emailDomain.com",
"Name": "Another Cc"
}
],
"ReplyTo": "myUsersReplyAddress@theirDomain.com",
"Subject": "This is an inbound message",
"MessageID": "22c74902-a0c1-4511-804f2-341342852c90",
"Date": "Thu, 5 Apr 2012 16:59:01 +0200",
"MailboxHash": "ahoy",
"TextBody": "[ASCII]",
"HtmlBody": "[HTML(encoded)]",
"Tag": "awesome",
"Headers": [
{
"Name": "X-Spam-Checker-Version",
"Value": "SpamAssassin 3.3.1 (2010-03-16) onrs-ord-pm-inbound1.wildbit.com"
},
{
"Name": "X-Spam-Status",
"Value": "No"
},
{
"Name": "X-Spam-Score",
"Value": "-0.1"
},
{
"Name": "X-Spam-Tests",
"Value": "DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,SPF_PASS"
},
{
"Name": "Received-SPF",
"Value": "Pass (sender SPF authorized) identity=mailfrom; client-ip=209.85.160.180; helo=mail-gy0-f180.google.com; envelope-from=myUser@theirDomain.com; receiver=451d9b70cf9364d23ff6f9d51d870251569e+ahoy@inbound.postmarkapp.com"
},
{
"Name": "DKIM-Signature",
"Value": "v=1; a=rsa-sha256; c=relaxed\/relaxed; d=wildbit.com; s=google; h=mime-version:reply-to:date:message-id:subject:from:to:cc :content-type; bh=cYr\/+oQiklaYbBJOQU3CdAnyhCTuvemrU36WT7cPNt0=; b=QsegXXbTbC4CMirl7A3VjDHyXbEsbCUTPL5vEHa7hNkkUTxXOK+dQA0JwgBHq5C+1u iuAJMz+SNBoTqEDqte2ckDvG2SeFR+Edip10p80TFGLp5RucaYvkwJTyuwsA7xd78NKT Q9ou6L1hgy\/MbKChnp2kxHOtYNOrrszY3JfQM="
},
{
"Name": "MIME-Version",
"Value": "1.0"
},
{
"Name": "Message-ID",
"Value": "<CAGXpo2WKfxHWZ5UFYCR3H_J9SNMG+5AXUovfEFL6DjWBJSyZaA@mail.gmail.com>"
}
],
"Attachments": [
{
"Name": "myimage.png",
"Content": "[BASE64-ENCODED CONTENT]",
"ContentType": "image/png",
"ContentLength": 4096
},
{
"Name": "mypaper.doc",
"Content": "[BASE64-ENCODED CONTENT]",
"ContentType": "application/msword",
"ContentLength": 16384
}
]
}

0 comments on commit 076cbe9

Please sign in to comment.