OT: converted attachements

H

hilz

Hi all...
I have this question which is probably Off Topic, but maybe remotely
related to Java. I hope someone might be able to help.
Sometimes I receive emails with attachments that are converted to text
and appear in the body of the message...( something similar to the text
at the end of this message).
Is there a way to convert this text into the actual binary file?
if this is possible using a small Java program, i appreciate if someone
would briefly explain to me what i need to do.
Thanks


Content-Type: image/jpeg; name="ATT00003.jpg"
Content-Transfer-Encoding: base64
Content-ID: <000d01c63ca6$b58dbac0$6401a8c0@port2>
Content-Description: ATT00003.jpg
Content-Location: 1_multipart%3F2_ATT00003.jpg

/9j/4AAQSkZJRgABAQEBLAEsAAD/2wBDAAgGBgcGBQgHBwcJCQgKDBQNDAsLDBkSEw8UHRof
Hh0aHBwgJC4nICIsIxwcKDcpLDAxNDQ0Hyc5PTgyPC4zNDL/2wBDAQkJCQwLDBgNDRgyIRwh
MjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjL/wAAR
CAFNAfQDASIAAhEBAxEB/8QAHwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL/8QAtRAA
AgEDAwIEAwUFBAQAAAF9AQIDAAQRBRIhMUEGE1FhByJxFDKBkaEII0KxwRVS0fAkM2JyggkK
FhcYGRolJicoKSo0NTY3ODk6Q0RFRkdISUpTVFVWV1hZWmNkZWZnaGlqc3R1dnd4eXqDhIWG
h4iJipKTlJWWl5iZmqKjpKWmp6ipqrKztLW2t7i5usLDxMXGx8jJytLT1NXW19jZ2uHi4+Tl
 
T

tom fredriksen

hilz said:
Content-Type: image/jpeg; name="ATT00003.jpg"
Content-Transfer-Encoding: base64

/9j/4AAQSkZJRgABAQEBLAEsAAD/2wBDAAgGBgcGBQgHBwcJCQgKDBQNDAsLDBkSEw8UHRof
Hh0aHBwgJC4nICIsIxwcKDcpLDAxNDQ0Hyc5PTgyPC4zNDL/2wBDAQkJCQwLDBgNDRgyIRwh
MjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjL/wAAR
CAFNAfQDASIAAhEBAxEB/8QAHwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL/8QAtRAA
AgEDAwIEAwUFBAQAAAF9AQIDAAQRBRIhMUEGE1FhByJxFDKBkaEII0KxwRVS0fAkM2JyggkK
FhcYGRolJicoKSo0NTY3ODk6Q0RFRkdISUpTVFVWV1hZWmNkZWZnaGlqc3R1dnd4eXqDhIWG
h4iJipKTlJWWl5iZmqKjpKWmp6ipqrKztLW2t7i5usLDxMXGx8jJytLT1NXW19jZ2uHi4+Tl

If you look at the two headers above they explain some stuff about your
content. The encoding header states how the material is coded for safe
transfer across a protocol (google "transfer encoding"), the type header
says something about the actual type of the content after its transfer
decoding has been performed. So you need to decode the base64 part, that
should give you a binary string of the Content-Type format. So just
google for a base64 lib.

To really understand things like this have a look at the MIME rfc, which
defined what such headers are and how to use/interpret them.

/tom
 
T

Thomas Weidenfeller

hilz said:
I have this question which is probably Off Topic, but maybe remotely
related to Java. I hope someone might be able to help.
Sometimes I receive emails with attachments that are converted to text
and appear in the body of the message...( something similar to the text
at the end of this message).

E-Mail MIME attachments are not physically attached in some way to an
email. They are always part of the mail itself, and just logically
treated as attachments.
Is there a way to convert this text into the actual binary file?
if this is possible using a small Java program, i appreciate if someone
would briefly explain to me what i need to do. [...]
Content-Type: image/jpeg; name="ATT00003.jpg"
Content-Transfer-Encoding: base64

This says it is base64 encoded - which is the standard encoding used in
MIME messages (uuencode would be another one). The JavaMail API can
handle this. It provides the means to separate a MIME mail into the
parts, and decode the parts into the original (binary) data.

There are also (non-java) packages out there for handling such mails,
e.g. the rather old metamail. However, every modern MUA should do this
without the need to use any external tool. It has become absolutely
standard to support MIME e-mails in mail clients since probably ten or
15 years. The Thunderbird client which you use can of course do it
without breaking a sweat.

