[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

fniles

9/6/2010 7:56:00 PM

Using winsock, how can I read POP 3 email attachment (the attachment is an
..EML file) ?

Thank you


37 Answers

Mayayana

9/6/2010 9:49:00 PM

0

You got the basic read working? If so, you
just need to parse the text. Attachments
are linked internally to Base64 strings. Open
an email with attachment in Notepad and
you'll see how it works. To convert Base64 to
bytes:

Private Function DecodeBase64(s64 As String) As String
Static Enc() As Byte
Dim B1() As Byte, B2() As Byte
Dim i As Long, i2 As Long, i3 As Long, LLen As Long
Dim Dec(0 To 255) As Byte
On Error Resume Next
If (Not Val(Not Enc)) = 0 Then
Enc =
StrConv("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",
vbFromUnicode)
End If
For i = 0 To 255
Dec(i) = 64
Next
For i = 0 To 63
Dec(Enc(i)) = i
Next
LLen = Len(s64)
B1 = StrConv(s64, vbFromUnicode)
ReDim Preserve B2(0 To (LLen \ 4) * 3 - 1)
For i = 0 To UBound(B1) Step 4
B2(i2) = (Dec(B1(i)) * 4) Or (Dec(B1(i + 1)) \ 16)
i2 = i2 + 1
B2(i2) = (Dec(B1(i + 1)) And 15) * 16 Or (Dec(B1(i + 2)) \ 4)
i2 = i2 + 1
B2(i2) = (Dec(B1(i + 2)) And 3) * 64 Or Dec(B1(i + 3))
i2 = i2 + 1
Next i
If B1(LLen - 2) = 61 Then
i2 = 2
ElseIf B1(LLen - 1) = 61 Then
i2 = 1
Else
i2 = 0
End If
ReDim Preserve B2(0 To UBound(B2) - i2)
DecodeBase64 = StrConv(B2, vbUnicode)
End Function

| Using winsock, how can I read POP 3 email attachment (the attachment is an
| .EML file) ?
|
| Thank you
|
|


Dee Earley

9/7/2010 7:43:00 AM

0

On 06/09/2010 20:55, fniles wrote:
> Using winsock, how can I read POP 3 email attachment (the attachment is an
> .EML file) ?

Have a look at RFC1939 for the POP3 protocol (It's as easy as login, get
message, disconnect), and then RFC822, the MIME/multipart MIME specs and
base64 decoding (if required).
If the attachment is another email, then that is nothing special, it's
just the same structure again.

--
Dee Earley (dee.earley@icode.co.uk)
i-Catcher Development Team

iCode Systems

(Replies direct to my email address will be ignored.
Please reply to the group.)

fniles

9/7/2010 9:28:00 PM

0

Thank you

What is RFC1939 and RFC822 ?
Where can I find it ?

"Dee Earley" <dee.earley@icode.co.uk> wrote in message
news:%23QILCEmTLHA.5944@TK2MSFTNGP06.phx.gbl...
> On 06/09/2010 20:55, fniles wrote:
>> Using winsock, how can I read POP 3 email attachment (the attachment is
>> an
>> .EML file) ?
>
> Have a look at RFC1939 for the POP3 protocol (It's as easy as login, get
> message, disconnect), and then RFC822, the MIME/multipart MIME specs and
> base64 decoding (if required).
> If the attachment is another email, then that is nothing special, it's
> just the same structure again.
>
> --
> Dee Earley (dee.earley@icode.co.uk)
> i-Catcher Development Team
>
> iCode Systems
>
> (Replies direct to my email address will be ignored.
> Please reply to the group.)


Bob Butler

9/7/2010 10:23:00 PM

0


"fniles" <fniles@pfmail.com> wrote in message
news:e8n3JOtTLHA.2068@TK2MSFTNGP05.phx.gbl...
> Thank you
>
> What is RFC1939 and RFC822 ?
> Where can I find it ?

http://www.lmgtfy.com/...

<g>

ralph

9/7/2010 10:28:00 PM

0

On Tue, 7 Sep 2010 16:27:53 -0500, "fniles" <fniles@pfmail.com> wrote:

>Thank you
>
>What is RFC1939 and RFC822 ?
>Where can I find it ?
>

The poorly named bible/s for the internet ...
"Request For Comments"

"Post Office Protocol - Version 3"
http://tools.ietf.org/ht...

"Internet Text Messages"
http://tools.ietf.org/h...

-ralph

Mayayana

9/7/2010 11:55:00 PM

0

| Thank you
|
| What is RFC1939 and RFC822 ?
| Where can I find it ?

The RFCs are the official documentation, but
that's a wild goose chase. It's like telling
you to read the official 2010 tax code to find
out whether you can deduct your office in the
home. The info. is in there...but you'll never
find it. I already told you how to find the
attachment and retrieve it. If you don't understand
just try looking at the raw text of a few emails.
The MIME format is text-based and systematic.
You can parse it just like an email program can
parse it.


Mayayana

9/8/2010 3:31:00 AM

0

I just tried this. It's a little bit tricky, at least in
OE, because the attached email was not fully
encoded. It was just sandwiched. Normally when you
attach a file it gets inserted as a single Base64 string.
(Note that you may have to remove carriage returns,
tabs, or other formatting junk before decoding Base64.)

Here's a sample of the format for an email with
a JPG attachment. Note that the "boundary" value
defines a random string that separates sections of the
email. The email is parsed using boundary markers
and empty lines to identify content. Boundaries must
begin with "--". The closing boundary begins with
"--" and also ends with "--".

_________ Begin sample ______________

from
to
date
subject
Message-ID
MIME-Version: 1.0
Content-Type: multipart/mixed;
boundary="BOUNDARY_STRING_1"
X-Mailer: [email program name here]
#
--BOUNDARY_STRING_1
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
#
(email text here)
#
--BOUNDARY_STRING_1
Content-Type: image/jpeg;
name="pic1.jpg"
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
filename="pic1.jpg"
#
(base 64 here)
#
--BOUNDARY_STRING_1--

________________ end sample ________

Notice that the attachment is identified
with the line:

Content-Disposition: attachment

The beginning of the attachment info. is marked
by a boundary string. The Base64 string representing
the actual file content has an empty line before and
after. So it's fairly easy to check for attachments
and it's easy to extract the attachment(s).

When I created an email with an attachment, then
attached that to another email, I ended up with the
entire first email copied in the second email. It began
with this:

Content-Type: message/rfc822;
name="mmm.eml"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
filename="mmm.eml"

But then instead of a blank line followed by Base64, there
was a blank line followed by the raw text of the first email:

From:
To:
Subject:
..etc.

The attachment in the attached email is still there. Then
the end is like this:

--Boundary_string_from_attached_email--

--Boundary_string_from_main_email--


So you have to parse an email within an email. But as
you can see from the snippets I've posted, it still follows
standards. You'll look for

Content-Disposition: attachment
with
Content-Type: message/rfc822

(It may be possible for an email to have other content
type. i'm not sure.)

The attached email will start after the next blank line.
From there you find

boundary=

then find the end of the attached email by
looking for that with "--" appended. Note,
however, that the boundary is only necessary
where Content-Type is multipart/*
If Content-Type is text/plain in the attached
email, the end of the attached email may be delineated
only by a boundary marker in the main email.

Basically, attached plain text is inserted as
plain text. Attached binary data is base64-encoded.
In the case of an attached email with attachments,
the attachment can be both because the actual file
content of the attached .EML is both. (It's all plain
text, technically, but any base64-encoded content
represents binary data.) So in order to
know whether you need to do any base64 decoding you
need to check the Content-Type of the attachment.
And you might have to do that recursively if you have
an attached EML file.

(I know this all sounds confusing, but it's actually
a simple and fairly sensible system once you get
the gist of it.)


fniles

9/10/2010 11:45:00 PM

0

Thank you, all.

Is it possible to save the attachment as a file, so that I can resend the
attachment as a file in another email ?


"Mayayana" <mayayana@invalid.nospam> wrote in message
news:i66vu7$bup$1@news.eternal-september.org...
> I just tried this. It's a little bit tricky, at least in
> OE, because the attached email was not fully
> encoded. It was just sandwiched. Normally when you
> attach a file it gets inserted as a single Base64 string.
> (Note that you may have to remove carriage returns,
> tabs, or other formatting junk before decoding Base64.)
>
> Here's a sample of the format for an email with
> a JPG attachment. Note that the "boundary" value
> defines a random string that separates sections of the
> email. The email is parsed using boundary markers
> and empty lines to identify content. Boundaries must
> begin with "--". The closing boundary begins with
> "--" and also ends with "--".
>
> _________ Begin sample ______________
>
> from
> to
> date
> subject
> Message-ID
> MIME-Version: 1.0
> Content-Type: multipart/mixed;
> boundary="BOUNDARY_STRING_1"
> X-Mailer: [email program name here]
> #
> --BOUNDARY_STRING_1
> Content-Type: text/plain;
> charset="iso-8859-1"
> Content-Transfer-Encoding: 7bit
> #
> (email text here)
> #
> --BOUNDARY_STRING_1
> Content-Type: image/jpeg;
> name="pic1.jpg"
> Content-Transfer-Encoding: base64
> Content-Disposition: attachment;
> filename="pic1.jpg"
> #
> (base 64 here)
> #
> --BOUNDARY_STRING_1--
>
> ________________ end sample ________
>
> Notice that the attachment is identified
> with the line:
>
> Content-Disposition: attachment
>
> The beginning of the attachment info. is marked
> by a boundary string. The Base64 string representing
> the actual file content has an empty line before and
> after. So it's fairly easy to check for attachments
> and it's easy to extract the attachment(s).
>
> When I created an email with an attachment, then
> attached that to another email, I ended up with the
> entire first email copied in the second email. It began
> with this:
>
> Content-Type: message/rfc822;
> name="mmm.eml"
> Content-Transfer-Encoding: 7bit
> Content-Disposition: attachment;
> filename="mmm.eml"
>
> But then instead of a blank line followed by Base64, there
> was a blank line followed by the raw text of the first email:
>
> From:
> To:
> Subject:
> ..etc.
>
> The attachment in the attached email is still there. Then
> the end is like this:
>
> --Boundary_string_from_attached_email--
>
> --Boundary_string_from_main_email--
>
>
> So you have to parse an email within an email. But as
> you can see from the snippets I've posted, it still follows
> standards. You'll look for
>
> Content-Disposition: attachment
> with
> Content-Type: message/rfc822
>
> (It may be possible for an email to have other content
> type. i'm not sure.)
>
> The attached email will start after the next blank line.
> From there you find
>
> boundary=
>
> then find the end of the attached email by
> looking for that with "--" appended. Note,
> however, that the boundary is only necessary
> where Content-Type is multipart/*
> If Content-Type is text/plain in the attached
> email, the end of the attached email may be delineated
> only by a boundary marker in the main email.
>
> Basically, attached plain text is inserted as
> plain text. Attached binary data is base64-encoded.
> In the case of an attached email with attachments,
> the attachment can be both because the actual file
> content of the attached .EML is both. (It's all plain
> text, technically, but any base64-encoded content
> represents binary data.) So in order to
> know whether you need to do any base64 decoding you
> need to check the Content-Type of the attachment.
> And you might have to do that recursively if you have
> an attached EML file.
>
> (I know this all sounds confusing, but it's actually
> a simple and fairly sensible system once you get
> the gist of it.)
>
>


Mayayana

9/10/2010 11:56:00 PM

0


|
| Is it possible to save the attachment as a file, so that I can resend the
| attachment as a file in another email ?
|
Why not? It's coming through as the complete text
of an email. The whole thing is just text. You just have
to identify the beginning and end of the attached email,
get that text, and save it.


fniles

9/12/2010 6:07:00 PM

0

Thank you.

I am looking for <HTML> and </HTML> in the text, but there are so many
things like "3D2=20","3D0=20", "3D1=20" that when I create an email using
that, the email doesn't look like the original.
Any suggestion ?

Thank you for your help.

This is part of the text:
<META name=3DGENERATOR content=3D"MSHTML 8.00.6001.18928"></HEAD>
<BODY>
<DIV><FONT size=3D2 face=3DArial></FONT>&nbsp;</DIV>
<TABLE id=3D201179 border=3D0 width=3D"100%" height=3D400>
<TBODY>
<TR>
<TD vAlign=3Dtop width=3D"100%">
<DIV dir=3Dltr align=3Dleft><FONT color=3D#0000ff size=3D2=20
face=3DArial></FONT>&nbsp;</DIV>
<DIV></DIV><A name=3Dtop target=3D_blank></A>
<TABLE style=3D"BORDER-COLLAPSE: collapse" border=3D0 =
cellSpacing=3D0=20
borderColor=3D#111111 cellPadding=3D0 width=3D"100%">
<TBODY>
<TR>
<TD colSpan=3D3>
<TABLE style=3D"BORDER-COLLAPSE: collapse" border=3D0 =
cellSpacing=3D0=20
borderColor=3D#111111 width=3D"100%">
<TBODY>
<TR>
<TD width=3D"80%" colSpan=3D2>
<TABLE style=3D"BORDER-COLLAPSE: collapse" border=3D1=20
cellSpacing=3D0 borderColor=3D#111111 cellPadding=3D0 =
width=3D"19%"=20
bgColor=3D#ff0000>
<TBODY>
<TR>
<TD width=3D"100%"><B><FONT color=3D#ffffff =
size=3D2=20


"Mayayana" <mayayana@invalid.nospam> wrote in message
news:i6egfn$kq7$1@news.eternal-september.org...
>
> |
> | Is it possible to save the attachment as a file, so that I can resend
> the
> | attachment as a file in another email ?
> |
> Why not? It's coming through as the complete text
> of an email. The whole thing is just text. You just have
> to identify the beginning and end of the attached email,
> get that text, and save it.
>
>