| Author |  | 
      
        | Guest Guest Group
 
  
 
 Joined: 10 November 2003
 Online Status: Online
 Posts: 262
 | 
          Hi,
           | Posted: 02 January 2006 at 8:32am | IP Logged |   |  
           | 
 |  I have a case where i need to download only mails that have attachments.
 There will be a large number of messages and only about 40% of them will have attachments.
 
 Whats is the best (speed and memory usage) way to do so?
 If you have done anything similar then please do share your experience with me.
 | 
       
        | Back to Top |     | 
       
       
        |  | 
        | Alex AfterLogic Support
 
  
  
 Joined: 19 November 2003
 Online Status: Offline
 Posts: 2207
 | 
          The POP3 protocol (unlike IMAP) does not have any features to detect whether the particular mail has attachments or not without downloading it.
           | Posted: 02 January 2006 at 9:15am | IP Logged |   |  
           | 
 |  
 However, MailBee can "guess" whether the message contains attachments or not by analysing message headers. Messages which contain attachments usually have specific Content-Type values. Thus, to decide which messages to download, you can use the code like below (for brevity, it's assumed the connection with the POP3 server is already established, no error checking, etc):
 
 
| Code: 
 
    
    | 
      
       | Set Msgs = POP3.RetrieveHeaders
 For I = 1 To Msgs.Count
 If Msgs(I).HasAttachments Then
 Set Msg = POP3.RetrieveSingleMessage(I)
 If Msg.HasAttachments Then
 ' Process the message here
 End If
 End If
 Next
 
 |  |  |  
 As you can see, we check .HasAttachments property twice. First, when downloading message header only; second, when downloading the entire message. This is because it's possible the message without attachments may still have wrong content-type. Thus, .HasAttachments property is not 100% accurate when only message headers are available. When the entire message was dwonloaded, .HasAttachments property value is determined from the number of attachments (Message.Attachments.Count) and is now 100% accurate.
 
 Regards,
 Alex
 | 
       
        | Back to Top |     | 
       
       
        |  |