mailing list archives

meli community discussions

⚠️ if something does not work as intended when interracting with the mailing lists,
reach out Github mirror Gitea repo @epilys:matrix.org

E-mail headers
From: Hatem El Hannachi <hatem.elhannachi@telnet.com.tn>
To: imap-protocol@u.washington.edu
Date: Fri, 08 Jun 2018 12:34:36 -0000
Message-ID: 7FEBB30F0CE41B419B38295024A58EE34D63B9@oxygen.mail.telnet.tunis permalink / raw / eml / mbox
Hi,

I am using imap for receiving mail. I used the following source code to receive mail:

//To open a pop session for receiving mail :

mail_link(&pop3driver);		/* link in the pop3 driver */
MAILSTREAM* l_mstream = NIL;
l_mstream=mail_open(NIL,g_a_cOpenMailString,T);

 
//To receive a mail with an attached file, I use these functions:

l_env=mail_fetchstructure(l_mstream,1,&l_body);
l_p_szBodyPart=mail_fetchbody(l_mstream,1, "1", &l_ulBodyPartLen);


I have the problem in deleting the received mail to avoid to receive it again, for this I used these functions:
mail_setflag(l_mstream,"1","\\DELETED");
mail_expunge(l_mstream);


But this not work, because I receive the same mail another time. 

Can any one tell me how can i delete the mail after receiving it to avoid that I receive it many times.


Here there is the source code I used to receive mail:

void RecieveMail(long debug)
{
	FILE* l_pFile;
	int l_iMail=0;

	//ajouter les drivers n?cessire 
	mail_link(&pop3driver);		/* link in the pop3 driver */

	printf("Ouverture de la boite mail\n");
	MAILSTREAM* l_mstream = NIL;

	ENVELOPE *l_env;
	BODY* l_body;		

	//param?tres contenant les ?l?ments cod?s du mail
	char* l_p_szBodyPart=0;
	unsigned long l_ulBodyPartLen;

	//param?tres contenant les ?l?ments d?cod?s du mail
	unsigned char* l_p_uszFileContenant=0;
	unsigned long l_ulFileLen;
    long l_nAlive = 1;
	l_mstream=mail_open(NIL,g_a_cOpenMailString,T);
	
	while(TRUE)
	{
		
		if (l_mstream )
		{	
			    if(!l_mstream->nmsgs )
				{	
						//reouverture
						l_mstream=mail_open(l_mstream,g_a_cOpenMailString,T);
						printf("**************** (%d) mails received  *********\n", l_iMail);
					    					    
				}

				if (l_mstream)
				{	
					
					while(l_mstream->nmsgs > 0)
					{
						l_env=mail_fetchstructure(l_mstream,1,&l_body);
						
      
						l_p_szBodyPart=mail_fetchbody(l_mstream,1, "1", &l_ulBodyPartLen);
						
						printf(l_p_szBodyPart);			

						//v?rifier s'il existe un fichier attach?
						if(l_body->type==TYPEMULTIPART)
						{
							//voir s'il ya un fichier join
							//on ne s'interesse qu'au 1er
							PART* l_part= l_body->nested.part;
							l_part=l_part->next;
            
							if(l_part!=NULL)
							{
								//si le fichier set de type application
								if(l_part->body.type == TYPEAPPLICATION && l_part->body.encoding == ENCBASE64)
								{
								    l_p_szBodyPart=mail_fetchbody(l_mstream,1, "2", &l_ulBodyPartLen);
									
									//conversion du fichier binaire et sauvegarde
									l_p_uszFileContenant=(unsigned char*)rfc822_base64((unsigned char*)l_p_szBodyPart,l_ulBodyPartLen,&l_ulFileLen);
									
									
									printf("**************** Reception mail %d*********\n", l_iMail);
									l_iMail++;
									l_pFile=fopen(g_a_cFilePath,"wb");
									fwrite(l_p_uszFileContenant,1,l_ulFileLen,l_pFile);
									fclose(l_pFile);
									free(l_p_uszFileContenant);							
								}
							}
						}
						//suppression du mail trait?			
						mail_setflag(l_mstream,"1","\\DELETED");
						mail_expunge(l_mstream);
											
						//reouverture
					   l_mstream=mail_open(l_mstream,g_a_cOpenMailString,T);
					   //raifraichissement
					   l_mstream=mail_open(l_mstream,g_a_cOpenMailString,T);
					   if(!l_mstream)
						 break;
						
					}
				}				
				else
				{
					l_mstream=mail_open(l_mstream,g_a_cOpenMailString,T);
					printf("**************** (%d) mails received  *********\n", l_iMail);
				}
		}
		else
		{
			 l_mstream=mail_open(l_mstream,g_a_cOpenMailString,T);
			 printf("**************** (%d) mails received  *********\n", l_iMail);
		}
	}
	
	//fermeture de la boite mail
	mail_close(l_mstream); 

}





Thanks for any help
Hatem


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman13.u.washington.edu/pipermail/imap-protocol/attachments/20060223/ae89cae1/attachment.html>
Reply
E-mail headers
From: mrc@CAC.Washington.EDU
To: imap-protocol@localhost
Date: Fri, 08 Jun 2018 12:34:36 -0000
Message-ID: Pine.OSX.4.64.0602230856470.13900@pangtzu.panda.com permalink / raw / eml / mbox
For future reference, please send questions involving the UW IMAP software 
to the imap-uw mailing list.  The imap-protocol mailing list is for 
questions dealing with the IMAP protocol architecture and not for software 
questions.  Thank you.

There are several problems.

First, you MUST NOT call mail_link() directly, and especially you should 
not do it in a subroutine.  Instead, at the very start of your main() 
function, you should have:
 	#include "linkage.c"

It is unpredictable what would happen if you fail to use the proper 
linkage.c, or if you call mail_link() for the same driver multiple times.

Second, I observe that you are doing:
 						//reouverture
 					   l_mstream=mail_open(l_mstream,g_a_cOpenMailString,T);
 					   //raifraichissement
 					   l_mstream=mail_open(l_mstream,g_a_cOpenMailString,T);
immediately after the mail_expunge() call.  I don't know why these 
statements are there, but they are definitely wrong.

Also note that in POP3, the action of an expunge does not actually happen 
until a proper close.  That is because the POP3 protocol does not remove 
messages until QUIT time.

-- Mark --

http://panda.com/mrc
Democracy is two wolves and a sheep deciding what to eat for lunch.
Liberty is a well-armed sheep contesting the vote.
Reply