title: Best way to save incoming/outgoing emails to MySQL
body: <p>What would be the best way to set-up a script which automatically 'monitors' several company (Google Apps) email addresses and copies incoming and outgoing email data into a MySQL database if the email is being sent to/from a recognised address.</p>
  
  <p>To identify recognised addresses, the script would need to query an existing MySQL table to see if a sender/recipient is a known user.  If this is the case, the email content and metadata would be written as a new row in the table.  Attachments would be copied to an FTP server, with the URL of this attachment stored as part of the email data.</p>
  
  <p>If the email is part of a threaded email chain, only the new part of the message should be stored, but the row ID of associated messages should also be stored.</p>
  
  <p>Any thoughts on how this could be possible would be greatly appreciated!  In particular, which programming languages and set-ups could achieve this...</p>
  
  <p>Many thanks...</p>