Parsing e-mail, only reply, when returned from Mandrill Inbound API

Using Mandrill's API and their Inbound routing abilities, I'm trying to receive only the reply from the e-mail. I'm trying to parse just the latest response, similar to how Asana or Zendesk allow you to reply to an e-mail and it will end up in their database (rather than using their webapps).

This is the JSON payload that Mandrill returns:

        "event": "inbound",
        "ts": 1421946625,
        "msg": {
            "raw_msg": "Received: from server (unknown [ip])\n\tby ip-ip (Postfix) with ESMTPS id 0F62820519\n\tfor <>; Thu, 22 Jan 2015 17:10:24 +0000 (UTC)\nReceived: from server ([ip]) by\n server ([ip]) with mapi id\n ip; Thu, 22 Jan 2015 09:10:23 -0800\nFrom: person<>\nTo: Person\n\t<>\nSubject: test\nThread-Topic: test\nThread-Index: AQHQNmZOwbsfpy7UQUuXQM6h0Jn9Gw==\nDate: Thu, 22 Jan 2015 17:10:22 +0000\nMessage-ID: <>\nReferences: <>\nIn-Reply-To: <>\nAccept-Language: en-US\nContent-Language: en-US\nX-MS-Has-Attach:\nX-MS-TNEF-Correlator:\nx-originating-ip: [myip]\nContent-Type: text/plain; charset=\"us-ascii\"\nContent-ID: <>\nContent-Transfer-Encoding: quoted-printable\nMIME-Version: 1.0\n\ntest",
            "headers": {
                "Received": [
                    "from server (unknown [ip]) by ip (Postfix) with ESMTPS id id for <>; Thu, 22 Jan 2015 17:10:24 +0000 (UTC)",
                    "from server ([ip]) by server ([ip]) with mapi id id; Thu, 22 Jan 2015 09:10:23 -0800"
                "From": "Person Person <>",
                "To": "Person Person <>",
                "Subject": "test",
                "Thread-Topic": "test",
                "Thread-Index": "id==",
                "Date": "Thu, 22 Jan 2015 17:10:22 +0000",
                "Message-Id": "<>",
                "References": "<>",
                "In-Reply-To": "<>",
                "Accept-Language": "en-US",
                "Content-Language": "en-US",
                "X-Ms-Has-Attach": "",
                "X-Ms-Tnef-Correlator": "",
                "X-Originating-Ip": "[ip]",
                "Content-Type": "text/plain; charset=\"us-ascii\"",
                "Content-Id": "<id@server>",
                "Content-Transfer-Encoding": "quoted-printable",
                "Mime-Version": "1.0"
            "text": "test",
            "text_flowed": false,
            "from_email": "",
            "from_name": "Person Person",
            "to": [
                    "Person Person"
            "subject": "test",
            "spf": {
                "result": "permerror",
                "detail": "SPF Permanent Error: No valid SPF record for included domain:"
            "spam_report": {
                "score": 0.6,
                "matched_rules": [
                        "name": "RCVD_IN_DNSWL_LOW",
                        "score": -0.7,
                        "description": "RBL: Sender listed at, low"
                        "name": null,
                        "score": 0,
                        "description": null
                        "name": "listed",
                        "score": 0,
                        "description": "in]"
                        "name": "RDNS_NONE",
                        "score": 1.3,
                        "description": "Delivered to internal network by a host with no rDNS"
            "dkim": {
                "signed": false,
                "valid": false
            "email": "",
            "tags": [],
            "sender": null,
            "template": null

The problem is that in the text key in the schema returns the ENTIRE e-mail chain when I just need the reply. I've tried adding an underscore to the top of my e-mail template, and when I receive the JSON payload POSTed to my server, I get only everything above the underscore. However, mail clients (I'm using Mac's Mail client) add on dates, froms, tos, etc.

How am I able to parse this so I can receive JUST the reply and any signature with it and not the unnecessary text that's included?

Here's the snippet that's working that gets rid of the e-mail chain that comes below:

$response = substr($request['msg']['text'], 0, strpos($input['msg']['text'], '_'));

The line above gets the string from the beginning up until it hits the _ in the e-mail template. The e-mail client adds above my template when someone replies (rendering the underscore only useful for ridding the e-mail chain that comes with the response, and not what's tacked on above), and that's the bit I need to remove so that I get ONLY the reply.

Visually, this is what the client does:

As you can see it adds on On Jan 22... which is what I'm trying to eliminate when parsing it when the Mandrill API sends it to my server.


Searched around a bit more and found this repo:

This repository has a method in its API getContent() that returns only the e-mail reply.

This did the trick.

Need Your Help

Android - Starting a service with extra information through put/getExtra

android service android-intent extra

I've really tried to get through the intent.putExtra() and getIntent().getExtras() and apply them to one of the SimpleService tutorials. I know a lot of people have already asked "why is bundle ex...

CQWP pulling link list , when a link is clicked renders the list item rather than opening the URL itself

sharepoint hyperlink cqwp

I have a content query web part on page which i am using to pull a list of links (from a link list)to display on page. I thought clicking this link, user would be able to navigate to the link itsel...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.