/Thomas
 
R

Roedy Green

Is there a way to convert this text into the actual binary file?

that particular one is base64 encoded. You could use any of the base64
decoder to get back the original bytes. See
http://mindprod.com/jgloss/base64.html
to understand the mechanism see
http://mindprod.com/jgloss/mime.html
and
http://mindprod.com/jgloss/javamail.html

One thing you might consider doing is upgrading to a more advanced
mail reader that does not get confused.

I am about to have a look at Thunderbird. I have been using Eudora
for years but it does not properly support SMIME or PGP , and
sometimes gets confused by attachments too. I would also like
anti-spam properly integrated.
 
H

hilz

Roedy said:
One thing you might consider doing is upgrading to a more advanced
mail reader that does not get confused.

I am about to have a look at Thunderbird. I have been using Eudora
for years but it does not properly support SMIME or PGP , and
sometimes gets confused by attachments too. I would also like
anti-spam properly integrated.


Actually this does not happen in Thunderbird. I only use Thunderbird for
news.
The problem i run into is in emails i receive at my hotmail :( account,
and i am viewing them using firefox (that is probably irrelevant).
So i don't have control over anything pretty much.

I am looking into writing a small utility to extract the attachement
from the text. you guys have provided me with some good information. I
just need to find the time to actually sit and write it!

thanks
 
H

hilz

Roedy said:
that particular one is base64 encoded. You could use any of the base64
decoder to get back the original bytes. See
http://mindprod.com/jgloss/base64.html
to understand the mechanism see
http://mindprod.com/jgloss/mime.html
and
http://mindprod.com/jgloss/javamail.html

One thing you might consider doing is upgrading to a more advanced
mail reader that does not get confused.

I am about to have a look at Thunderbird. I have been using Eudora
for years but it does not properly support SMIME or PGP , and
sometimes gets confused by attachments too. I would also like
anti-spam properly integrated.

Roedy,
I read the bas64 page on your website, and it seems to explain the
situation very well.
One thing that came to mind is the end of line characters.
If you notice, the characters are wraped at some specific length.
I assume i will have to remove those end of line characters when i am
processing the string in order to decode it. is that correct?
 
R

Roedy Green

The problem i run into is in emails i receive at my hotmail :( account,
and i am viewing them using firefox (that is probably irrelevant).
So i don't have control over anything pretty much.

I don't know what hotmail does with attachments, but if you forwarded
tem to a real email account perhaps they would come through unscathed.
 
R

Roedy Green

situation very well.
One thing that came to mind is the end of line characters.
If you notice, the characters are wraped at some specific length.
I assume i will have to remove those end of line characters when i am
processing the string in order to decode it. is that correct?
no. They are just noise and are automatically ignored. Any
character not in the base64 set is discarded. e.g. \n tab.

My version of Base64 8 comes with well-commented source. It is not
rocket science. That's why there are so many to choose from.

http://mindprod.com/products1.html#BASE64

Someday when I have a brain freeze I will run a bakeoff between them
to see if any are noticeably better.
 
H

hilz

Roedy said:
I don't know what hotmail does with attachments, but if you forwarded
tem to a real email account perhaps they would come through unscathed.

I tried that before, and didn't work
seems they come to hotmail that way.
 
T

Tris Orendorff

I am looking into writing a small utility to extract the attachement
from the text. you guys have provided me with some good information. I
just need to find the time to actually sit and write it!

I realize it's a pain to change email addresses but have you considered
changing to another email provider. eg. Yahoo lets you use pop3 to access
your mail ($20/year) and they also pop up icons that can be clicked on to
download attachments (free).
 
R

Roedy Green

I realize it's a pain to change email addresses but have you considered
changing to another email provider. eg. Yahoo lets you use pop3 to access
your mail ($20/year) and they also pop up icons that can be clicked on to
download attachments (free).

Main webmail are Gmail, Hotmail, Yahoo, Aol, others?
 
H

hilz

Tris said:
I realize it's a pain to change email addresses but have you considered
changing to another email provider. eg. Yahoo lets you use pop3 to access
your mail ($20/year) and they also pop up icons that can be clicked on to
download attachments (free).

Actually I have Gmail too, and i think it is superior to all other free
webmail services i've tried. But the point is that I just can't give up
my hotmail account.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top