Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.