Page 16 of 23

Posted: Tue Jan 13, 2009 1:32 pm
by gnozal
The ''Unable to lock maildrop' error may happen if the connection made to the the server has been broken (the mailbox will usually reset itself after some delay) or if another connection is currently open to the mailbox.

In PurePOP3, the TimeOut is the time a library function waits for an answer from the server before exiting with error
#PurePOP3_ServerTimeOut.

1. Did you get #PurePOP3_ServerTimeOut / #PurePOP3_BadResponse errors ?
2. In your code, could simultaneous connections happen (threads ...) ?

In any case, I would try increasing the delay between two checks.

Posted: Tue Jan 13, 2009 1:43 pm
by PB
I only got the errors mentioned above. No threads in use. But I've set the
timeout now to 10 seconds and my app only opens and checks the server
every 30 seconds. Seems to be stable to far.

(BTW, the default timeout of 5 seconds was causing errors too, so maybe
you should increase it to 10 by default?).

Posted: Tue Jan 13, 2009 1:51 pm
by gnozal
PB wrote:I only got the errors mentioned above. No threads in use. But I've set the
timeout now to 10 seconds and my app only opens and checks the server
every 30 seconds. Seems to be stable to far.
Ok.
Maybe the 10 seconds delay was too short for the server ?
PB wrote:(BTW, the default timeout of 5 seconds was causing errors too, so maybe you should increase it to 10 by default?).
I set it to 5 seconds because it worked with the servers I had tested. Maybe I was just lucky. I have no idea what the average response time is.

Posted: Tue Jan 13, 2009 2:03 pm
by PB
> I set it to 5 seconds because it worked with the servers I had tested

Yes, 5 seconds is too low for my needs. (This was before the above problem).
I set it to 10 and it worked better and was more reliable, so I recommend
leaving it at 10 by default so other users don't have issues. It's only another
5 seconds so it's not too long to wait. ;)

BTW, does PurePOP3 work with Gmail? I keep getting timeouts when testing,
like it can't log in. I've enabled POP in Gmail and tried changing the port to 995
(per its help) but still nothing? The help says SSL authentication is needed?

Posted: Tue Jan 13, 2009 2:23 pm
by gnozal
PB wrote:BTW, does PurePOP3 work with Gmail? I keep getting timeouts when testing, like it can't log in. I've enabled POP in Gmail and tried changing the port to 995 (per its help) but still nothing? The help says SSL authentication is needed?
No, GMAIL uses TLS/SSL.
It may work with STunnel though ; here a PureSMTP example : http://www.purebasic.fr/english/viewtopic.php?t=33066

