This project is read-only.

Impossible to retrieve attachment in POP3

Sep 25, 2012 at 2:34 PM
Edited Sep 25, 2012 at 11:25 PM

Hi,

I have an email with has an attachment (a .txt file) but it's impossible to retrieve it !

I have tried the following :

int NbParts = mailmessage.Contents.Count; 
int aa = MailMessage.GetAttachedContents( mailmessage ).Count; 
 

both give me 0 (NbParts & aa)

the foreach( MailContent ct in mailmessage.Contents ) loops over too !

edited : it seems that the problem comes in an email in which the attachment is base64 encoded ....

any idea ?
thanks in advance,
Domi.

 

 

 

 

 

 

 

Sep 26, 2012 at 3:08 AM

Hi.
Please show me or send me your raw mail data.
I'll investigate what wrong with it.

Sep 26, 2012 at 7:59 AM
Edited Sep 26, 2012 at 8:38 AM

Hi,

thanks for your fast reply and for your excellent library.
In fact, the content of the attached text file is in the mg.BodyText in base64.

here is the _Data :

+OK 1779 octets
Return-Path: xxxxxxxxxx@skynet.be>
Delivered-To: xxxxxxxxxxxxx@ciel.be
Received: from b0.ovh.net (HELO queue) (213.186.33.50)
 by b0.ovh.net with SMTP; 22 Sep 2012 08:53:51 +0200
Received: from ovhs1.cielnetwork.be (HELO OVHS1.home) (188.165.226.9)
  by mx3.ovh.net with SMTP; 22 Sep 2012 08:53:51 +0200
Received: from ovhs1 ([127.0.0.1]) by home with MailEnable ESMTP; Sat, 22 Sep 2012 08:53:51 +0200
Date: Sat, 22 Sep 2012 08:53:51 +0200
Subject: Referencement Webservice
To:xxxxxxxxxxxxx@ciel.be
From: MASSILLON" <info@xxxxxxxxxxxxx.be>
Cc: xxxxxxxxxxxxx@ciel.be
MIME-Version: 1.0
Content-Type: application/octet-stream; name="_GRE8007268.txt"
Content-Transfer-Encoding: base64
Content-Disposition:attachement; filename="_GRE8007268.txt"
Message-ID: <3BDB81A5566243F984618BC81F03FD02.MAI@home>
X-Ovh-Tracer-Id: 6953276349986819574
X-Ovh-Remote: 188.165.226.9 (ovhs1.cielnetwork.be)
X-Ovh-Local: 213.186.33.73 (mx3.ovh.net)
X-OVH-SPAMSTATE: OK
X-OVH-SPAMSCORE: 0
X-OVH-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrfeehtddrkeegucetufdoteggodetrfcurfhrohhfihhlvgemucfqggfjnecuuegrihhlohhuthemuceftddtnecunecuhfhrohhmpefotefuuffknffnqffpfdcuoehinhhfohesfhhorhhgvgdqthhouhhrnhgrihdrsggvqeenucfjughrpeffuffvhfggtgfgugfksefqsgertddttddt
X-Spam-Check: DONE|U 0.500049/N
X-Antispam: clean, score=2
X-Antivirus: avast! (VPS 120925-1, 25/09/2012), Inbound message
X-Antivirus-Status: Clean

Q0lFTCBHRVNUSU9OIENPTU1FUkNJQUxFIFBSTyBQT1VSIFdJTkRPV1MsMSwxNy4wLDAxLzAxLzIw
MDIsR1JFODAwNzI2OCxMYSBGb3JnZSBkZSBCZWNsZXJzLE1BU1NJTExPTixQSElMSVBQRSwsMTAg
cGxhY2UgZGUgQmVjbGVycywsNzUzMixUT1VSTkFJIEJlY2xlcnMsQmVsZ2lxdWUsMDY5NTQ2NjUz
LDA2OTU0NjY1Myw4NTE1MDFCNkU4MTc0NjFFLEJFMDY3MDMzNTMyNiwwLEJFQ0xFUlMsWDg2NjQs
Ny45NCBHbyxTZXZlbiwsLCwsLCxSZXZlbmRldXIsLCwsLCwsLCwsLCwsLENvbW1lcmNlIC8gQXJ0
aXNhbmF0LCw0LCwsQkUwNjcwMzM1MzI2LENvbW1lcmNlLGluZm9AZm9yZ2UtdG91cm5haS5iZSxS
ZXZlbmRldXIsLCwsLA==

 

.

As you can see, the attached filename is _GRE8007268.txt

Do you need something else ? if you need more, can you explain how I can send it ?

PS: I have de-activated my antivirus/firewall without effect.

Thanks in advance,
sincerly,
Domi.

Sep 26, 2012 at 12:25 PM

OK.It is enough information.

I found out that this mail Content-Type is application/octed-stream.
So, library treat this mail as binary data and set BodyData value to BodyText property without decode.

You can easily get actual text data by below code.
--------------------------------------------------------------------------------------------------------------------
MailMessage mg = //Get some where...
mg.BodyText = MailParser.DecodeFromMailBody(mg.BodyData, mg.ContentTransferEncoding, mg.ContentEncoding);

--------------------------------------------------------------------------------------------------------------------

I hope that  my library automatically detect this mail is text mail and decode it.
This decision is made inside of IsText property InternetTextMessage class.
--------------------------------------------------------------------------------------------------------------------
        public Boolean IsText
        {
            get
            {
                return (this.ContentType.Value.StartsWith("text/", StringComparison.OrdinalIgnoreCase) == true) ||
                    (this.ContentType.Value.Equals("application/xml", StringComparison.OrdinalIgnoreCase) == true) ||
                    (this.ContentType.Value.Equals("application/json", StringComparison.OrdinalIgnoreCase) == true);
            }
        }
--------------------------------------------------------------------------------------------------------------------
I plan to change above code to below.
When MailMessage object has file name and the extension is .text, it may be a text data.
--------------------------------------------------------------------------------------------------------------------
        public Boolean IsText
        {
            get
            {
                return (this.ContentType.Value.StartsWith("text/", StringComparison.OrdinalIgnoreCase) == true) ||
                    (this.ContentType.Value.Equals("application/xml", StringComparison.OrdinalIgnoreCase) == true) ||
                    (this.ContentType.Value.Equals("application/json", StringComparison.OrdinalIgnoreCase) == true) ||
                    (this.ContentDisposition != null && this.ContentDisposition.FileName != null && this.ContentDisposition.FileName.EndWith(".txt"));
            }
        }
--------------------------------------------------------------------------------------------------------------------
But I could not ensure that algorithm is certain or not.
Someday I may implement it.

Anyway, you can get text value by MailParser.DecodeFromMailBody method.

regards.

Sep 27, 2012 at 2:45 PM

Hi higty,

Thanks for this but this solves the problems partially; I have added the code in the IsText method and I get the BodyText decoded correctly (no need to add  MailParser.DecodeFromMailBody somewhere else) but the mailmessage.Contents.Counts is always set to 0 and in my main message loop, I can't get the filename and therefore I'm unable to re-construct the attached file.

Maybe, we need to investigate more :-)
but thankx sincerly in trying to maintain this great lib up-to-date.

Domi.