Skip to content

Instantly share code, notes, and snippets.

@Flyingmana
Created April 23, 2011 00:33
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • 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( "testlist@mailserver.example", "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