Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

Geting Mail Messages From IMAP to UNIX mail file ???
I need a solution to get messages from IMAP server transfered over to my
server. Once the transfer complete I want to be able to read them. And one
more thing this script has needs to run from cron.

So far I figured out to get messages from the IMAP . Here is my code in the
nutshell.
Email message and attachements get transfered correctly however when trying
to read the file created with "mail -f file" it tells me that there is 0
messages in that file even though I know there is at least 10 messages.

how can I write these emails to the file and be able to read them later.
????

<CODE>

* Connecting to Mailserver  $mbox is a connection link */
$mbox = @imap_open("$MAILSERVER$MAILBOX",$IMAPUSER,$IMAPPASS);


if (!$mbox) {
/* If $mbox does not exist it means that connection
to the server was not established
we need to report this issue */
$error = "phpMailArchive IMAP CONNECTION FAILED";
$err_body .= 'phpMailArchive was not able to connect to' . $MAILSERVER ."
\n\n ERROR: \n". imap_last_error() . "\r\n";
report_error($error,$err_body);
@imap_close($inbox);
exit;
}

$total = @imap_num_msg($mbox); //Get Total Number of messages
echo "Total Messages: ". $total . "<br>";

for($msgid=1; $msgid <= $total; $msgid++) {

/* first all vars from the previous mail got killed */
$structure = NULL;
$headers = NULL;
$xp_id = NULL;
$xp_time_unix = NULL;
$xp_date_year = NULL;
$xp_date_month = NULL;
$xp_date_day= NULL;
$xp_time_iso = NULL;
$xp_date_iso = NULL;
$xp_from_full = NULL;
$xp_from_host = NULL;
$xp_md5 = NULL;
$xp_header_raw = NULL;
$parts = NULL;
$parts_count = NULL;
$xp_full_raw = NULL;
$xp_body_raw = NULL;
$xp_fetch_body_text= NULL;
$alert_state = NULL;
$alert_host = NULL;
$alert_check = NULL;

//$headers = imap_header($mbox, $msgid);
$headers = imap_headerinfo ($mbox, $msgid);


/* initiate most of our vars */
$xp_id = $headers->message_id;
$xp_time_unix = $headers->udate;
$xp_date_year = @date("Y", $xp_time_unix);;
$xp_date_month = @date("F", $xp_time_unix);;
$xp_date_day= @date("d", $xp_time_unix);;
$xp_from_full = $headers->from;


/* TEST TO SEE IF DIRECTORY ALREADY EXISTS ... IF NOT CREATE IT
UNFORCHANETELY WE HAVE TO TEST FOR ALL MONTH AND YEAR DIRECTORIES
SEPARATELY OR MKDIR FUNCTION WILL FAIL    */
if(!is_dir("$BASEDIR/$xp_date_year/$xp_date_month")) {
if(!is_dir("$BASEDIR/$xp_date_year")) {
mkdir("$BASEDIR/$xp_date_year", 0777);
}
mkdir("$BASEDIR/$xp_date_year/$xp_date_month", 0777);
}

// GET FULL HEADER & EMAIL BODY AND WRITE IT TO THE FILE
$xp_full_raw = imap_fetchheader($mbox, $msgid);
$xp_body_raw = imap_body($mbox, $msgid);
$handle = fopen("$BASEDIR/$xp_date_year/$xp_date_month/$xp_date_day",
"w+");
fwrite($handle, $xp_full_raw . $xp_body_raw);
fclose($handle);
}

</CODE>



Report this thread to moderator Post Follow-up to this message
Old Post
Ninjaboy
10-24-04 08:55 AM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

PHP Language archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 04:38 AM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.