PHP Classes

sort out messages

Recommend this page to a friend!

      POP3 e-mail client  >  All threads  >  sort out messages  >  (Un) Subscribe thread alerts  
Subject:sort out messages
Summary:how to sort it out
Messages:62
Author:vlad
Date:2008-12-11 04:38:15
Update:2009-03-20 04:16:29
 
  1 - 10   11 - 20   21 - 30   31 - 40   41 - 50   51 - 60   61 - 62  

  1. sort out messages   Reply   Report abuse  
Picture of vlad vlad - 2008-12-11 04:38:16
Dear
Manuel

could you help please?

im very new to the class. i could make messages to go to the php page however it looks like a mess. attachments displays as some terrible code.

how can i separate message,subject, attachment ... etc to put it nicely to the db?
this is the php page:

worldwideprojectinfo.com/test/pop3_ ...

and my code is below...

<?php

require ('pop3.class.inc');

$pop3 = new POP3;

// Connect to mail server
$do = $pop3->connect ('xxx.xxx.xx');
if ($do == false) {
die($pop3->error);
}

// Login to your inbox
$do = $pop3->login ('xx@xxxx.xx', 'xxxxxxxxxx');

if ($do == false) {
die($pop3->error);
}

// Get office status
$status = $pop3->get_office_status();

if ($status == false) {
die($pop3->error);
}

$count = $status['count_mails'];

if ($count == '0') {
echo 'There are no new e-mails';
}

for ($i = 1; $i <= $count; $i++) {
$email = $pop3->get_mail($i);

if ($email == false) {
echo $pop3->error;
continue;
}

$email = parse_email ($email);
echo '<b>From: </b>' . htmlentities($email['headers']['From']) . '<br />';
echo '<b>Subject: </b>' . htmlentities($email['headers']['Subject']) . '<br /><br />';
//echo nl2br($email['message']);
echo $email['message'];
echo '<hr />';


// TODO: store the e-mail in a database or on the HDD

// Remove from mail server
# $do = $pop3->delete_mail ($i);
# if ($do == false) {
# echo $pop3->error;
# }
}

$pop3->close();

function parse_email ($email) {
// Split header and message
$header = array();
$message = array();

$is_header = true;
foreach ($email as $line) {
if ($line == '<HEADER> ' . "\r\n") continue;
if ($line == '<MESSAGE> ' . "\r\n") continue;
if ($line == '</MESSAGE> ' . "\r\n") continue;
if ($line == '</HEADER> ' . "\r\n") { $is_header = false; continue; }

if ($is_header == true) {
$header[] = $line;
} else {
$message[] = $line;
}
}

// Parse headers
$headers = array();
foreach ($header as $line) {
$colon_pos = strpos($line, ':');
$space_pos = strpos($line, ' ');

if ($colon_pos === false OR $space_pos < $colon_pos) {
// attach to previous
$previous .= "\r\n" . $line;
continue;
}

// Get key
$key = substr($line, 0, $colon_pos);

// Get value
$value = substr($line, $colon_pos+2);
$headers[$key] = $value;

$previous =& $headers[$key];
}

// Parse message
$message = implode('', $message);

// Return array
$email = array();
$email['message'] = $message;
$email['headers'] = $headers;

return $email;
}
?>

  2. Re: sort out messages   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2008-12-11 05:06:01 - In reply to message 1 from vlad
It seems you are using some other POP3 class.

My POP3 class can work together with a MIME parser class which parses the messages and save body parts to files or strings, thus making it easy to put in the DB.

phpclasses.org/pop3class

phpclasses.org/mimeparser

  3. Re: sort out messages   Reply   Report abuse  
Picture of vlad vlad - 2008-12-11 21:08:53 - In reply to message 2 from Manuel Lemos
oops! thats right!

i downloaded POP3 and Mime. put them at one location... however im totally lost now.. im can see the messages (at test_pop3.php) from my email box but it has so many different code around.

im not sure what to put here:
$workstation=UrlEncode("?????"); // i saw on the forum the answer but it is not clear for me yet what to put there???


$authentication_mechanism=UrlEncode("USER");-- should i put something instead of USER ? ?

i feel like im totally lost now :) im trying to figure out how to get emails and all stuff to organize it and put into database...
may be you have step by step instruction what file to use and how?

will appreciate your help..
thanks

  4. Re: sort out messages   Reply   Report abuse  
Picture of vlad vlad - 2008-12-11 22:52:16 - In reply to message 3 from vlad
for example when i test the page
parse_message.php

i got an error:

MIME message decoding error: could not open the message file to decode pop3://xxx%40xxx.xx:xxxxxxxx@localhost/1?debug=1&html_debug=1&realm=email.axo.cc&workstation=&apop=0&authentication_mechanism=USER

  5. Re: sort out messages   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2008-12-12 02:31:26 - In reply to message 4 from vlad
You may drop the realm, workstation and authentication_mechanism options.

Anyway, I think your problem may be the host name. If the host name address is not localhost, you should change the POP3 URL to use the correct host name instead.

  6. Re: sort out messages   Reply   Report abuse  
Picture of vlad vlad - 2008-12-15 04:36:23 - In reply to message 5 from Manuel Lemos
the mail server is at the address
email.axo.cc:3000/
i put different options
email.axo.cc
email.axo.cc:3000

what name should u put?

  7. Re: sort out messages   Reply   Report abuse  
Picture of vlad vlad - 2008-12-15 04:40:28 - In reply to message 6 from vlad
i just found some little mistake at mime_parser.php (there is an extra ?> )

after i removed ?> im getting error

MIME message decoding error: could not open the message file to decode pop3://vlad@axo.cc/1

should i give an write permissions to some file or folder?


  8. Re: sort out messages   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2008-12-15 07:02:18 - In reply to message 7 from vlad
No, the problem is that you are not specifying the password for that user. It should be something like this, where XXXX is the password of the vlad user:

pop3://vlad:XXXX@axo.cc/1

  9. Re: sort out messages   Reply   Report abuse  
Picture of vlad vlad - 2008-12-17 03:44:47 - In reply to message 8 from Manuel Lemos
hello! i commented
$authentication_mechanism="USER";
$realm="";
$workstation="";


and i got a message:

MIME message decoding successful
Message structure

array(5) {
["Headers"]=>
array(21) {
["received:"]=>
array(9) {
[0]=>
string(154) "from pop.cl
. etc
. etc
. etc

...

array(1) {
["address"]=>
string(29) "httpd@web19.websitesource.net"
}
}
["DataLength"]=>
int(980)
}

C QUIT
S +OK axonz9@axo.cc axo.cc POP Server signing off (40 messages left)
Closing connection.

Disconnected from the POP3 server "email.axo.cc".


what does it mean? it mean that i can do something? i mean take what i nee and put in into data base?
from which page do i do it? from browse_mailbox.php?
could you please advice what arrays or variables give me the info i need?

what array does it or what? im so dumb... sometimes :)


  10. Re: sort out messages   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2008-12-17 04:15:16 - In reply to message 1 from vlad
That is explained in the documentation of the MIME parser class. Take a look at the documentation of the $decoded argument of the Decode function and $results argument of the Analyze function.

phpclasses.org/browse/file/14673.ht ...

 
  1 - 10   11 - 20   21 - 30   31 - 40   41 - 50   51 - 60   61 - 62