Skip to content

Instantly share code, notes, and snippets.

@Flyingmana
Created April 23, 2011 00:33
Show Gist options
  • Save Flyingmana/938034 to your computer and use it in GitHub Desktop.
Save Flyingmana/938034 to your computer and use it in GitHub Desktop.
ezmlm exporter
<?php
require_once 'ezc/Base/base.php';
spl_autoload_register( array( 'ezcBase', 'autoload' ) );
function fetch( $messageNrs , $imap){
$mails = array();
foreach( $messageNrs as $nr)
{
$set = $imap->fetchByMessageNr( $nr );
$parser = new ezcMailParser();
$message = $parser->parseMail( $set );
foreach ( $message[0]->body->getParts() as $key => $part)
{
if( $key === 0 ){ continue; };
$mails[] = $part;
}
}
return $mails;
}
function writeToDisk($mails, $dir){
foreach ( $mails as $key=>$mail){
file_put_contents( $dir.'/'.$key.'.txt', $mail->generate() );
}
}
$imap = new ezcMailImapTransport( "mailserver.example" );
$imap->authenticate( "[email protected]", "password" );
// Select the Inbox mailbox
$imap->selectMailbox( 'Inbox' );
//which mails should be fetched
$mails = fetch( range(1,6), $imap );
writeToDisk($mails, '/tmp/test/maillist');
echo count($mails);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment