Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

FetchMail - Pop3 Retrieval and Archiving


  • Please log in to reply
5 replies to this topic
Dragonscloud
  • Members
  • 96 posts
  • Last active: Jul 21 2010 08:33 PM
  • Joined: 16 Jul 2005
This script provides a front-end GUI for the simplest aspects of Getmail, a command-line Pop3 utility. If getmail.exe is not in the working directory,
the user is given a download option to the working directory for convenience.

Setup is accomplished by entering the profile name, server, username, and password in the edit boxes and clicking "install.". Settings are saved in a .ini file.

Clicking the "fetch" button moves any existing files from the "Current" directory to the "Archive" folder for a cumulative backup. All emails on the server are then collected, renamed based on subject line and date, converted to .eml files, then placed in the Current folder.

The Gui Provides buttons for opening the storage folders.

With some tweaking, Getmail's other options can be utilized, but I wanted to keep it simple for now.

Updates:
7-30] Added a bit of support for multiple users. If the UserName field changes and mail is retrieved, that user is given its' own folders under Current and Archive directories. True profiling may be added if I get around to restructuring the GUI and altering the format of the .ini file.

7-31]-Added full support for profiles.
-Reorganized Gui code based on placement of controls.



IfNotExist, getmail.exe
  {
    MsgBox,1,File Missing,File needed: Getmail.exe `n Click OK to download   getmail.zip to this program's working directory.`n Extract Getmail.exe then   restart this program to Continue.
    IfMsgBox, Cancel
        ExitApp
    IfMsgBox, OK
        URLDownloadToFile, http://www.interlog.com/~tcharron/getmail.zip, Getmail.zip
    Run, %A_WorkingDir%
  }
IfNotExist, Current
    FileCreateDir, Current
IfNotExist, Archive,
    FileCreateDir, Archive
IfNotExist, fetchmail.ini
    IniWrite, DefaultUser|,fetchmail.ini, 0DDL, ProfileList
IniRead, GetProfileList, fetchmail.ini, 0DDL,ProfileList, %A_Space%
IniRead,GetProfile, fetchmail.ini, DefaultUser, ProfileName, Add Profile Name
IniRead,GetServer, fetchmail.ini, DefaultUser, Server, Add Server Name
IniRead,GetUserName, fetchmail.ini, DefaultUser, UserName, Add User Name
IniRead,GetPassword, fetchmail.ini, DefaultUser, Password,
Gui, Add, GroupBox, x5 y9 w160 h50 , Getmail
Gui, Add, Button, x15 y29 w60 h20 , &Install
Gui, Add, Button, x95 y29 w60 h20 gBFetch, &Fetch
Gui, Add, GroupBox, x5 y69 w160 h50 , View
Gui, Add, Button, x15 y89 w60 h20 gBViewCurrent, &Current
Gui, Add, Button, x95 y89 w60 h20 gBViewArchive, &Archive
Gui, Add, GroupBox, x6 y130 w160 h230, Settings
Gui, Add, DropDownList, Choose1 x16 y150 w140 vProfileList gDSelectProfile,%GetProfileList%
Gui, Add, Text, x16 y175 w140 h20 +Center, Profile
Gui, Add, Edit, x16 y190 w140 h20 vProfile, %GetProfile%
Gui, Add, Text, x16 y215 w140 h20 +Center, Server
Gui, Add, Edit, x16 y230 w140 h20 vServer, %GetServer%
Gui, Add, Text, x16 y255 w140 h20 +Center, UserName
Gui, Add, Edit, x16 y270 w140 h20 vUserName, %GetUserName%
Gui, Add, Text, x16 y295 w140 h20 +Center , Password
Gui, Add, Edit,Password x16 y310 w140 h20 vPassword, %GetPassword%
Gui, Add, Button,x16 y335 w70 h20 gBChangeDefault ,Set &Default
Gui, Add, Button,x85 y335 w70 h20 gBSubmitProfile ,Add &Profile
Gui, Show, x158 y75 Autosize, FetchMail
Return
BViewArchive:
  Gui, Submit, NoHide
  Run, Archive\%UserName%
Return
BChangeDefault:
  Gui, Submit, NoHide
  IniWrite,%Profile%,fetchmail.ini, DefaultUser, ProfileName
  IniWrite,%Server%, fetchmail.ini, DefaultUser,Server
  IniWrite,%UserName%, fetchmail.ini, DefaultUser,UserName
  IniWrite,%Password%, fetchmail.ini, DefaultUser, Password
Return

BViewCurrent:
  Gui, Submit, NoHide
  Run, Current\%UserName%
Return
BFetch:
  Gui, Submit, NoHide
  IfNotExist, Current\%UserName%
      FileCreateDir, Current\%UserName%
  IfNotExist, Archive\%UserName%
      FileCreateDir, Archive\%UserName%
  FileMove, Current\%UserName%\*.eml, Archive\%UserName%,1
  SetTitleMatchMode, 2
  Run, "getmail.exe" -u  %UserName% -domainstamp
  WinWait,getmail.exe
  WinWaitClose

  Loop, *.txt
    {
      Loop, Read, %A_LoopFileName%
        {
          If A_LoopReadLine Contains Subject:
              Subject = %A_LoopReadLine%
          If A_LoopReadLine Contains Date:
              Date = %A_LoopReadLine%
        }
      StringTrimLeft, Date, Date, 5
      StringTrimRight, Date, Date, 9
      StringReplace, Date, Date,:,,
      StringTrimLeft, Subject, Subject, 8
      StringReplace, Subject, Subject,:,,
      StringReplace, Subject, Subject,?,,
      StringReplace,Subject, Subject,*,,
      StringReplace, Subject, Subject,<,,
      StringReplace, Subject, Subject,>,,
      StringReplace, Subject, Subject,|,,
      StringReplace, Subject, Subject,",,
      StringReplace, Subject, Subject,/,,
      StringReplace, Subject, Subject,\,,
      FileMove, %A_LoopFileName%, Current\%UserName%\%Subject%%Date%.eml,1
    }
