# Outlook Web Access 2003 # supports attachments # does not support sending of mail # # @Requires: 1.1 beta3 # @Version: 0.7.1 # german texts (with MrPostman 1.2.2+) # @Version: 0.7 # (martin.vlcek) Log in using basic authorization # @Version: 0.6 # Attachments of messages an ID containing [ or ] can now be downloaded # @Version: 0.5 # Able to parse messages with "undisclosed recipients" # @Version: 0.4 # Multiple mailaddresses are now separated by commas and newlines instead of semicolons. # @Version: 0.3.1 # ordering of options in configuration dialog # allow multiple extensions # use generic default values for settings # @Version: 0.3 # header parsing does not fail when return address is specified # messages with an ID containing [ or ] can now be downloaded # @Version: 0.2 # Allow Multiple pages # remove hardcoded https://webmail.ua.ac.be # @Version: 0.1 # initial version sub getInfo local(info) info.name = "outlookWA 2003" info.authors[0] = "Steven.Aerts " info.version = "0.7" info.updateService = "" info.documentationLink = "" info.options["extension"].value = "@mycompany.com" info.options["extension"].label = "Mail Extensions" info.options["extension"].description = "Extensions (include the @!) separated by ','" info.options["extension"].order = 1 info.options["isHttp"].value = false info.options["isHttp"].label = "Use HTTP" info.options["isHttp"].description = "Use HTTP rather than HTTPS for sign on" info.options["isHttp"].order = 2 info.options["host"].value = "webmail.mycompany.com" info.options["host"].label = "Server Name" info.options["host"].description = "Set to the server name, which you would access for the mail extension" info.options["host"].order = 3 info.options["locale"].value = "de" info.options["locale"].label = "Locale" info.options["locale"].description = "Locale, e.g. 'de' (German), 'en' (English)" info.options["locale"].order = 4 info.options["dateFormat"].value = "dd/MM/yyyy HH:mm" info.options["dateFormat"].label = "Date Format" info.options["dateFormat"].description = "Format of the date in Java SimpleDateFormat syntax" info.options["dateFormat"].order = 5 #--- german texts info.options["extension"].de.label = "E-Mail-Endungen" info.options["extension"].de.description = "E-Mail-Endungen (mit @) getrennt durch ','" info.options["isHttp"].de.label = "HTTP verwenden" info.options["isHttp"].de.description = "HTTP anstatt HTTPS verwenden" info.options["host"].de.label = "Server-Name" info.options["host"].de.description = "Der Name des Servers, der die E-Mails mittels OWA bereitstellt" info.options["locale"].de.label = "Sprache" info.options["locale"].de.description = "Sprache der OWA-Installation, z.B. 'de' (Deutsch), 'en' (Sprache)" info.options["dateFormat"].de.label = "Datumsformat" info.options["dateFormat"].de.description = "Format des Datums in Java SimpleDateFormat-Syntax (siehe Hilfe)" return info end sub getExtensions # more fault tolerant in regard to separators than specified in description return split(info.options["extension"].value,"[\s,;]+") end sub login(username,password) local(found,domain,user,mailext,pattern_mainframe) found,domain,user,mailext = match(username,"([^\\\]+)\\\(.+)@(.*)") # sometimes no domain is required if (!found) found,user,mailext = match(username,"(.+)@(.*)") domain = "" end failif(!found,"Invalid user name - must be \"auth-domain\\username@mail-domain\" or \"username@mail-domain\"!") baseurl = iif(info.options["isHttp"].value,"http://","https://") & info.options["host"].value setbaseurl(baseurl) size.locale = info.options["locale"].value size.unit = map("B",1,"KB",1024,"MB",1024*1024,"GB",1024*1024*1024) date.locale = info.options["locale"].value date.format = info.options["dateFormat"].value desturl = baseurl & "/exchange/" params = map("destination",desturl, "username", iif(domain=="",user,domain & "\\" & user), "password", password) status, page = post("/exchweb/bin/auth/owaauth.dll", params) if (status != 200) # sometimes log in is by accessing the home page and basic authorization addcredentials(iif(domain=="",user,domain&"\\"&user),password) status, page = get(baseurl) failif(status != 200, "Error logging in: http return code " & status) end return page,user end sub loginForReceive(username,password) local(url,status,page,found,pattern_msgframe,pattern_msgline,user,pagemsgs,currentPage,nrOfPages) page,user = login(username,password) pattern_msgframe = "\"([^\?\"]+)/\?Cmd=contents\"" setbaseurl(iif(info.options["isHttp"].value,"http://","https://") & info.options["host"].value & "/" & "exchange/" & user & "/") found,postbox=match(page,pattern_msgframe) url = postbox & "/?Cmd=contents" status,page = get(url) failif(status!=200,"Error retrieving message list frame!") found,nrOfPages = match(page,"name=\"Page\"(?:[^>]+>){3,3} [\w]+ (\d+)") nrOfPages = integer(nrOfPages) currentPage = 1 msgs=list() while (currentPage <= nrOfPages) if (currentPage > 1) status,page = get(url & "&Page=" & currentPage) failif(status!=200,"Error retrieving message list frame!") end pattern_msgline = "\"([^\\?\"]+/[^\"]+\\.EML\\?Cmd=open)\"><[^>]+>(?:)?(\\d+) (B|KB|MB|GB)<" pagemsgs=list() numfound,pagemsgs[].id,pagemsgs[].size.value,pagemsgs[].size.unit = matchall(page,pattern_msgline) msgs = join(msgs, pagemsgs) currentPage = currentPage + 1 end return true end sub receive(msg) local(found,status,page,from,to,cc,attachpat,i) status,page = get(replaceall(replaceall(msg.id,"\\[","%5B"), "\\]", "%5D")) msg.mimetype = "text/html" #--Parse header pattern_header = "\"idReadMessageHeaderTbl\"(?:>[^<]*<[^>]*){11}>([^<]+)(?:(?:[^<]*(?:]*>){3} [a-zA-Z]+([^<]+)<(?:[^>]*>[^<]*<){12}[^>]*> ((?:[^<]*(?:]*(?:>[^<]*<[^>]*){11}> ((?:[^<]*(?:]*>[^<]*<){11}[^>]*> ([^<]*)" found,from,msg.date,to,cc,msg.subject = match(page,pattern_header) msg.from = replaceall(replaceall(from,"\\[","<"), "\\]", ">") msg.to = extractMail(to) msg.cc = extractMail(cc) msg.date = trim(msg.date) #--Parse body pattern_body="class=\"tblMsgBody\"[^>]*>[^<]*<[^>]*>[^<]*<[^>]*>(.*)(?:<[^>]*>[^<]*){3}<[^>]*name=\"ParentFolder\"" found,msg.text = match(page,pattern_body) msg.text = "" & msg.text & "" #--Parse attachements pattern_attach = "href=\"(https?://[^\"]+\\?attach=\d+)\"[^>]+><[^>]+>([^<(]+)" found,msg.attachments[].link,msg.attachments[].text = matchall(page, pattern_attach) i = 0 while (i < size(msg.attachments)) msg.attachments[i].link = replaceall(replaceall(msg.attachments[i].link,"\\[","%5B"), "\\]", "%5D") i = i + 1 end return msg end sub extractMail(html) local(mails, pattern_email, ret, numFound, mail) pattern_email = "title=\"([^@\"]+@[^\"]+)\"><[^>]+>([^<]+)" numFound, mails[].address, mails[].title = matchall(html, pattern_email) ret = "" foreach(mails, mail) ret = ret & mail.title & " <" & mail.address & ">,\n " end if (ret != "") numFound, ret = match(ret, "(.*),\n ") end return ret end sub delete(msgs) local(msg, status, page) foreach(msgs, msg) status,page = post(msg.id, map("MsgID", "/" & replaceall(msg.id, "\?.*", ""), "Cmd", "delete")) end return true end sub logout get("?Cmd=logoff") return true end