Recommend this page to a friend! |
POP3 e-mail client | > | All threads | > | Multiple copies of Message | > | (Un) Subscribe thread alerts |
|
Ryan Shacklett - 2006-12-01 23:15:10
Fantastic class! Thanks so much for your time and sharing your efforts -- I have learned a ton from figuring how your code works.
Here's what I've run into: In testing my scripts, sometimes - randomly - when I run the script (below) it will give me duplicate listings (with different IDs) from the same email message. In addition to the obvious problem this creates, when I use the parser class to pull the message and save parts to files -- it correctly pulls and saves the first instance of the message, but the duplicate message(s) the parser does not save any files out. I haven't had any problems of this nature on this account with any other mail programs. Here's the PHP code - so you get and idea of how I'm using your code (I'm sure there's a better way to do what I'm doing -- I'm open for any suggestions - I just mainly used groupings of code from your example files to save time & error factor): // this code gets me the # of messages to get... if(($error=$pop3->Open())=="") { if(($error=$pop3->Login($user,$password,$apop))=="") { if(($error=$pop3->Statistics($messages,$size))=="") { $result=$pop3->ListMessages("",0); if(GetType($result)=="array") { for(Reset($result),$message=0;$message<count($result);Next($result),$message++) echo "Message ",Key($result)," - ",$result[Key($result)]," bytes.\n"; $result=$pop3->ListMessages("",1); if(GetType($result)=="array") { for(Reset($result),$message=0;$message<count($result);Next($result),$message++) echo "Message ",Key($result),", Unique ID - \"",$result[Key($result)],"\"\n"; } } } } } $error=$pop3->Close(); // then I run a loop to use the parser to pull the message and save to file. for ($message=1; $message <= $messages; $message++) { $message_file='pop3://'.$user.':'.$password.'@'.$emval['POP Server'][0].'/'.$message. '?debug='.$debug.'&html_debug='.$html_debug.'&realm='.$realm.'&workstation='.$workstation. '&apop='.$apop.'&authentication_mechanism='.$authentication_mechanism; $mime=new mime_parser_class; $mime->decode_bodies = 1; $parameters=array( 'File'=>$message_file, 'SaveBody'=>$tempdir ); $success=$mime->Decode($parameters, $decoded); print_r($decoded); // there's a bunch of other code I omitted that processes the files, and adds the info to a Filemaker Database via XML. // and then delete the message if(($error=$pop3->Open())=="") { if(($error=$pop3->Login($user,$password,$apop))=="") { $error=$pop3->DeleteMessage($message); } } $error=$pop3->Close(); } Here's the output: Message 1 - 3005 bytes. Message 2 - 3436 bytes. Message 1, Unique ID - "1161799679.392" Message 2, Unique ID - "1161799679.393" Message 1 $decode output: Array ( [0] => Array ( [Headers] => Array ( [return-path:] => <rshacklett@gmail.com> [received:] => Array ( [0] => from murder ([unix socket]) by mail.ultimaxinc.com (Cyrus v2.2.12-OS X 10.4.8) with LMTPA; Fri, 01 Dec 2006 15:37:39 -0700 [1] => from localhost (localhost [127.0.0.1]) by mail.ultimaxinc.com (Postfix) with ESMTP id 84AD8A9213 for <test@3705kipling.com>; Fri, 1 Dec 2006 15:37:39 -0700 (MST) [2] => from mail.ultimaxinc.com ([127.0.0.1]) by localhost (74-92-217-225-Colorado.hfc.comcastbusiness.net [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 08692-03 for <test@3705kipling.com>; Fri, 1 Dec 2006 15:37:29 -0700 (MST) [3] => from nz-out-0102.google.com (nz-out-0506.google.com [64.233.162.235]) by mail.ultimaxinc.com (Postfix) with ESMTP id E71FFA91F2 for <test@3705kipling.com>; Fri, 1 Dec 2006 15:37:28 -0700 (MST) [4] => by nz-out-0102.google.com with SMTP id f1so1517524nzc for <test@3705kipling.com>; Fri, 01 Dec 2006 14:37:28 -0800 (PST) [5] => by 10.64.242.5 with SMTP id p5mr7746476qbh.1165012647974; Fri, 01 Dec 2006 14:37:27 -0800 (PST) [6] => by 10.65.126.15 with HTTP; Fri, 1 Dec 2006 14:37:27 -0800 (PST) ) [x-sieve:] => CMU Sieve 2.2 [domainkey-signature:] => a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:to:subject:in-reply-to:mime-version:content-type:references; b=uu9104vrkSvhwTVtNAhSWSs2TZRKCewVzk7BfRYhvoVuAMqJBn1JjOl7eXt10LjVlJQN3jLk6UDIGnMYffk2ruYpnxDK1Ap65hkXPvtXqBjS2XpG6Jl8dZGg54LUlR20QekWyi89fwTI/Y1iy8be89jYR3zBEL6v2s7AbDRlkPc= [message-id:] => <cff3cdcc0612011437j15f91796o2de02d64ba5bba1d@mail.gmail.com> [date:] => Fri, 1 Dec 2006 15:37:27 -0700 [from:] => "Ryan Shacklett" <rshacklett@gmail.com> [to:] => test@3705kipling.com [subject:] => Fwd: update on software [in-reply-to:] => <cff3cdcc0611281848u5d3e07a2h62e8bd263eb17349@mail.gmail.com> [mime-version:] => 1.0 [content-type:] => multipart/alternative; boundary="----=_Part_7834_27435093.1165012647904" [references:] => <cff3cdcc0611281848u5d3e07a2h62e8bd263eb17349@mail.gmail.com> [x-virus-scanned:] => by amavisd-new at ultimaxinc.com ) [Parts] => Array ( [0] => Array ( [Headers] => Array ( [content-type:] => text/plain; charset=ISO-8859-1; format=flowed [content-transfer-encoding:] => 7bit [content-disposition:] => inline ) [Parts] => Array ( ) [BodyFile] => /tmp/maildl/1 [BodyPart] => 1 [BodyLength] => 197 ) [1] => Array ( [Headers] => Array ( [content-type:] => text/html; charset=ISO-8859-1 [content-transfer-encoding:] => 7bit [content-disposition:] => inline ) [Parts] => Array ( ) [BodyFile] => /tmp/maildl/2 [BodyPart] => 2 [BodyLength] => 380 ) ) ) ) Message 2 $decode output: ( [0] => Array ( [Headers] => Array ( [return-path:] => <rshacklett@gmail.com> [received:] => Array ( [0] => from murder ([unix socket]) by mail.ultimaxinc.com (Cyrus v2.2.12-OS X 10.4.8) with LMTPA; Fri, 01 Dec 2006 15:37:39 -0700 [1] => from localhost (localhost [127.0.0.1]) by mail.ultimaxinc.com (Postfix) with ESMTP id 84AD8A9213 for <test@3705kipling.com>; Fri, 1 Dec 2006 15:37:39 -0700 (MST) [2] => from mail.ultimaxinc.com ([127.0.0.1]) by localhost (74-92-217-225-Colorado.hfc.comcastbusiness.net [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 08692-03 for <test@3705kipling.com>; Fri, 1 Dec 2006 15:37:29 -0700 (MST) [3] => from nz-out-0102.google.com (nz-out-0506.google.com [64.233.162.235]) by mail.ultimaxinc.com (Postfix) with ESMTP id E71FFA91F2 for <test@3705kipling.com>; Fri, 1 Dec 2006 15:37:28 -0700 (MST) [4] => by nz-out-0102.google.com with SMTP id f1so1517524nzc for <test@3705kipling.com>; Fri, 01 Dec 2006 14:37:28 -0800 (PST) [5] => by 10.64.242.5 with SMTP id p5mr7746476qbh.1165012647974; Fri, 01 Dec 2006 14:37:27 -0800 (PST) [6] => by 10.65.126.15 with HTTP; Fri, 1 Dec 2006 14:37:27 -0800 (PST) ) [x-sieve:] => CMU Sieve 2.2 [domainkey-signature:] => a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:to:subject:in-reply-to:mime-version:content-type:references; b=uu9104vrkSvhwTVtNAhSWSs2TZRKCewVzk7BfRYhvoVuAMqJBn1JjOl7eXt10LjVlJQN3jLk6UDIGnMYffk2ruYpnxDK1Ap65hkXPvtXqBjS2XpG6Jl8dZGg54LUlR20QekWyi89fwTI/Y1iy8be89jYR3zBEL6v2s7AbDRlkPc= [message-id:] => <cff3cdcc0612011437j15f91796o2de02d64ba5bba1d@mail.gmail.com> [date:] => Fri, 1 Dec 2006 15:37:27 -0700 [from:] => "Ryan Shacklett" <rshacklett@gmail.com> [to:] => test@3705kipling.com [subject:] => Fwd: update on software [in-reply-to:] => <cff3cdcc0611281848u5d3e07a2h62e8bd263eb17349@mail.gmail.com> [mime-version:] => 1.0 [content-type:] => multipart/alternative; boundary="----=_Part_7834_27435093.1165012647904" [references:] => <cff3cdcc0611281848u5d3e07a2h62e8bd263eb17349@mail.gmail.com> [x-virus-scanned:] => by amavisd-new at ultimaxinc.com ) [Parts] => Array ( [0] => Array ( [Headers] => Array ( [content-type:] => text/plain; charset=ISO-8859-1; format=flowed [content-transfer-encoding:] => 7bit [content-disposition:] => inline ) [Parts] => Array ( ) [BodyFile] => /tmp/maildl/1 [BodyPart] => 1 [BodyLength] => 197 ) [1] => Array ( [Headers] => Array ( [content-type:] => text/html; charset=ISO-8859-1 [content-transfer-encoding:] => 7bit [content-disposition:] => inline ) [Parts] => Array ( ) [BodyFile] => /tmp/maildl/2 [BodyPart] => 2 [BodyLength] => 380 ) ) ) ) Thanks So Much! Ryan Shacklett rshacklett@ultimaxinc.com
Manuel Lemos - 2006-12-02 04:07:14 - In reply to message 1 from Ryan Shacklett
Duplicate messages may happen. If you find duplicates in the mailbox with different UID, that is because the messages were dropped there like that. It is was not caused by the POP3 class.
As for the body message parts, it appears that they were saved in the /tmp/maildl/ directory. Aren't the messages there?
Ryan Shacklett - 2006-12-02 15:57:07 - In reply to message 2 from Manuel Lemos
Thanks for such a quick response!
Okay - I wasn't sure if it was the class, or the pop server, or the sending server creating / seeing the multiple messages. (was trying to figure out where the problem was originating from -- I figured you had a boatload more experience in this area and would know where the problem was!) The first message of the multiple copies the class correctly writes the files, and are placed in the /tmp/maildl directory. The duplicate messages do not contain any files (even though the results from the $decode array say the parts are saved out). ...but obviously we don't need to worry about that problem... The real question is: What is the best way to detect these duplicate messages so that I can programically ignore and delete them? Since on the duplicate messages I can't see the body copy to compare, and the UIDs are different, would just looking for messages being received from the same message-id: and date: work for detecting and removing duplicates? ...what's your thoughts? Thank you so much for your time! Ryan Shacklett
Manuel Lemos - 2006-12-03 21:23:50 - In reply to message 3 from Ryan Shacklett
If you specified the same directory to save message bodies, it is very likely that the bodies of the last messages overwritten the bodies of the previous.
As for detecting real duplicates, looking at the message-id header should be sufficient. |
info at phpclasses dot org
.