Return

BSubmitProfile:
  Gui, Submit, NoHide
  FileReadLine, CheckForDuplicate, fetchmail.ini, 2
  If CheckForDuplicate Contains %Profile%
      Gosub, ModifyProfile
  Else
    {
      IniWrite,%GetProfileList%|%Profile%, fetchmail.ini,0DDL,ProfileList
      IniRead, GetProfileList, fetchmail.ini, 0DDL, ProfileList
      GuiControl,,ProfileList,%Profile%
    }
  Gosub, ModifyProfile
Return

DSelectProfile:
  Gui, Submit, NoHide
  IniRead,GetProfile, fetchmail.ini, %ProfileList%, ProfileName, Add Profile Name
  IniRead,GetServer, fetchmail.ini, %ProfileList%, Server, Add Server Name
  IniRead,GetUserName, fetchmail.ini, %ProfileList%, UserName, Add User Name
  IniRead,GetPassword, fetchmail.ini, %ProfileList%, Password,
  GuiControl,,%Profile%,%ProfileList%
  GuiControl,,%Server%,%GetServer%
  GuiControl,,%UserName%,%GetUserName%
  GuiControl,,%Password%,%GetPassword%
Return
Install:
  Gui, Submit, NoHide
  IniWrite, %Profile%, fetchmail.ini, %Profile%, ProfileName
  IniWrite, %Server%, Fetchmail.ini,%Profile%, Server
  IniWrite, %UserName%, Fetchmail.ini, %Profile%, UserName
  IniWrite, %Password%, Fetchmail.ini, %Profile%, Password
  Run, "getmail.exe" -install %Server% %Profile% %Password%
  FileCreateDir, Archive\%UserName%
  FileCreateDir, Current\%UserName%
Return
ModifyProfile:
  IniWrite,%Profile%,fetchmail.ini, %Profile%, ProfileName
  IniWrite,%Server%, fetchmail.ini, %Profile%,Server
  IniWrite,%UserName%, fetchmail.ini, %Profile%,UserName
  IniWrite,%Password%, fetchmail.ini, %Profile%, Password
Return
GuiClose:
  ExitApp

“yields falsehood when preceded by its quotation” yields falsehood when preceded by its quotation.

toralf
  • Moderators
  • 4035 posts
  • Last active: Aug 20 2014 04:23 PM
  • Joined: 31 Jan 2005
Hi Dragonscloud,
Thanks for the credit, But please remove it. It is purely your code.

Two comments:
- Why do you use Reload? You can avoid it.
- Please use syntax indentation for your code. It helps to read the code.

Thanks for sharing. It is a very nice idea.
Ciao
toralf
 
I use the latest AHK version (1.1.15+)
Please ask questions in forum on ahkscript.org. Why?
For online reference please use these Docs.

Dragonscloud
  • Members
  • 96 posts
  • Last active: Jul 21 2010 08:33 PM
  • Joined: 16 Jul 2005

Hi Dragonscloud,
Thanks for the credit, But please remove it. It is purely your code.

Done, per your request.

Two comments:
- Why do you use Reload? You can avoid it.

I didn't know how until just a moment ago. The script has been edited.
If you know of a solution better than "gui, show," I'm open to suggestions.

- Please use syntax indentation for your code. It helps to read the code.
I'd be more than happy to follow the conventions for readability if I knew the specifics. Perhaps you can point me in the right direction?

Thanks for the feedback.
“yields falsehood when preceded by its quotation” yields falsehood when preceded by its quotation.

toralf
  • Moderators
  • 4035 posts
  • Last active: Aug 20 2014 04:23 PM
  • Joined: 31 Jan 2005
Hi,

Instead of
Gui, Submit
Gui Show

Please try
Gui, Submit, NoHide
Ciao
toralf
 
I use the latest AHK version (1.1.15+)
Please ask questions in forum on ahkscript.org. Why?
For online reference please use these Docs.

toralf
  • Moderators
  • 4035 posts
  • Last active: Aug 20 2014 04:23 PM
  • Joined: 31 Jan 2005

I'd be more than happy to follow the conventions for readability if I knew the specifics. Perhaps you can point me in the right direction?

Have a look at the script Auto-Syntax-Tidy
Ciao
toralf
 
I use the latest AHK version (1.1.15+)
Please ask questions in forum on ahkscript.org. Why?
For online reference please use these Docs.

Dragonscloud
  • Members
  • 96 posts
  • Last active: Jul 21 2010 08:33 PM
  • Joined: 16 Jul 2005

Hi,

Instead of
Gui, Submit
Gui Show

Please try
Gui, Submit, NoHide


:D Thanks, that's just what I was looking for.
I also ran the script through AutoSyntaxTidy.
“yields falsehood when preceded by its quotation” yields falsehood when preceded by its quotation.