Jump to content

_pop3 UDF, according to the 1939 RFC


Apzo
 Share

Recommended Posts

Hello

I made a set of pop3 functions, based on the pop3 RFC and the wonderfull abilities of the 3.1.1.110 au3 beta version.

You will find in the zip file a sample script, and of course the library.

The functions are :

_pop3Connect (server, login, passwd [, port])
_Pop3Dele(msg_number)
_Pop3List([msg_number])
_Pop3Noop()
_Pop3Quit()
_Pop3Retr(msg_number)
_Pop3Rset()
_Pop3Stat()
_Pop3Top(msg_number, lines)
_Pop3Uidl([msg_number])

I'm sure you bot coders will love it :o

Have fun !

Apzo.

[Edit]

2008, Oct 29.

Thanks to Alexandre Beloin, the _pop3Disconnect() has been updated.

The zip file has been updated too.

[/Edit]

_pop3.zip

Edited by Apzo
Link to comment
Share on other sites

sounds cool, I'll look at it later. BTW what login method do you use? plain text?

Plain text, yes, the good old login/pass on port 110 is still a major security hole :o

However I'm trying to understand the APOP mechanism, it uses md5 but I don't know if my ISP currently support it.

I'll tell here about new enhancements.

Apzo.

Link to comment
Share on other sites

Looks great, will check it out.

How does it handle attachments?

Attachments are not part of the POP3 protocol.

The mails are text encoded in the mailbox, and retrieved as text.

If you need to handle attachments, I've seen a base64 UDF around here that may suit your needs.

EDIT : attachments rather need a mime decoder, kinda great challenge !

Some work for Mikeytown2 and Blindwig ?

That's great! Can you make an IMAP one one? :sorcerer:

Why not ? It may be a great copy/paste party, but it shouldn't be difficult ;)

I'm thinking about some other protocols, such as SMTP and IRC :o

It's easy now to code net protocols with the new net and regexp functions :geek:

Apzo.

Edited by Apzo
Link to comment
Share on other sites

Attachments are not part of the POP3 protocol.

The mails are text encoded in the mailbox, and retrieved as text.

If you need to handle attachments, I've seen a base64 UDF around here that may suit your needs.

Why not ? It may be a great copy/paste party, but it shouldn't be difficult ;)

I'm thinking about some other protocols, such as SMTP and IRC :o

It's easy now to code net protocols with the new net and regexp functions :geek:

Apzo.

Yeah check out my sig for links to the base64 encoder/decoder. i also just updated my SMTP stuff in that same thread, so you might want to look at that as well. I modded the code from the beta Inet file for my smtp stuff.

C:\program Files\AutoIt3\beta\Include\Inet.au3

I also added sending email directly to the mx server in the example.

Link to comment
Share on other sites

Yeah check out my sig for links to the base64 encoder/decoder. i also just updated my SMTP stuff in that same thread, so you might want to look at that as well. I modded the code from the beta Inet file for my smtp stuff.

C:\program Files\AutoIt3\beta\Include\Inet.au3

I also added sending email directly to the mx server in the example.

Great job, once more :geek:

But attachments need mime decode :o

