Consider the following piece of code.
Code: Select all
For iMsg=1 To PurePOP3_CountMessages() ; retrieve each message and examine the header and if matched, save attachment
If PurePOP3_RetrieveMessage(iMsg) > 0
; message retrieved successfully, process it
AppLog("Λήψη Μηνύματος "+Str(iMsg),#False)
AppLog("Επισυναπτόμενα μηνύματος: "+Str(PurePOP3_CountAttachedFiles()),#False)
szFAtt$=""
szID$=""
sztmp1$=""
sztmp2$=""
msginfo$=PurePOP3_GetMessageInfo()
If FindString(msginfo$,"net.314 MedSync:",1)
AppLog("Το μήνυμα είναι προβλεπόμενο.",#False)
; the message subject is like this: net.314 MedSync: (ID) ...
; I need to get the ID
sztmp1$=Right(msginfo$,Len(msginfo$)-FindString(msginfo$,"net.314 MedSync: (",1))
sztmp2$=Right(sztmp1$,Len(sztmp1$)-FindString(sztmp1$,"(",1))
szID$=StringField(sztmp2$,1,")")
; get the attachment name
szFAtt$=StringField(PurePOP3_ListAttachementsForMessage(),1,Chr(9))
Debug szFAtt$
; now, save the attachment to the $BackupDir$\szID$ folder
If PurePOP3_SaveAttachementsToFile(Backend\BackupDir+"\"+szID$) = #Null
AppLog("Αδυναμία αποθήκευσης συννημμένων στο φάκελο "+Backend\BackupDir+"\"+szID$,#False)
Else
AppLog("Επιτυχής αποθήκευση αρχείου "+Backend\BackupDir+"\"+szID$,#False)
EndIf
; extract the saved attachment to the $ExtractDir$\szID$ folder
If PureZIP_ExtractFiles(Backend\BackupDir+"\"+szID$+"\"+szFAtt$, "*.*", Backend\ExtractDir+"\"+szID$, #False) = #Null
AppLog("Αδυναμία αποσυμπίεσης αρχείου "+Backend\BackupDir+"\"+szID$+"\"+szFAtt$,#False)
Else
AppLog("Επιτυχής αποσυμπίεση αρχείου "+Backend\BackupDir+"\"+szID$+"\"+szFAtt$,#False)
; add the e-mail to the final e-mail notification queue
szMessageNotification=szMessageNotification+"Successfully retrieved data from "+msClient(Val(szID$))\Label+" - "+szFAtt$+Chr(13)
EndIf
Else
; mail is OK, but no attachments
AppLog("Βρέθηκε μήνυμα αλλά όχι επισυναπτόμενο.",#False)
AppLog("Διαγραφή μη προβλεπoμένου μηνύματος "+Str(PurePOP3_DeleteMessage(iMsg))+"("+PurePOP3_GetLastServerMessage()+")",#False)
EndIf
EndIf
Next
; close the POP3 server
PurePOP3_ClosePOP3Connection()
Suppose we have a mail server (maxmail) with 4 messages. Each message has an attachment, so there are 4 attachments in total. The above code should iterate 4 times and save 4 attachements.
The only problem is that it runs only 3 times, right after executing this
Code: Select all
; extract the saved attachment to the $ExtractDir$\szID$ folder
If PureZIP_ExtractFiles(Backend\BackupDir+"\"+szID$+"\"+szFAtt$, "*.*", Backend\ExtractDir+"\"+szID$, #False) = #Null
AppLog("Αδυναμία αποσυμπίεσης αρχείου "+Backend\BackupDir+"\"+szID$+"\"+szFAtt$,#False)
Else
AppLog("Επιτυχής αποσυμπίεση αρχείου "+Backend\BackupDir+"\"+szID$+"\"+szFAtt$,#False)
The code worked with PureBasic 4.10b2 and PurePOP3, but now it produces this result with PureBasic 4.10 final and the latest PurePOP3.
I am providing the debug files produced by PurePOP3_Debug() so that it will help tracking down what's possibly wrong with the code or the library itself.
Code: Select all
http://www.uploading.com/files/ULBGR6C5/PPOP3dbg.zip.html
Many thanks in advance.