regex - Why does this regular expression test give different results for what should be the same body text? -


here's pertinent code, giving different results on regular expression test message body depending on whether launch using testlaunchurl or message passed outlook when incoming message arrives:

public sub openlinksmessage(olmail outlook.mailitem)   dim reg1 regexp  dim allmatches matchcollection  dim m match  dim strurl string  dim retcode long  set reg1 = new regexp  reg1  .pattern = "(https?[:]//([0-9a-z=\?:/\.&-^!#$;_])*)"  .global = true  .ignorecase = true end  playthesound "speech on.wav"  retcode = reg1.test(olmail.body) msgbox "the retcode reg1.test(olmail.body) equals" + str(retcode) ' if regular expression test urls in message body finds 1 or more if retcode        playthesound "chimes.wav" '      use regex return instances match allmatches group        set allmatches = reg1.execute(olmail.body)        each m in allmatches                strurl = m.submatches(0) '              don't activate urls unsubscribing; skip them                if instr(1, strurl, "unsubscribe") goto nexturl '              if url ends > being enclosed in darts, strip > off                if right(strurl, 1) = ">" strurl = left(strurl, len(strurl) - 1) '              url activate accept must contain both of substrings in if statement                playthesound "tada.wav"                if instr(1, strurl, ".com")                      playthesound "trainwhistle.wav" '                    activate link accept job                      retcode = shellexecute(0, "open", strurl)                      set reg1 = nothing                      exit sub                end if  nexturl:    next  end if  set reg1 = nothing  end sub  private sub testlaunchurl()     dim curritem mailitem     set curritem = activeexplorer.selection(1)     openlinksmessage curritem end sub 

the test if reg1.test(olmail.body) returns 0 when invoked outlook rule on incoming message , returns -1 when use debugger trigger for same message inbox.

the code acting though has null message body when triggered outlook rule versus having message body when kicked off me same message once it's in inbox.

i flummoxed, can't understand how 1 , same message, 1 , same body, can give 2 different results depending on hands message subroutine.

additional debugging information: since issue appears surround value of body of message, added following code, examines htmlbody well:

if isnull(olmail.body)      msgbox "the message body null!!" else      msgbox "body:  " + "|" + olmail.body + "|" end if  if isnull(olmail.htmlbody)      msgbox "the message htmlbody null!!" else      msgbox "body:  " + "|" + olmail.htmlbody + "|" end if 

when script triggered outlook rule on message content, , content, "http://britishtoolworks.com", when arrives these 2 message boxes:

[i being forbidden post images reason. these show absolutely nothing between 2 pipe characters body , text, nothing url in it, htmlbody]

while these message boxes if trigger script via testlaunchurl after that same message sitting in inbox:

[shows actual expected content. forbidden posting more images.]

if can explain discrepancy, please do.

here code works. it's clear .body member of olmail not available until sort of behind scenes processing has had time occur , if don't wait long enough won't there when go test using it. focus on public sub openlinksmessage problem had been occurring.

the major (and only) change allowed expected processing of olmail.body take place, apparently, addition of line of code: set inspectmail = olmail.getinspector.currentitem. time takes set statement run allows .body become available on olmail parameter that's passed in outlook rule. what's interesting if display inspectmail.body after set statement shows empty, olmail.body used to.

option explicit  private declare function shellexecute _   lib "shell32.dll" alias "shellexecutea" ( _   byval hwnd long, _   byval operation string, _   byval filename string, _   optional byval parameters string, _   optional byval directory string, _   optional byval windowstyle long = vbminimizedfocus _   ) long    public sub openlinksmessage(olmail outlook.mailitem)   dim inspectmail outlook.mailitem  dim reg1 regexp  dim allmatches matchcollection  dim m match  dim strurl string  dim snaggedbody string  dim retcode long  ' purpose of following set statement strictly "burn time" .body member of ' olmail available time needed below.  without statement .body consistently ' showing empty.  what's interesting if use msgbox display inspectmail.body after ' set statement shows empty. set inspectmail = olmail.getinspector.currentitem  set reg1 = new regexp  reg1  .pattern = "(https?[:]//([0-9a-z=\?:/\.&-^!#$;_])*)"  .global = true  .ignorecase = true end  retcode = reg1.test(olmail.body) ' if regular expression test urls in message body finds 1 or more if retcode '      use regex return instances match allmatches group        set allmatches = reg1.execute(olmail.body)        each m in allmatches                strurl = m.submatches(0) '              don't activate urls unsubscribing; skip them                if instr(1, strurl, "unsubscribe") goto nexturl '              if url ends > being enclosed in darts, strip > off                if right(strurl, 1) = ">" strurl = left(strurl, len(strurl) - 1) '              url activate accept must contain both of substrings in if statement                if instr(1, strurl, ".com") '                    activate link accept job                      retcode = shellexecute(0, "open", strurl)                      set inspectmail = nothing                      set reg1 = nothing                      set allmatches = nothing                      set m = nothing                      exit sub                end if  nexturl:    next  end if  set inspectmail = nothing set reg1 = nothing set allmatches = nothing set m = nothing  end sub 

special niton patience , assistance on other questions formed basis one. led me solution.

addendum: individual assisting me elsewhere brought deserves noting here, think she's got right. using gmail via imap access download messages. appears happening once header information populated mailitem object, outlook rule being triggered. rest of members of object, including .body, appear being populated asynchronously behind scenes. speed of processing in script versus speed of population processing can lead situations script triggered header information , gets point accesses .body before it's been populated outlook itself. what's interesting when occurred, , of time until solution found, .body not considered null. isnull test never passed, content when printed nothing, in absolutely nothing between 2 pipe characters used delimiters. "nothing takes characters" not null?

clearly whole mailitem passed not pass "is nothing" test, , not think test individual member of object "is nothing."

for myself, consider buggy. before mailitem object ever handed off script processing logical presumption members of object can prepopulated prepopulated outlook before handoff. doesn't appear happening way, , under outlook 2010 on machine , outlook 2016 on another. if member has not yet been populated should have null value, should initialized prior population process taking place.


Comments

Popular posts from this blog

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

python Tkinter Capturing keyboard events save as one single string -

sql server - Why does Linq-to-SQL add unnecessary COUNT()? -