(I hope my boss didn't noticed my error)

A solution is to use Munpack; I'd prefer an UDF but I couldn't find some.

Apzo.

Link to comment
Share on other sites

  • 1 year later...
  • 1 month later...

Gmail doensn't use the pop3 protocol !

It's a web based one, like Hotmail.

Apzo.

you can still use pop3 if you want...and hotmail has pop3 servers too by the way...

The cake is a lie.www.theguy0000.com is currentlyUP images.theguy0000.com is currentlyUP all other *.theguy0000.com sites are DOWN

Link to comment
Share on other sites

  • 2 weeks later...

Anything new on SSL and pop3?

http://mail.google.com/support/bin/answer.py?answer=13287

Pop enabled, yes, but SSL secured :P

Thus the IP port is not 110 but 995, and ssl encoded.

So far we don't have SSL funcs in AutoIt (HELP !), maybe stunnel would help.

BTW I'm still looking for Jabber doc and help : Jabber protocol (Gtalk) seems promising.

Any DLL coder in touch for it yet ?

Apzo.

Link to comment
Share on other sites

  • 7 months later...

Maybe useful for other:

The function _Pop3Quit() send a QUIT to the server but doesn't run the function _Pop3Disconnect(), so you're never fully disconnected. A simple solution is to add _Pop3Disconnect() after _Pop3Quit()

Also _Pop3Disconnect() never reset $pop3_IsConnected to zero. So even if you use _Pop3Disconnect() you'll still be unable to connect again(Error: $pop3_error_already_connected). You need to add $pop3_IsConnected = 0 just before Return 0 in the function _Pop3Disconnect().

Func _pop3Disconnect()
    If $pop3_IsConnected <> 0 Then
        TCPCloseSocket ($pop3_socket)
        TCPShutDown ()
        $pop3_IsConnected = 0; Add this line to get a proper connection status
        Return 0
    Else
        SetError($pop3_error_not_connected)
        Return -1
    EndIf
EndFunc  ;==>_pop3Disconnect
Link to comment
Share on other sites

  • 3 months later...
  • 2 weeks later...

So this UDF will not work with SSL right? No gmail, or yahoo? Also, what POP servers work with it, I have tried several and not had a lot of success.

Thanks!

Correct, it won't. Different reasons (unless you have a paid yahoo account).

Depending on what you need, you can check out the cdo mail methodology that's commonly used around here for sending mail, if you're trying to build a reader, don't have a lot of help for you.

I've written some code that at some time may be fleshed out enough involving blat and stunnel that gets me what I need for things like email logging, etc.

Reading the help file before you post... Not only will it make you look smarter, it will make you smarter.

Link to comment
Share on other sites

I wrote (with great help from MrCreatoR) e-mail parser, which may be useful for someone.

It returns an Array where saved:

In the 1st line - Sender's name

In the 2nd line - Sender's address

In the 3rd line - Recipient name

In the 4th line - Recipient address

In the 5th line - Subject

In the 6th line - Charset

In the 7th line - Message body

In the 8th line - Attachment's name (if exists)

In the 9th line - Attachment's body (if exists)

In the next pairs of lines - names and bodies of the other attachments (if exist)

#include <Array.au3>
#include <_pop3.au3>

; Just example
Global $MyPopServer = "pop.yandex.ru"
Global $MyLogin = "delta2-greit"
Global $MyPasswd = "will_not_say"
 
; Connecting to POP3
_pop3Connect($MyPopServer, $MyLogin, $MyPasswd)
If @error Then
    MsgBox(16, "Error. Code " & @error, "Unable to connect to " & $MyPopServer)
    Exit
Else
    ConsoleWrite("Connected to server pop3 " & $MyPopServer & @CR)
EndIf
; Downloading letter #1
Local $retr = _Pop3Retr(1)
If Not @error Then
    $aParsedLetter = _ParseEmail ($retr); sends downloaded letter for parsing
Else
    ConsoleWrite("Retr commande failed" & @CR)
    Exit
EndIf
; Closing connection
ConsoleWrite(_Pop3Quit() & @CRLF)
; End of the example
 
 
_ArrayDisplay ($aParsedLetter)
 
Func _ParseEmail ($sReadFile)
    Dim $aLetter[1]
    _AddToLetterArray (StringRegExp($sReadFile, '(?im)^From: +(.*)(?: |<)(?:.*?<|)(.*?)(?:>|)\r\n', 1), $aLetter)
    _AddToLetterArray (StringRegExp($sReadFile, '(?im)^To: +(.*)(?: |<)(?:.*?<|)(.*?)(?:>|)\r\n', 1), $aLetter)
    _AddToLetterArray (StringRegExp($sReadFile, '(?im)^Subject: +(.*)\r\n', 1), $aLetter)
    _AddToLetterArray (StringRegExp($sReadFile, '(?i) charset="?(.*?)(?:"|\r\n)', 1), $aLetter)

    $aSplit = StringSplit ($sReadFile, @CRLF, 1)
    $iFirstBoundaryString = _ArraySearch ($aSplit, "boundary=", 0, 0, 0, 1)
    $iBoundary = $aSplit[$iFirstBoundaryString]
    $iBoundary_startpos = StringInStr ($iBoundary, '"')
    $iBoundary_endpos = StringInStr ($iBoundary, '"', 0, 2)
    $boundary = StringMid ($iBoundary, $iBoundary_startpos+1, $iBoundary_endpos-$iBoundary_startpos-1)
    $boundary1 = _ArraySearch ($aSplit, $boundary, $iFirstBoundaryString+1, 0, 1, 1)
    $boundary2 = _ArraySearch ($aSplit, $boundary, $boundary1+1, 0, 1, 1)
    $message = ""
    $Write = False
    For $i=$boundary1 To $boundary2-1
        If $aSplit[$i] = "" Then $Write = True
        If $Write = True Then $message &= $aSplit[$i] & @CRLF
    Next
    _AddToLetterArray ($message, $aLetter)
 
    _AddToLetterArray (StringRegExp($sReadFile, '(?ims) filename="?(.*?)(?:"|\r).*?\n\r\n(.*?)\r\n^-+', 3), $aLetter)
 
    Return $aLetter
EndFunc; ==> _ParseEmail
 
Func _AddToLetterArray ($aContents, ByRef $afLetter)
   If IsArray($aContents) Then
        For $t = 0 to UBound ($aContents) - 1
            _ArrayAdd ($afLetter, $aContents[$t])
        Next
    Else
        _ArrayAdd ($afLetter, $aContents)
    EndIf
    Return $afLetter
EndFunc;==>_AddToLetterArray

Any reaction will be highly appreciated.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...