How to save an Email attachment as an Email message?
<p>I am pretty new when it comes to handling emails in php. </p>

<p>Basically I need to read a pop3 mailbox and save the messages to a database and the attachments to a folder. Then mail that same mail (slightly altered) back to another email recipient.</p>

<p>I thought I got this all working, then I realized when the attachment is another mail message I only receive the body as text (after base64_decode).</p>

<p>Is it possible to save an attached email to a file and then send it as attachment in another message? </p>

<p>Any help will be appreciated.</p>

<p>Here is some code to put it into perspective :</p>

<pre><code>// This is the IMAP connection: imap_open("{"."$host:$port/pop3$ssl"."}$folder",$user,$pass,OP_SILENT);
$mailConnection = $this-&gt;Maildata-&gt;mail_login($host,$port,$user,$pass,$folder,$ssl);

// This retrieves the list of mails in the current folder
$messageList = $this-&gt;Maildata-&gt;mail_list($mailConnection,$message);
foreach ($messageList as $messageId =&gt; $messageListData) {

    // This reads the mail object into an array
    $mailMessage = $this-&gt;Maildata-&gt;mail_mime_to_array($mailConnection,$messageId,true);

    // This loops through each mail
    foreach ($mailMessage as $tmpId =&gt; $tmpData) {
        // Excluded save to database since it is unrelated

        // This checks if item is an attachment and saves it.
        if (isset($tmpData['is_attachment']) &amp;&amp; $tmpData['is_attachment'] === true) {
            $tmpName = date('Y-m-d H:i:s', strtotime('now'));
            $this-&gt;Maildata-&gt;mail_attachment_save($tmpData['data'], $tmpName .$tmpData['name']);
        }
    }
}
</code></pre>

<p>P.S. This all works, but <code>imap_fetchbody($mailConnection , $messageId, $prefix);</code> doesn't seem to send all the data I need.</p>
