home *** CD-ROM | disk | FTP | other *** search
EPOC OPL Source | 2000-10-05 | 15.1 KB | 589 lines |
-
-
- REM Macro SaveMail (for Epoc Release 3)
-
- REM To be used with Macro5 (from v2.37)
- REM and a Psion S5 or Geofox + MsgSuite Email (v1.52)
- REM by S.Alisi - sergioalisi@geocities.com
- REM http://www.geocities.com/siliconvalley/bridge/1492
-
- INCLUDE "Systinfo.oxh"
-
- CONST AppName$="SaveMail"
- CONST AppVersion$=" v2.51 ER3"
- CONST DataUID&=&10000086
- CONST WordUID&=&1000007F
- CONST EmailUID&=&10000162
- CONST IniFile$="C:\System\SaveMail.ini"
- CONST SourceBoxName$="SaveMail.box"
-
- PROC Main:
- GLOBAL Email$(255),Data$(255)
- GLOBAL EmailRSC$(255),DataRSC$(255)
- GLOBAL MultiBox%,UserDialog%,DateFormat&,MacroNew%
- GLOBAL TotMsg&,NumMsg%,NoSubj%,DelMsg%,PasteToWord%,Skip%,TotSkip%
- GLOBAL Date$(30),From$(250),To$(250)
- GLOBAL CC$(250),BCC$(250),Subject$(250),Body$(250)
-
- Macro5Test:
- TotMsg&=1 :NumMsg%=1
- if IniSetup%: :return :endif
- if StartEmail%: :return :endif
- GetFocus:
- if MultiBox%
- if MultiBoxProc%:(1) :return :endif
- endif
- if UserDialog%
- if UserDialogProc%: :return :endif
- endif
- StartData:
- while NumMsg%<=TotMsg&
- CopyFromEmail:
- AdjustDate:
- AdjustFields:
- if PasteToWord%
- PasteToWord:
- else
- PasteToData:
- endif
- Report:
- endwh
- ENDP
-
- PROC Macro5Test:
- rem check if SaveMail is launched from Macro5 and as a macro
- onerr No_Macro::
- Email$=GetApp$:(EmailUID&)
- return
- No_Macro::
- onerr off
- alert(AppName$+AppVersion$,"To be launched as a macro with Macro5")
- stop
- ENDP
-
- PROC Macro5Ver:
- rem check which version of Macro5 is currently installed
- onerr Old_Macro::
- if LibVersion%: >=240
- MacroNew%=-1
- return
- endif
- Old_Macro::
- onerr off
- MacroNew%=0
- ENDP
-
- PROC IniSetup%:
- LOCAL s0%,s1%,s2%,s3%
- Start::
- if not exist (IniFile$)
- if Email$=""
- alert(AppName$+AppVersion$,"Sorry, I can't find Email.app")
- return -1
- endif
- EmailRSC$=Left$(Email$,Len(Email$)-3)+"rsc"
- Data$="*"+Right$(SourceBoxName$,4)
- DataRSC$="Z:\System\Apps\Data\Data.rsc" rem for Psion S5
- if not exist (DataRSC$)
- DataRSC$="Z:\System\Apps\Data\Data.ruk" rem for Geofox
- if not exist (DataRSC$)
- alert(AppName$+AppVersion$,"Sorry, I can't find Data.rsc/ruk")
- return -1
- endif
- endif
- rem the following line finds the Date Format of your machine
- SIDateFormat:(DateFormat&, s0%, s1%, s2%, s3%)
- dinit AppName$+" Setup (step 1 of 3) ..."
- dtext "","- your Email program is located on drive "+Left$(Email$,1)
- if DateFormat&=0
- dtext "","- your System Date format is ""mm"+chr$(s1%)+"dd"+chr$(s2%)+"yyyy"""
- elseif DateFormat&=1
- dtext "","- your System Date format is ""dd"+chr$(s1%)+"mm"+chr$(s2%)+"yyyy"""
- elseif DateFormat&=2
- dtext "","- your System Date format is ""yyyy"+chr$(s1%)+"mm"+chr$(s2%)+"dd"""
- endif
- Macro5Ver:
- if MacroNew%
- dtext "","- your Macro5 version is "+gen$(LibVersion%:/100,2)+"."+right$(gen$(LibVersion%:,4),2)
- else
- dtext "","- SaveMail is not tested with Macro5 versions prior to 2.37"
- endif
- dbuttons "Cancel",27,"Continue",13
- if dialog
- else
- IniResult%:(-1)
- return -1
- endif
- if MultiBoxProc%:(0)
- IniResult%:(-1)
- return -1
- endif
- dinit AppName$+" Setup (step 3 of 3)"
- dtext "","Each time you launch SaveMail you can ..."
- dcheckbox MultiBox%,"1) have a choice of the target Data file"
- dtext "","2) open a dialog window to automate the process"
- dcheckbox UserDialog%,"of storing/deleting a group of messages"
- dbuttons "Cancel",27,"Continue",13
- if dialog
- else
- IniResult%:(-1)
- return -1
- endif
- create IniFile$,a,Email$,EmailRSC$,Data$,DataRSC$,MultiBox%,UserDialog%,DateFormat&,MacroNew%
- a.Email$=Email$
- a.EmailRSC$=EmailRSC$
- a.Data$=Data$
- a.DataRSC$=DataRSC$
- a.MultiBox%=MultiBox%
- a.UserDialog%=UserDialog%
- a.DateFormat&=DateFormat&
- a.MacroNew%=MacroNew%
- append
- close
- IniResult%:(0)
- return -1
- else
- onerr Wrong_ini::
- open IniFile$,a,Email$,EmailRSC$,Data$,DataRSC$,MultiBox%,UserDialog%,DateFormat&,MacroNew%
- Email$=a.Email$
- EmailRSC$=a.EmailRSC$
- Data$=a.Data$
- DataRSC$=a.DataRSC$
- MultiBox%=a.MultiBox%
- UserDialog%=a.UserDialog%
- DateFormat&=a.DateFormat&
- MacroNew%=a.MacroNew%
- onerr off
- close
- endif
- return
- Wrong_ini::
- dinit AppName$+AppVersion$
- dtext "","Problem reading your SaveMail.ini file!"
- dtext "","Relaunch the Setup procedure?"
- dtext "","(you will loose your old settings)"
- dbuttons "Cancel",27,"Continue",13
- if dialog
- delete IniFile$
- goto Start::
- else
- return -1
- endif
- ENDP
-
- PROC IniResult%:(Type%)
- dinit AppName$+AppVersion$
- if Type%=-1 rem Setup aborted
- dtext "","Setup aborted..."
- dtext "","Relaunch the macro to complete"
- else rem Setup completed
- dtext "","Setup successfully completed..."
- dtext "","Now you can relaunch the macro"
- endif
- dbuttons "Continue",13
- dialog
- ENDP
-
- PROC StartEmail%:
- if MacroNew% rem Macro5 v2.40 or later installed
- busy "Opening Email, please wait ...",3,1
- if (FgApp%:(Email$))=1
- SendRscMenu:(EmailRSC$,4,&1008) rem switch to inbox ("Shift+Ctrl+i" for UK/USA)
- busy off
- GetFocus:
- alert("SaveMail has opened your Email program...","Now highlight an Inbox/Sent message and relaunch")
- return -1
- endif
- busy off
- else rem Macro5 v2.37 installed
- if (FgApp%:(Email$))=1
- GetFocus:
- giprint "Opening Email, please wait..."
- pause 90
- SendRscMenu:(EmailRSC$,4,&1008) rem switch to inbox ("Shift+Ctrl+i" for UK/USA)
- alert("SaveMail is opening Email program...","Highlight an Inbox/Sent message and relaunch")
- return -1
- endif
- endif
- ENDP
-
- PROC StartData:
- if MacroNew%=0 rem Macro5 v2.37 installed
- if (FgApp%:(Data$))=1
- GetFocus:
- giprint "Opening MailBox file, please wait..."
- pause 150
- endif
- FgApp%:(Email$)
- endif
- ENDP
-
- PROC MultiBoxProc%:(Type%)
- LOCAL Button%
- Start::
- if Type%=1 rem call from Main: procedure
- open IniFile$,a,Email$,EmailRSC$,Data$,DataRSC$,MultiBox%,UserDialog%,DateFormat&,MacroNew%
- Data$=a.Data$
- close
- dinit AppName$+AppVersion$,16
- dtext "","Select the location of your target Data file:"
- else rem call from IniSetup%: procedure
- dinit AppName$+" Setup (step 2 of 3) ..."
- dtext "","Select the location of your default Mailbox Data file:"
- endif
- dfile Data$,"File,Folder,Disk",128+8+32,0,0,DataUID&
- dtext "or choose ...","'New' to create a new Mailbox Data file"
- if Type%=1
- dtext "...","'Word' to store to a Psion Word file"
- dtext "...","'Setup' to relaunch the Setup procedure"
- dbuttons "New",%N,"Word",%W,"Setup",%S,"Cancel",27,"Continue",13
- else
- dbuttons "New",%N,"Cancel",27,"Continue",13
- endif
- Button%=dialog
- if Button%=13
- if Data$=""
- giprint "No target file selected"
- goto Start::
- endif
- elseif Button%=%s
- dinit AppName$+AppVersion$
- dtext "","Relaunch the Setup procedure?"
- dtext "","(you will loose the current settings)"
- dbuttons "Cancel",27,"Continue",13
- if dialog
- delete IniFile$
- if IniSetup%: :return -1 :endif
- else
- Data$=Right$(SourceBoxName$,4)
- goto Start::
- endif
- elseif Button%=%n
- if NewData%:(Type%) :goto Start:: :endif
- elseif Button%=%w
- if UseWord%: :goto Start:: :endif
- else
- return -1
- endif
- giprint "Target file is "+Data$
- pause 20
- ENDP
-
- PROC NewData%:(Type%)
- LOCAL SetDefault%,SourceBox$(255)
- SourceBox$=Macros$+SourceBoxName$
- if exist (SourceBox$)
- Data$=Right$(SourceBoxName$,4)
- dinit AppName$+AppVersion$
- dtext "","Create new MailBox Data file:"
- dfile Data$,"File,Folder,Disk",1+8
- if Type%=1
- dcheckbox SetDefault%,"Set as default"
- endif
- dbuttons "Cancel",27,"Continue",13
- if dialog
- copy SourceBox$,Data$
- if SetDefault% and Type%=1
- open IniFile$,a,Email$,EmailRSC$,Data$,DataRSC$,MultiBox%,UserDialog%,DateFormat&,MacroNew%
- a.Data$=Data$
- update
- close
- endif
- else
- return -1
- endif
- else
- giprint "NEW option not available"
- Data$=Right$(SourceBoxName$,4)
- return -1
- endif
- ENDP
-
- PROC UseWord%:
- LOCAL Button%
- Start::
- Data$=""
- dinit AppName$+AppVersion$
- dtext "","Select an existing Word file:"
- dfile Data$,"File,Folder,Disk",128+8+32,0,0,WordUID&
- dtext "or choose ...","'New' to create a new empty one"
- dbuttons "New",%N,"Cancel",27,"Continue",13
- Button%=dialog
- if Button%=13
- if Data$=""
- giprint "No target file selected"
- goto Start::
- else
- UseDoc%:("Word",Data$,3) rem open in background
- pause 20
- PasteToWord%=-1
- FgApp%:(Email$)
- GetFocus:
- endif
- elseif Button%=%n
- Data$=""
- dinit AppName$+AppVersion$
- dtext "","Create a new Word file:"
- dfile Data$,"File,Folder,Disk",1+8
- dbuttons "Cancel",27,"Continue",13
- if dialog
- UseDoc%:("Word",Data$,1) rem create new word file
- pause 20
- PasteToWord%=-1
- FgApp%:(Email$)
- GetFocus:
- else
- goto Start::
- endif
- else
- return -1
- endif
- ENDP
-
- PROC UserDialogProc%:
- LOCAL Button%
- dinit AppName$+AppVersion$
- dlong TotMsg&,"Number of messages to store",1,100
- dtext "","(starting from the highlighted one and going down)",$200
- dcheckbox NoSubj%,"Highlighted message has no subject"
- dtext "","(this option forces one single message storing)",$200
- dcheckbox DelMsg%,"Delete original message from Email"
- dtext "","(use with care, don't forget to save attachments...)",$200
- dbuttons "Cancel",27,"Continue",13
- if dialog
- if NoSubj%=-1 :TotMsg&=1 :endif
- else
- return -1
- endif
- if DelMsg%
- dinit "Please read carefully:"
- dtext "","You have chosen the ""Auto-Delete"" option, so:"
- dtext "","- DO NOT touch the keyboard and"
- dtext "","- DO NOT switch to any other program"
- dtext "","while the macro is running, as this could also lead to"
- dtext "","the loss of all your messages...",$200
- dtext "","A dialog box will inform you when the task has ended."
- dbuttons "Disable",%D,"Abort",27,"Continue",13
- Button%=dialog
- if Button%=%d
- DelMsg%=0
- giprint """Auto-Delete"" option disabled"
- pause 20
- elseif Button%<>13
- return -1
- endif
- endif
- ENDP
-
- PROC CopyFromEmail:
- LOCAL Dummy$(255)
- FgApp%:(Email$)
- SendKey:("Enter") rem open the message
- pause 50
- SendKey:("Fn+Up") rem move to DATE field
- SendRscMenu:(EmailRSC$,4,&125) rem select all ("Ctrl+a" for UK/USA)
- Date$=Copy$:
- if Date$="" rem message is a fax
- Skip%=-1
- TotSkip%=TotSkip%+1
- else
- SendKey:("Right,Down") rem move to FROM field
- SendRscMenu:(EmailRSC$,4,&125) rem select all
- Dummy$=Copy$:
- From$=Left$(Dummy$,250)
- SendKey:("Right,Down") rem move to TO field
- SendRscMenu:(EmailRSC$,4,&125) rem select all
- Dummy$=Copy$:
- To$=Left$(Dummy$,250)
- SendKey:("Right,Down") rem move to CC field
- SendRscMenu:(EmailRSC$,4,&125) rem select all
- Dummy$=Copy$:
- CC$=Left$(Dummy$,250)
- SendKey:("Right,Down") rem move to BCC field
- SendRscMenu:(EmailRSC$,4,&125) rem select all
- Dummy$=Copy$:
- BCC$=Left$(Dummy$,250)
- SendKey:("Right,Down") rem move to SUBJECT field
- SendRscMenu:(EmailRSC$,4,&125) rem select all
- Dummy$=Copy$:
- Subject$=Left$(Dummy$,250)
- SendKey:("Right,Fn+Down,Fn+Down") rem move to BODY field
- SendRscMenu:(EmailRSC$,4,&125) rem select all
- pause 20
- Dummy$=Copy$:
- Body$=Left$(Dummy$,250)
- SendKey:("Ctrl+c") rem this copies more than 255 chars
- endif
- SendKey:("Esc") rem close message
- pause 20
- ENDP
-
- PROC AdjustDate:
- rem the following code simply changes the
- rem DATE format used in Email (it depends on
- rem the System settings) to "yyyy/mm/dd hh:mm:ss"
- rem to have messages properly sorted by date
- LOCAL D$(4),M$(4),Y$(4)
- if Skip% :return :endif
- if DateFormat&=0 rem mm/dd/yyyy
- D$=Mid$(Date$,3,3)
- M$=Mid$(Date$,3,1)+Left$(Date$,2)
- Y$=Mid$(Date$,7,4)
- Date$=Right$(Date$,Len(Date$)-10)
- Date$=Y$+M$+D$+Date$
- elseif DateFormat&=1 rem dd/mm/yyyy
- D$=Left$(Date$,2)
- M$=Mid$(Date$,3,4)
- Y$=Mid$(Date$,7,4)
- Date$=Right$(Date$,Len(Date$)-10)
- Date$=Y$+M$+D$+Date$
- endif
- ENDP
-
- PROC AdjustFields:
- rem the following code rearranges the copied fields
- if Skip% :return :endif
- if NoSubj%
- Subject$="< no subject >"
- elseif Subject$="" or Subject$=Body$
- if BCC$="" or BCC$=Body$
- Subject$=CC$ :CC$="" :BCC$=""
- else
- Subject$=BCC$ :BCC$=""
- endif
- endif
- ENDP
-
- PROC PasteToData:
- FgApp%:(Data$)
- pause 20
- if NumMsg%=1 rem first message (or single message) to store
- SendRscMenu:(DataRSC$,4,&D) rem new entry ("Ctrl+Shift+n" for UK/USA)
- endif
- pause 20
- if Skip%<>-1
- SendKey:("Tab,Tab,Tab,Tab,Tab") rem move to BODY field
- SendKey:("Ctrl+v")
- pause 20
- SendKey:("Shift+Tab") rem move to CC/BCC field
- Paste:(CC$+Chr$(013)+BCC$) rem Chr$(013)=carriage return
- pause 20
- SendKey:("Shift+Tab") rem move to TO field
- if To$<>""
- Paste:(To$)
- endif
- pause 20
- SendKey:("Shift+Tab") rem move to FROM field
- Paste:(From$)
- pause 20
- SendKey:("Shift+Tab") rem move to DATE field
- Paste:(Date$)
- pause 20
- SendKey:("Shift+Tab") rem move to TITLE field
- if Subject$<>""
- Paste:(Subject$)
- endif
- pause 20
- SendRscMenu:(DataRSC$,4,&16) rem save message ("Ctrl+s" for UK/USA)
- endif
- if NumMsg%=TotMsg& rem last message (or single message) stored
- SendKey:("Esc") rem exit from "new entry mode"
- endif
- ENDP
-
- PROC PasteToWord:
- if Skip% :return :endif
- FgApp%:(Data$)
- pause 20
- SendRscMenu:(DataRSC$,4,&125) rem select all ("Ctrl+a" for UK/USA)
- SendKey:("Left,Enter")
- pause 20
- SendKey:("Ctrl+v")
- SendKey:("Enter")
- Paste:("************ end of message ************")
- SendKey:("Enter")
- SendRscMenu:(DataRSC$,4,&125) rem select all ("Ctrl+a" for UK/USA)
- SendKey:("Left,Enter")
- pause 20
- if Subject$<>""
- SendKey:("Enter")
- Paste:("* Subject: "+Subject$)
- pause 20
- endif
- SendKey:("Enter")
- Paste:("* Date: "+Date$)
- pause 20
- if Subject$<>""
- SendKey:("Enter")
- Paste:("* From: "+From$)
- pause 20
- endif
- if To$<>""
- SendKey:("Enter")
- Paste:("* To: "+To$)
- endif
- pause 20
- if CC$<>"" or BCC$<>""
- SendKey:("Enter")
- Paste:("* CC/BCC:"+CC$+Chr$(013)+BCC$) rem Chr$(013)=carriage return
- endif
- SendKey:("Enter")
- Paste:("* Body:")
- pause 20
- SendRscMenu:(DataRSC$,4,&125) rem select all ("Ctrl+a" for UK/USA)
- pause 10
- SendKey:("Left")
- ENDP
-
- PROC Report:
- GetFocus:
- if Len(To$)=250 or Len(CC$)=250 or Len(BCC$)=250
- dinit AppName$+" warning"
- dtext "","Check if the last saved message contains one of"
- dtext "","the To/CC/BCC fields exceeding the 250 chars limit"
- if TotMsg&>1
- NumMsg%=TotMsg&
- dtext "","The message storing procedure has been stopped..."
- endif
- if DelMsg%
- dtext "","The original message won't be deleted from Email"
- endif
- dbuttons "Continue",13
- dialog
- SendKey:("Esc") rem exit from "new entry mode" (if necessary)
- else
- if Skip%
- giprint "Message NOT stored"
- elseif TotMsg&>1 rem storing a group of messages
- giprint "Message "+gen$(NumMsg%,3)+" of "+gen$(TotMsg&,3)+" stored"
- else
- giprint "New message stored"
- endif
- pause 20
- FgApp%:(Email$)
- pause 20
- if DelMsg% and Skip%<>-1
- Sendkey:("Del") rem delete current message
- SendRscButton:("z:\System\Data\Eikon.rsc",308,2) rem confirm deletion with "Yes" button
- pause 20
- else
- SendKey:("Down") rem move down to the next message
- endif
- if NumMsg%=TotMsg& and (TotMsg&>1 or DelMsg% or Skip%) rem last message of a group
- GetFocus:
- dinit AppName$+AppVersion$
- if TotSkip%>0
- dtext "","Unable to store "+gen$(TotSkip%,3)+" message(s)",$200
- endif
- dtext "",gen$(TotMsg&-TotSkip%,3)+" message(s) successfully stored to:"
- dtext "",Data$
- dbuttons "Continue",13
- dialog
- endif
- endif
- NumMsg%=NumMsg%+1
- Skip%=0
- ENDP
-
-
-