Hello all,
Does anyone have a suggestion for best way for PurePOP3 to recover from an interrupted Internet connection?
I have a small program (pasted at end of this post) with a button that calls a function, CheckMail() which then calls PurePOP3_OpenPop3Connection().
Things work very well so long as my Internet connection is not interrupted, in fact this problem only seems to arise
if the Internet is blocked After a successful connection (Scenario 1, described below). The issue seems to
occur after successfully connecting (Scenario 2).
Scenario #1, successful recovery from bad Internet connection Before connecting:
When the Internet is blocked and I click Check Mail, PurePOP3_OpenPop3Connection() naturally fails to
connect, returning the appropriate error codes, -2 for "no connection" in this case.
Once the Internet connection is established, the app recovers recover nicely and I can then click the Check Email
button and then requesters come up, telling me about the email that is waiting for me on the server. Success!
- - -
Scenario #2, Unsuccessful Recovery from Disrupted Internet connection After initially connecting successfully:
Synopsis: With a good Internet connection, run the app and click Check Email. Then, after a requester / notifier comes up, block the Internet connection. Now the app doesn't seem to recover.
If the Internet connection is interrupted After PurePOP3_OpenPop3Connection() has successfully established a
connection, this little app never recovers once I restore the Internet connection.
With a good Internet connection, I click the Check Email and start to get requesters telling me about each email
on the server.
(So far so good, but here's where things get a little more interesting.)
If the Internet is then disconnected After clicking Check Email (successfully connecting and with one of the
message requesters still up), that is when the app gets into some kind of mode that so far I haven't figured out
how to recover from, (except by closing the app and re-running it).
This happens regardless of how the Internet is blocked (either through software like ZoneAlarm or by physically
unplugging the RJ45 cable)!
I've added a couple of "rcovery buttons", one which calls PurePOP3_ClosePOP3Connection() and another
which calls PurePOP3_Noop() however so far neither of these has helped.
When I shut the app down, and restart it, I click Check Email and PurePOP3_OpenPOP3Connection(...)
connects just fine and is able to connect once again to the server, so I have little reason to suspect the server is
causing this problem.
It seems something in my app or the PurePOP3 library needs to be reset somehow.
Is there a certain sequence of calls I should be making to restore PurePOP3_OpenPOP3Connection() 's ability
to connect?
Thank you very much,
Roark
Code: Select all
; PureBasic Visual Designer v3.95 build 1485 (PB4Code)
;- Window Constants
Enumeration
#Window1
EndEnumeration
;- Gadget Constants
;
Enumeration
#FrameEmailAccounts
#LabelAddInPOP
#InPOP
#LabelAddUsername
#Username
#LabelAddEmailAddress
#LabelAddDisplayName
#EmailAddress
#DisplayName
#LabelAddPassword
#Password
#CheckEmail
#Disconnect
#ServerReset
EndEnumeration
Procedure Open_Window1()
If OpenWindow(#Window1, 170, 89, 806, 554, "Spf -- Spam Protection Factor", #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_TitleBar | #PB_Window_ScreenCentered )
Frame3DGadget(#FrameEmailAccounts, 8, 8, 760, 500, "")
TextGadget(#LabelAddInPOP, 28, 138, 110, 16, "In (POP)", #PB_Text_Center)
StringGadget(#InPOP, 28, 158, 110, 20, "")
TextGadget(#LabelAddUsername, 168, 138, 90, 16, "Username", #PB_Text_Center)
StringGadget(#Username, 153, 158, 125, 20, "")
; TextGadget(#LabelAddEmailAddress, 318, 138, 90, 16, "Email Address", #PB_Text_Center)
; StringGadget(#EmailAddress, 283, 158, 160, 20, "")
TextGadget(#LabelAddPassword, 618, 138, 90, 20, "Password", #PB_Text_Right)
StringGadget(#Password, 598, 158, 140, 20, "", #PB_String_Password)
ButtonGadget(#CheckEmail,638,208,100,40,"Check Email")
ButtonGadget(#Disconnect, 638, 278, 100, 40, "Disconnect")
ButtonGadget(#ServerReset, 638, 328, 100, 40, "Reset Server")
EndIf
EndProcedure
Global w1
Procedure message(title.s,message.s)
ProcedureReturn MessageRequester(title,message,#PB_MessageRequester_Ok)
EndProcedure
Procedure ask(title.s,message.s,flags)
ProcedureReturn MessageRequester(title,message,flags)
EndProcedure
Procedure warn(msg.s)
ProcedureReturn message(AppName$ + " :: Warning",msg)
EndProcedure
;-
Procedure LoadConfiguration()
tempDir$ = GetTemporaryDirectory()
f = ReadFile(#PB_Any,tempdir$+"config_delete")
If f
SetGadgetText(#InPOP,ReadString(f))
SetGadgetText(#Username,ReadString(f))
; SetGadgetText(#EmailAddress,ReadString(f))
SetGadgetText(#Password,ReadString(f))
CloseFile(f)
EndIf
EndProcedure
Procedure SaveConfiguration()
tempDir$ = GetTemporaryDirectory()
f = CreateFile(#PB_Any,tempDir$+"config_delete")
If f
WriteStringN(f,GetGadgetText(#InPOP))
WriteStringN(f,GetGadgetText(#Username))
; WriteStringN(f,GetGadgetText(#EmailAddress))
WriteStringN(f,GetGadgetText(#Password))
CloseFile(f)
EndIf
EndProcedure
;-
Procedure CheckEmail()
failedToConnect = #False
If checkingEmail
warn("already checking email...")
ProcedureReturn
EndIf
checkingEmail = #True ;now busy!
port = 110
server$ = GetGadgetText(#InPOP)
username$ = GetGadgetText(#Username)
password$ = GetGadgetText(#Password)
If PurePOP3_OpenPOP3Connection(server$, port, username$, password$) <> #PurePOP3_Ok
;Connection Error, Seems to recover just fine when the connection fails here, but see 6 lines down...
failedToConnect = #True
Else
mCount = PurePOP3_CountMessages()
If mCount
For i = 1 To mCount
mNumber = i
If PurePOP3_RetrieveMessage(i) < 0
;Connection (disruption) Error, Never seems to recover when the connection fails here...
Break ;out of For loop...
Else
;no error, show message info to user...
info$ = PurePOP3_GetMessageInfo()
date$ = StringField(info$,1,Chr(9))
date$ = Right(date$,Len(date$)-Len("Delivery-date:"))
subject$ = StringField(info$,2,Chr(9))
subject$ = Right(subject$,Len(subject$)-Len("Subject:"))
from$ = StringField(info$,3,Chr(9))
from$ = Right(from$,Len(from$)-Len("From:"))
message("Email","from="+from$+", subject="+subject$)
EndIf ;PurePOP3_RetrieveMessage(i)
Next ;i = 1 to mCount...
EndIf; mCount
If failedToConnect = #False
;no errors
PurePOP3_ClosePOP3Connection()
EndIf
EndIf ;PurePOP3_OpenPOP3Connection(Server, Port, User, Pwd) = #PurePOP3_Ok
checkingEmail = #False ;finished!
EndProcedure
;-
;- FUN STARTS HERE !!!
checkingEmail = #False
AppName$ = "Test POP3"
w1 = Open_Window1()
LoadConfiguration()
;- EVENT LOOP
Repeat
Event = WaitWindowEvent()
WindowID = EventWindow()
GadgetID = EventGadget()
EventType = EventType()
;-LEFT MOUSE CLICK !!
If Event = #PB_Event_Gadget And (EventType = PB_EventType_LeftClick) ;left click...
Select GadgetID
Case #CheckEmail:
If checkingEmail = #False
CheckEmail()
EndIf
Case #Disconnect:
PurePOP3_ClosePOP3Connection() ;hoping this might help restore things...
Case #ServerReset:
PurePOP3_Reset() ;PurePOP3_Noop() ;hoping either of these might help restore things...
EndSelect ;GadgetID
EndIf ;left click...
Until (Event = #PB_Event_CloseWindow) ;End of the event loop
SaveConfiguration()
End