title: How to copy email from Gmail to my server using PHP IMAP?
body: <p>How can I copy email from Gmail to my server's <code>/home/email</code> directory after connecting to a Gmail mailbox using <a href="http://php.net/manual/en/book.imap.php" rel="nofollow">PHP's IMAP functionality</a>?</p>
  
  <p>I want to retrieve every email as a file in MIME format and I want to download the complete MIME file with PHP, not just the body or header of the email. Because of this, <code>imap_fetchbody</code> and <code>imap_fetchheader</code> can't do the job.</p>
  
  <p>Also, it seems <code>imap_mail_copy</code> and <code>imap_mail_move</code> can't do the job because they are designed to copy / move email to mailboxes:</p>
  
  <ul>
  <li>imap_mail_copy: Copy specified messages to a mailbox.    </li>
  <li>imap_mail_move: Move specified messages to a mailbox.</li>
  </ul>