MBOX-Line: From hatem.elhannachi at telnet.com.tn  Thu Feb 23 01:06:29 2006
To: imap-protocol@u.washington.edu
From: Hatem El Hannachi <hatem.elhannachi@telnet.com.tn>
Date: Fri Jun  8 12:34:36 2018
Subject: [Imap-protocol] Problem in receiving mail using imap
Message-ID: <7FEBB30F0CE41B419B38295024A58EE34D63B9@oxygen.mail.telnet.tunis>

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>