Posted: Sat Jan 17, 2009 3:28 am
by PB
Hi gnozal, still having problems with PurePOP3 here. :(

Here's my actual code, with the processing bits and AddLog() proc removed,
as you don't need to see them here as they're too long.

Click here to see the log result:
File:1->LogFile.zip
Image

As you can see in the log result, it's okay most of the time, but then goes
through periods of not working. Do you think it's maybe my POP server?

Code: Select all

; Checks mail server every 60 seconds.

InitNetwork()

PurePOP3_SetTimeOut(30) ; Default of 5 means this code NEVER works.

OpenWindow(0,0,0,0,0,"",#PB_Window_Invisible)

Procedure AddToLog(text$)
  Debug text$
EndProcedure

Procedure.s Stamp()
  ProcedureReturn "test: "
EndProcedure

Repeat

  ev=WindowEvent()

  If ev=0

    Sleep_(1)

    If GetTickCount_()>timeout

      If PurePOP3_OpenPOP3Connection("mail.tpg.com.au",110,"name","pass")<>#PurePOP3_Ok
        AddToLog(Stamp()+"Failed to connect to mail server ("+PurePOP3_GetLastServerMessage()+").")
      Else
        n=PurePOP3_CountMessages()
        If n=0
          AddToLog(Stamp()+"Connected to mail server but found 0 messages waiting.")
        Else
          AddToLog(Stamp()+"Connected to mail server and found "+Str(n)+" messages waiting.")
          For m=1 To n
            Sleep_(1)
            If PurePOP3_RetrieveMessage(m)<0
              AddToLog(Stamp()+"Failed to retrieve message "+Str(m)+" of "+Str(n)+".")
            Else
              ok=0 : b=PurePOP3_GetMessageTextInMemory()
              If b : body$=PeekS(b) : FreeMemory(b) : EndIf
              AddToLog("")
              AddToLog(Stamp()+"Parsing message "+Str(m)+" of "+Str(n)+"...")
              ;
              ; Processing mail snipped out here to reduce size.
              ; Successful processes have "ok=1" in their code.
              ;
              If ok=0
                AddToLog(Stamp()+"Failed")
              Else
                AddToLog(Stamp()+"Success!")
              EndIf
            EndIf
          Next
        EndIf
        PurePOP3_ClosePOP3Connection()
      EndIf

      timeout=GetTickCount_()+60000

    EndIf

  EndIf

ForEver

Posted: Sat Jan 17, 2009 9:05 am
by gnozal
Hi PB,

All I can say is I never had this problem. And I am no network guru.

1. It would be useful to know the error returned by PurePOP3_OpenPOP3Connection() when it fails to connect to the server.
If it is #PurePOP3_NoConnection (-2), it means OpenNetworkConnection(pop3server, POP3Port) failed. I don't see what I could do.
If it is some other error, it might be a another problem.

2. It would be interesting to add < AddToLog(Stamp()+"Close connection to mail server ("+PurePOP3_GetLastServerMessage()+").") > after PurePOP3_ClosePOP3Connection(), to check if the connection was properly closed.

Posted: Sat Jan 17, 2009 9:47 am
by PB
Hi gnozal,

> It would be useful to know the error returned by PurePOP3_OpenPOP3Connection()

You mean the actual error code and not the message? Okay, I will change
the code to return that too. Sometimes the message is just "+OK" when it
fails, as you can see from the log. That's weird. :)

I will also add the PurePOP3_GetLastServerMessage() after closing, as you
suggested, and also turn on the debug thing to see what it reports. I won't
be able to report back until next week though, as this problem is happening
when I'm at work.

Posted: Sat Jan 17, 2009 10:08 am
by gnozal
PB wrote:Sometimes the message is just "+OK" when it
fails, as you can see from the log. That's weird. :)
It's the last server message.
So if the connection failed [no server message], it might be the server's reply to the "QUIT" command sent by a previous PurePOP3_ClosePOP3Connection() call.

Posted: Sun Jan 18, 2009 7:05 am
by PB
I just updated my app to use the default timeout (5 seconds) and to parse
my POP3 inbox every 10 seconds, and here is the result:

Code: Select all

18/01/09 15:58:07  Connected to mail server and found 1 messages waiting.
18/01/09 15:58:08  Parsing message 1 of 1 for actions...
18/01/09 15:58:08  Not actioned.
18/01/09 15:58:08  Closed connection (1).
18/01/09 15:58:18  Connected to mail server and found 1 messages waiting.
18/01/09 15:58:18  Parsing message 1 of 1 for actions...
18/01/09 15:58:18  Not actioned.
18/01/09 15:58:18  Closed connection (1).
18/01/09 15:58:28  Connected to mail server and found 1 messages waiting.
18/01/09 15:58:28  Parsing message 1 of 1 for actions...
18/01/09 15:58:28  Not actioned.
18/01/09 15:58:28  Closed connection (1).

[Above repeated until this next bit]

18/01/09 16:03:40  Failed to connect to mail server (-3 / ERR PurePOP3 Server TimeOut).
18/01/09 16:03:50  Failed to connect to mail server (-2 / ERR PurePOP3 Server TimeOut).
18/01/09 16:04:00  Failed to connect to mail server (-2 / ERR PurePOP3 Server TimeOut).
18/01/09 16:04:10  Failed to connect to mail server (-2 / ERR PurePOP3 Server TimeOut).
18/01/09 16:04:20  Failed to connect to mail server (-2 / ERR PurePOP3 Server TimeOut).
18/01/09 16:04:30  Failed to connect to mail server (-2 / ERR PurePOP3 Server TimeOut).
So, it seems to run for a while before error code -3 is returned, followed
by endless error codes of -2 when trying to connect. :( The closing of
connections seems to be okay, returning a code of 1 each time. This
was with the default timeout settings, and it only lasted for 5 minutes
before dying. So I used PurePOP3_SetTimeOut(15) and checked every
30 seconds instead of 10, and here is the log now:

Code: Select all

18/01/09 16:25:43  Connected to mail server and found 1 messages waiting.
18/01/09 16:25:43  Parsing message 1 of 1 for actions...
18/01/09 16:25:43  Not actioned.
18/01/09 16:25:43  Closed connection (1).
18/01/09 16:26:13  Connected to mail server and found 1 messages waiting.
18/01/09 16:26:13  Parsing message 1 of 1 for actions...
18/01/09 16:26:13  Not actioned.
18/01/09 16:26:13  Closed connection (1).
18/01/09 16:26:43  Connected to mail server and found 1 messages waiting.
18/01/09 16:26:43  Parsing message 1 of 1 for actions...
18/01/09 16:26:43  Not actioned.
18/01/09 16:26:43  Closed connection (1).

[Over half an hour later]

18/01/09 17:01:06  Connected to mail server and found 1 messages waiting.
18/01/09 17:01:06  Parsing message 1 of 1 for actions...
18/01/09 17:01:06  Not actioned.
18/01/09 17:01:06  Closed connection (1).
18/01/09 17:01:36  Connected to mail server and found 1 messages waiting.
18/01/09 17:01:36  Parsing message 1 of 1 for actions...
18/01/09 17:01:36  Not actioned.
18/01/09 17:01:36  Closed connection (1).
18/01/09 17:02:06  Connected to mail server and found 1 messages waiting.
18/01/09 17:02:07  Parsing message 1 of 1 for actions...
18/01/09 17:02:07  Not actioned.
18/01/09 17:02:07  Closed connection (1).
It seems to be more stable now. Don't know if there's anything else you
can do? That's why I suggest make the default timeout something like
15 instead of 5.

Posted: Mon Jan 19, 2009 8:48 am
by gnozal
PB wrote:It seems to be more stable now. Don't know if there's anything else you can do?
I don't know either.
PB wrote:That's why I suggest make the default timeout something like 15 instead of 5.
Ok, I will update the lib + help.

Posted: Mon Jan 19, 2009 11:35 am
by gnozal
Update (JAN 26th 2009)

Changes :
- default time out is now 15 s
- PurePOP3_ClosePOP3Connection() only closes connection if server answer to 'QUIT' was '+OK'.
- a quick fix for multipart/alternative messages without content transfer encoding
- some other fix for Lotus Domino generated messages

GetMessageTextInMemory() fails

Posted: Tue Jan 20, 2009 1:08 pm
by PB
Hi gnozal,

Been giving your lib a thorough workout lately. ;)

If I send a RichText email from my Yahoo Mail account to my home POP3
account, and then retrieve it successfully and use GetMessageTextInMemory()
on it, it doesn't always get the body as expected.

This is the body of such a Yahoo Mail that I sent:

Code: Select all

{{one two}}
And GetMessageTextInMemory() returns 24 chars that are NOT made up
of those. I'm using PeekS() to get the text, so maybe a null character is
wrecking it? How can I check? Anyway, here's some screenshots and info:

The RichText Yahoo mail in my normal POP3 account's Inbox:

Image

My app's Debug info and tooltip showing the faulty string which doesn't
contain any of the body of the email:

Image

I can send you the actual message source via PM if you like?

Posted: Tue Jan 20, 2009 1:33 pm
by gnozal
Hi PB,
it would be helpful if you could send me the traces ; see PurePOP3_Trace(#True) in the help.
POP3 is a real nightmare ... Almost every client encodes the same message a bit differently, and you have multipart, alternative, mixed, base 64 encoded stuff etc...
Btw, in your code you FreeMemory(b) and then you use MemorySize(b). I am not sure it is safe.

Posted: Tue Jan 20, 2009 1:43 pm
by PB
Here is the memory block in the viewer immediately after calling the
GetMessageTextInMemory() command on the mail. As you can see,
it doesn't contain the message body at all. :(

Image

> in your code you FreeMemory(b) and then you use MemorySize(b)

Yeah, that was just a mistake in the Debug lines. Ignore that. :oops:

> it would be helpful if you could send me the traces

Done; see your PM. :)