# ZendMail and Amazon's Kindle Converter

If you’re trying to use
[Zend_Mail](http://framework.zend.com/manual/en/zend.mail.html) to send
email to Amazon’s free [PDF-to-Kindle
converter](http://www.amazon.co.uk/kindlepersonaldocuments/), you might
like to know that for some reason two headers that `Zend_Mail` adds to
the message—`Content-Transfer-Encoding` and `Content-Disposition`—trick
Amazon’s converter into thinking that there are no attachments. (These
emails are interpreted correctly by pretty much everything else as far
as I can tell so I’m not sure if this is `Zend_Mail`’s fault, or
Amazon’s, or both.)

There’s probably several ways to fix this, but I fixed it by creating a
new version of `Zend_Mail_Transport_Smtp`:

```php
class Zend_Mail_Transport_Smtp_Kindle extends Zend_Mail_Transport_Smtp
{
    protected function _prepareHeaders($headers)
    {
        // Remove some headers from the mail enclosure--these somehow confuse
        // Amazon's Kindle converter, leading it to conclude that there are
        // no attachments.  (Even though every other mail client seems to be
        // able to cope.)

        if (array_key_exists("Content-Transfer-Encoding", $headers)) {
            unset($headers["Content-Transfer-Encoding"]);
        }
        if (array_key_exists("Content-Disposition", $headers)) {
            unset($headers["Content-Disposition"]);
        }

        return parent::_prepareHeaders($headers);
    }
}
```

Anyway, with this “bug” worked around, I can now do this:

![OS X print dialog, with "Send to Kindle"
option](http://beebo.org/img/stuff/print.png)

My `~/Library/PDF Services/Send to Kindle` reads:

```sh
#!/bin/bash

TITLE=$(perl -MURI::Escape -e 'print uri_escape(join(" ", @ARGV))' $1)

cat "$3" | curl --data-binary @- "http://beebo.org/api/kindle/?username=ithinkihaveacat&title=$TITLE"
```

(See “[Providing PDF Workflow Options in the Print
Dialog](http://developer.apple.com/library/mac/#documentation/Printing/Conceptual/PDF_Workflow/pdfwf_concepts/pdfwf_concepts.html)”
for more information.)
