      1: <?php
      2:
      3: class Mandrill_Inbound {
      4:     public function __construct(Mandrill $master) {
      5:         $this->master = $master;
      6:     }
      7:
      8:     /**
      9:      * List the domains that have been configured for inbound delivery
     10:      * @return array the inbound domains associated with the account
     11:      *     - return[] struct the individual domain info
     12:      *         - domain string the domain name that is accepting mail
     13:      *         - created_at string the date and time that the inbound domain was added as a UTC string in YYYY-MM-DD HH:MM:SS format
     14:      *         - valid_mx boolean true if this inbound domain has successfully set up an MX record to deliver mail to the Mandrill servers
     15:      */
     16:     public function domains() {
     17:         $_params = array();
     18:         return $this->master->call('inbound/domains', $_params);
     19:     }
     20:
     21:     /**
     22:      * Add an inbound domain to your account
     23:      * @param string $domain a domain name
     24:      * @return struct information about the domain
     25:      *     - domain string the domain name that is accepting mail
     26:      *     - created_at string the date and time that the inbound domain was added as a UTC string in YYYY-MM-DD HH:MM:SS format
     27:      *     - valid_mx boolean true if this inbound domain has successfully set up an MX record to deliver mail to the Mandrill servers
     28:      */
     29:     public function addDomain($domain) {
     30:         $_params = array("domain" => $domain);
     31:         return $this->master->call('inbound/add-domain', $_params);
     32:     }
     33:
     34:     /**
     35:      * Check the MX settings for an inbound domain. The domain must have already been added with the add-domain call
     36:      * @param string $domain an existing inbound domain
     37:      * @return struct information about the inbound domain
     38:      *     - domain string the domain name that is accepting mail
     39:      *     - created_at string the date and time that the inbound domain was added as a UTC string in YYYY-MM-DD HH:MM:SS format
     40:      *     - valid_mx boolean true if this inbound domain has successfully set up an MX record to deliver mail to the Mandrill servers
     41:      */
     42:     public function checkDomain($domain) {
     43:         $_params = array("domain" => $domain);
     44:         return $this->master->call('inbound/check-domain', $_params);
     45:     }
     46:
     47:     /**
     48:      * Delete an inbound domain from the account. All mail will stop routing for this domain immediately.
     49:      * @param string $domain an existing inbound domain
     50:      * @return struct information about the deleted domain
     51:      *     - domain string the domain name that is accepting mail
     52:      *     - created_at string the date and time that the inbound domain was added as a UTC string in YYYY-MM-DD HH:MM:SS format
     53:      *     - valid_mx boolean true if this inbound domain has successfully set up an MX record to deliver mail to the Mandrill servers
     54:      */
     55:     public function deleteDomain($domain) {
     56:         $_params = array("domain" => $domain);
     57:         return $this->master->call('inbound/delete-domain', $_params);
     58:     }
     59:
     60:     /**
     61:      * List the mailbox routes defined for an inbound domain
     62:      * @param string $domain the domain to check
     63:      * @return array the routes associated with the domain
     64:      *     - return[] struct the individual mailbox route
     65:      *         - id string the unique identifier of the route
     66:      *         - pattern string the search pattern that the mailbox name should match
     67:      *         - url string the webhook URL where inbound messages will be published
     68:      */
     69:     public function routes($domain) {
     70:         $_params = array("domain" => $domain);
     71:         return $this->master->call('inbound/routes', $_params);
     72:     }
     73:
     74:     /**
     75:      * Add a new mailbox route to an inbound domain
     76:      * @param string $domain an existing inbound domain
     77:      * @param string $pattern the search pattern that the mailbox name should match
     78:      * @param string $url the webhook URL where the inbound messages will be published
     79:      * @return struct the added mailbox route information
     80:      *     - id string the unique identifier of the route
     81:      *     - pattern string the search pattern that the mailbox name should match
     82:      *     - url string the webhook URL where inbound messages will be published
     83:      */
     84:     public function addRoute($domain, $pattern, $url) {
     85:         $_params = array("domain" => $domain, "pattern" => $pattern, "url" => $url);
     86:         return $this->master->call('inbound/add-route', $_params);
     87:     }
     88:
     89:     /**
     90:      * Update the pattern or webhook of an existing inbound mailbox route. If null is provided for any fields, the values will remain unchanged.
     91:      * @param string $id the unique identifier of an existing mailbox route
     92:      * @param string $pattern the search pattern that the mailbox name should match
     93:      * @param string $url the webhook URL where the inbound messages will be published
     94:      * @return struct the updated mailbox route information
     95:      *     - id string the unique identifier of the route
     96:      *     - pattern string the search pattern that the mailbox name should match
     97:      *     - url string the webhook URL where inbound messages will be published
     98:      */
     99:     public function updateRoute($id, $pattern=null, $url=null) {
    100:         $_params = array("id" => $id, "pattern" => $pattern, "url" => $url);
    101:         return $this->master->call('inbound/update-route', $_params);
    102:     }
    103:
    104:     /**
    105:      * Delete an existing inbound mailbox route
    106:      * @param string $id the unique identifier of an existing route
    107:      * @return struct the deleted mailbox route information
    108:      *     - id string the unique identifier of the route
    109:      *     - pattern string the search pattern that the mailbox name should match
    110:      *     - url string the webhook URL where inbound messages will be published
    111:      */
    112:     public function deleteRoute($id) {
    113:         $_params = array("id" => $id);
    114:         return $this->master->call('inbound/delete-route', $_params);
    115:     }
    116:
    117:     /**
    118:      * Take a raw MIME document destined for a domain with inbound domains set up, and send it to the inbound hook exactly as if it had been sent over SMTP
    119:      * @param string $raw_message the full MIME document of an email message
    120:      * @param array|null $to optionally define the recipients to receive the message - otherwise we'll use the To, Cc, and Bcc headers provided in the document
    121:      *     - to[] string the email address of the recipient
    122:      * @param string $mail_from the address specified in the MAIL FROM stage of the SMTP conversation. Required for the SPF check.
    123:      * @param string $helo the identification provided by the client mta in the MTA state of the SMTP conversation. Required for the SPF check.
    124:      * @param string $client_address the remote MTA's ip address. Optional; required for the SPF check.
    125:      * @return array an array of the information for each recipient in the message (usually one) that matched an inbound route
    126:      *     - return[] struct the individual recipient information
    127:      *         - email string the email address of the matching recipient
    128:      *         - pattern string the mailbox route pattern that the recipient matched
    129:      *         - url string the webhook URL that the message was posted to
    130:      */
    131:     public function sendRaw($raw_message, $to=null, $mail_from=null, $helo=null, $client_address=null) {
    132:         $_params = array("raw_message" => $raw_message, "to" => $to, "mail_from" => $mail_from, "helo" => $helo, "client_address" => $client_address);
    133:         return $this->master->call('inbound/send-raw', $_params);
    134:     }
    135:
    136: }
    137:
    138:
    139: