Mine is a little complete app that checks my pop3 every 5 minutes and tell me if i have new mail, also let me delete unwanted mail.
It can be improved a lot because was coded in a few hours just like an excercise.
You need to have a "\Mail" folder in the same path.
Just Put your servername, username, and password in places where are required.
Code: Select all
If InitNetwork() = 0
MessageRequester("Error", "Can't initialize the network !", 0)
End
EndIf
Global ConnectionID.l
Global Conectado.l
Global *Buffer.l
Global eol$
Global Dir$
Dir$ = Space(500)
GetCurrentDirectory_(500,@Dir$)
eol$ = Chr(13)+Chr(10)
*Buffer = AllocateMemory(0, 10000)
Procedure CleanMails()
If ExamineDirectory(0,Dir$ + "\Mail\" , "*.*")
Repeat
FileType = NextDirectoryEntry()
If FileType
FileName$ = DirectoryEntryName()
If FileType = 1
DeleteFile(Dir$ + "\Mail\" + FileName$)
EndIf
EndIf
Until FileType = 0
EndIf
EndProcedure
Procedure ComparaMails(Mail.s, Content.s)
If ExamineDirectory(0,Dir$ + "\Mail\" , "*.*")
Repeat
FileType = NextDirectoryEntry()
If FileType
FileName$ = DirectoryEntryName()
If FileType = 1
If FileName$ = Mail
If ReadFile(0,Dir$ + "\Mail\" + FileName$)
Contenido$ = Space(Lof())
ReadData(@Contenido$,Lof())
CloseFile(0)
If Contenido$ = Content
ProcedureReturn 1
EndIf
EndIf
EndIf
EndIf
EndIf
Until FileType = 0
ProcedureReturn 0
EndIf
EndProcedure
Procedure ChecaMail()
SysTrayIconToolTip(0, "Connecting...")
KillTimer_(WindowID(),0)
ClearGadgetItemList(1)
InitNetwork()
ConnectionID = OpenNetworkConnection("pop3.yourserver.com", 110)
If ConnectionID
Delay(5)
Repeat
Delay(10)
Result = NetworkClientEvent(ConnectionID)
Select Result
Case 2
Repeat
Delay(10)
RequestLength.l = ReceiveNetworkData(ConnectionID, *Buffer, 5000)
Until RequestLength.l > 3
Command$ = PeekS(*Buffer)
Var$ = Space(RequestLength)
PokeS(*Buffer,Var$)
If FindString(Command$,"+OK hello from popgate",0)
SendNetworkString(ConnectionID, "USER yourusername"+eol$)
ElseIf FindString(Command$,"+OK password required",0)
SendNetworkString(ConnectionID, "PASS yourpassword"+eol$)
ElseIf FindString(Command$,"+OK maildrop ready",0)
espacio = FindString(Command$," ",22) - 21
Cuanto$ = Mid(Command$,21,espacio)
Cuantos = Val(Cuanto$)
If Cuantos > 0
Cuanto = 1
SendNetworkString(ConnectionID, "TOP 1 0"+eol$)
Delay(150)
Else
SendNetworkString(ConnectionID, "QUIT"+eol$)
SysTrayIconToolTip(0, "You dont have new emails")
CloseNetworkConnection(ConnectionID)
Final = 1
EndIf
ElseIf FindString(Command$,"octets",0) ;And FindString(Command$,"MIME-Version",0)
Beep_(1000,1)
from = FindString(Command$,"From:",0) + 6
endfrom = FindString(Command$,eol$,from + 1) - from
From$ = Mid(Command$,from,endfrom)
subject = FindString(Command$,"Subject:",0) + 9
endsubject = FindString(Command$,eol$,subject + 1) - subject
Subject$ = Mid(Command$,subject,endsubject)
AddGadgetItem(1, Cuanto - 1, From$ + Chr(10) + Subject$)
File$ = From$
For i = 1 To 47
File$ = ReplaceString(File$,Chr(i),"",0)
Next i
For i = 58 To 64
File$ = ReplaceString(File$,Chr(i),"",0)
Next i
For i = 122 To 255
File$ = ReplaceString(File$,Chr(i),"",0)
Next i
If Len(File$) > 10
;File$ = Right(File$,10)
EndIf
File$ = File$ + ".txt"
If Cuanto < Cuantos
Cuanto = Cuanto + 1
Delay(10)
SetWindowText_(WindowID(),Str(Cuanto))
SysTrayIconToolTip(0, "Downloading " + Str(Cuanto) + " from " + Str(Cuantos))
SendNetworkString(ConnectionID, "TOP " + Str(Cuanto) + " 0"+eol$)
If ComparaMails(File$,Command$ ) = 0
Nuevo = 1
If OpenFile(0,Dir$ + "\Email\" + File$)
WriteString(Command$)
CloseFile(0)
EndIf
EndIf
Else
SendNetworkString(ConnectionID, "QUIT"+eol$)
If ComparaMails(File$,Command$ ) = 0
Nuevo = 1
If OpenFile(1,Dir$ + "\Mail\" + File$)
WriteString(Command$)
CloseFile(1)
Else
Beep_(1000,3)
EndIf
EndIf
If Nuevo
SysTrayIconToolTip(0, "You have " + Str(Cuantos) + " new emails")
HideWindow(0, 0)
Else
SysTrayIconToolTip(0, "You dont have new emails")
EndIf
CloseNetworkConnection(ConnectionID)
Final = 1
EndIf
EndIf
EndSelect
Until Final = 1
EndIf
SetTimer_(WindowID(),0,300000,@ChecaMail());180000
SysTrayIconToolTip(0, "Waiting...")
EndProcedure
Procedure DeleteMail(Cual)
ConnectionID = OpenNetworkConnection("pop.yourserver.com", 110)
If ConnectionID
Delay(5)
Repeat
Delay(10)
Result = NetworkClientEvent(ConnectionID)
Select Result
Case 2
Repeat
Delay(10)
RequestLength.l = ReceiveNetworkData(ConnectionID, *Buffer, 5000)
Until RequestLength.l > 3
Command$ = PeekS(*Buffer)
Var$ = Space(RequestLength)
PokeS(*Buffer,Var$)
If FindString(Command$,"+OK hello from popgate",0)
SendNetworkString(ConnectionID, "USER yourusername"+eol$)
ElseIf FindString(Command$,"+OK password required",0)
SendNetworkString(ConnectionID, "PASS yourpassword"+eol$)
ElseIf FindString(Command$,"marked deleted",0)
SysTrayIconToolTip(0,Str(ii+1) + " e mail deleted")
SendNetworkString(ConnectionID, "QUIT"+eol$)
ElseIf FindString(Command$,"+OK maildrop ready",0)
SendNetworkString(ConnectionID, "DELE " + Str(Cual) + " 0"+eol$)
ElseIf FindString(Command$,"-ERR",0)
SendNetworkString(ConnectionID, "QUIT"+eol$)
ElseIf FindString(Command$,"+OK server signing off",0)
CloseNetworkConnection(ConnectionID)
Final = 1
EndIf
EndSelect
Until Final = 1
Beep_(1555,10)
ProcedureReturn 1
Else
ProcedureReturn 2
EndIf
EndProcedure
#List = 1
#Check = 4
#Delete = 2
#Close = 3
If OpenWindow(0,100,150,450,230,#PB_Window_SystemMenu|#PB_Window_Invisible,"MailCheck")
CreateGadgetList(WindowID())
ListIconGadget(#List,10,10,430,180,"From",250,#PB_ListIcon_MultiSelect|#PB_ListIcon_AlwaysShowSelection)
AddGadgetColumn(1, 1, "Subject", 150)
ButtonGadget(#Check,190,200,50,25,"Check")
ButtonGadget(#Delete,290,200,50,25,"Delete")
ButtonGadget(#Close,390,200,50,25,"Minimize",#PB_Button_Default)
AddSysTrayIcon(0, WindowID(), LoadImage(0,"Windows 98-Mi PC.ico"))
SysTrayIconToolTip(0, "PopUp Mail Checker" + Chr(13) + Chr(10) + "ok")
CleanMails()
SetTimer_(WindowID(),0,1,@ChecaMail())
Repeat
EventID=WaitWindowEvent()
Delay(10)
Select EventID
Case #PB_EventGadget
Select EventGadgetID()
Case #Check
KillTimer_(WindowID(),0)
SetTimer_(WindowID(),0,1,@ChecaMail())
SysTrayIconToolTip(0, "Checking...")
Case #Close
HideWindow(0, 1)
Case #Delete
KillTimer_(WindowID(),0)
SysTrayIconToolTip(0, "Deleting...")
For i = 0 To CountGadgetItems(1)
WindowEvent()
ii = CountGadgetItems(1) - i
WindowEvent()
If GetGadgetItemState(1, ii) <> 0
If DeleteMail(ii + 1) = 1
RemoveGadgetItem(1, ii)
WindowEvent()
Delay(100)
EndIf
EndIf
Next i
SetTimer_(WindowID(),0,180000,@ChecaMail())
WindowEvent()
Beep_(1777,50)
EndSelect
Case #PB_Event_SysTray
HideWindow(0, 0)
EndSelect
Until EventID=#PB_EventCloseWindow
EndIf
RemoveSysTrayIcon(0)
CloseNetworkConnection(ConnectionID)
KillTimer_(WindowID(),0)
CleanMails()
End