Code: Select all
#NoEnv
#Persistent
SetBatchLines, -1
CoordMode, ToolTip, Screen
; Instantiate the event handler class.
EMail := new OutlookApplicationEvents()
return ; End of Auto-execute section.
Esc::
EMail.Quit()
return
^!l::Reload
; Basic Outlook events class. Can be connected to an Outlook Application object.
class OutlookApplicationEvents {
__New(olApp := "") {
; If nothing was passed to this method, then use the active instance of Outlook. This will throw an error if
; Outlook is not running.
if (olApp = "")
try olApp := ComObjActive("Outlook.Application")
If IsObject(olApp)
TrayTip, % "Outlook Eventhandler", % "COM-Connection established", 1
; Store Outlook application object for later use (optional).
this.olApp := olApp
; Connect Outlook Application object events to this instance.
ComObjConnect(this.olApp, this)
}
__Call(Event, Args*) {
msg := "--- >>>> " A_Hour ":" A_Min ":" A_Sec " - Event: " Event " <<<< "
if !IsFunc( this[Event] ) { ; If this event does not correspond to a method...
msg .= ": Event is not supported" ; Display the event name.
}
For idx, param in Args
{
;str .= idx ":`n"
If IsObject(param) {
For key, val in param
str .= "`t" key ": " val "`n"
} else {
str .= "`t" param "`n"
}
}
SciTEOutput(msg "`nArgs:`n" str)
}
ItemLoad() {
SciTEOutput("Event (Itemload): " this.olApp.CurrentItem.name)
t:= ""
For key, val in this
t.= key ": " val "`n"
SciTEOutput(t)
}
NewMail() {
;For key, val in this
; SciTEOutput("`t" key ": " (IsObject(val) ? " is object": val))
Subject := this.Subject
SciTEOutput("~" this.Body)
SciTEOutput("~" this.SendUsingAccount)
SciTEOutput("~" Subject)
attachments := this.attachments
Loop % Attachments.Count
{
thisattachment := attachments.Item(A_Index)
SciTEOutput("attachment: " thisattachment.DisplayName)
}
}
Send(Cancel) {
if InStr(Email.Body, "stupid") {
MsgBox The new company policy is to NOT call our customers "stupid".`nPlease rephrase your email.
return ComObject(0xB,0)
}
}
ExtractAttachment(folderName, EmailSubject, attachmentname, PathToSaveTo) {
attachmentname := "i)" attachmentname
olApp := ComObjActive("Outlook.Application")
outlooknamespace := olApp.GetNameSpace("MAPI")
folder := outlooknamespace.Folders(folderName)
Loop % folder.items.count {
email := folder.items.Item(A_Index)
if(InStr(email.Subject, EmailSubject)) {
attachments := email.Attachments
Loop % Attachments.Count {
thisattachment := attachments.Item(A_Index)
if RegExMatch(thisattachment.DisplayName , attachmentname ) {
Fullpath := pathtosaveto "\" thisattachment.DisplayName
thisattachment.SaveAsFile(FullPath)
return thisattachment.DisplayName ; disable this line and it will extract every attachments and same name attachment get renames,
}
}
}
}
msgbox, no email found Having Subject = %EmailSubject% `n specially having attachment with name = %attachmentname%
}
Quit() { ; Occurs when Outlook begins to close.
ComObjConnect(this.olApp) ; Disconnect application events.
ExitApp ; Exit this script.
}
}
SciTEOutput(Text:="", Clear=false, LineBreak=true, Exit=false) {
static SCI_GETLENGTH := 2006, SCI_GOTOPOS := 2025
try
SciObj := ComObjActive("SciTE4AHK.Application") ;get pointer to active SciTE window
catch
return ;if not return
; move Caret to end of output window
ControlSend, Scintilla2, {LControl Down}{End}{LControl Up} , % "ahk_id " SciObj.SciTEHandle
If Clear || (StrLen(Text) = 0) {
SendMessage, SciObj.Message(0x111, 420) ;If clear=true -> Clear output window
return
}
SciObj.Output(Text (LineBreak ? "`r`n": "")) ;send text to SciTE output pane
If Exit {
MsgBox, 36, Exit App?, Exit Application? ;If Exit=1 ask if want to exit application
IfMsgBox,Yes, ExitApp ;If Msgbox=yes then Exit the appliciation
}
}
Allerdings habe ich keine Ahnung wie ich erkennen kann ob die eingetroffene EMail einen Anhang enthält.
Code: Select all
NewMail() {
For key, val in this
SciTEOutput("`t" key ": " (IsObject(val) ? " is object": val))
....
Dieser enthält olApp, logischerweise ein Objekt und die Daten SendUsingAccount, Body, Subject, To. Mehr allerdings nicht.
Und an diesem Punkt komme ich nicht weiter.
Ich könnte jetzt das Event (Aufruf der Funktion) als Trigger nutzen und jedesmal das Outlook.Folders-Objekt durchsuchen.
Nun erhoffe ich mir von Euch allerdings mehr Einblicke in das COM-Konzept von Outlook. Ich hoffe das wirkt nicht zu frech auf Euch.
Und da ich mich selbst nicht als allzu frech empfinde, mache ich die Beantwortung meiner Frage noch umfangreicher.
Die funktionierende Ausgabe der key:value Daten im Event-Objekt hat mich auf die Idee gebracht, dann auch noch für alle Events bei __Call(Event, Args*) { die erhaltenden variadischen Argumente ausgeben zu lassen.
Outlook übergibt hier in manchen Fällen auch Objekte, deren Namen ich allerdings nicht ermitteln kann.
Deshalb habe ich versucht zumindestens die key:value's zu ermitteln.
Allerdings ist das dann völlig ergebnislos geblieben. Da hab ich wohl etwas nicht verstanden.
Code: Select all
For idx, param in Args
{
If IsObject(param) {
For key, val in param
str .= "`t" key ": " val "`n"
} else {
str .= "`t" param "`n"
}
}