title: Get inline email attachments with PHP in a formatted email send from an IOS device
body: <p>I'm using <a href="http://code.google.com/p/php-imap/" rel="nofollow">PHP-imap</a> to read emails and there attachments from a IMAP Account. The emails are send from an iPhone or iPad. It works fine when they write an email and paste in an image they took.</p>
  
  <p>Here's a snippet how I get the attachments:</p>
  
  <pre><code>require_once("plugins/MailLib/MailLib.php");
  
  $mailbox = new MailLib();
  $mailbox-&gt;connect($username, $password, $server, $port, $path, false);
  
  $mails = array();
  $mailIds = $mailbox-&gt;getMails("UNSEEN");
  
  if($mailIds != null &amp;&amp; count($mailIds) &gt; 0) {
      foreach($mailIds as $mailId) {
          $mail = $mailbox-&gt;getMail($mailId);
          if($mail['attachments']) {
              foreach($mail['attachments'] as $attachment) {
                  $file = $mailbox-&gt;getAttachment($attachment, $mailId);
                  $destFile = "path/to/folder/".time().".jpg";
                  $fh = fopen($destFile, 'a') or die("can't open file");
                  fwrite($fh, $file);
                  fclose($fh);
              }
          }
   }
  </code></pre>
  
  <p>It all crashes as soon as they start formatting the content with the default options like bold, italic or underline. Because then I get the following email content:</p>
  
  <pre><code>&lt;div&gt;
      &lt;em&gt;Test&lt;/em&gt; with &lt;strong&gt;formatting&lt;/strong&gt;
      &lt;br&gt;
      &lt;br&gt;
      &lt;img id="7CB777EB-3124-4AEA-8894-6F743EA78F79" src="cid:7CB777EB-3124-4AEA-8894-6F743EA78F79" alt="image.jpeg"&gt;
      &lt;br&gt;
      &lt;br&gt;
      &lt;div&gt;Send from my iPhone&lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>Is there any kind of php library out there to get those attachments as well?</p>