Monday, July 26, 2021

#1 2021-06-14 07:37:13 am

bwill
Member
Registered: 2019-07-17
Posts: 8

Speed up script for getting mailboxes of Outlook

I've got a super old AppleScript to get the mailboxes of Outlook:

Applescript:

global AllFolders
   set AllFolders to {}
   global ContainerName
   set ContainerName to ""
   tell application "/Applications/Microsoft Outlook.app"
       set allMailFolders to get mail folders
       repeat with currentFolder in allMailFolders
           set FolderName to name of currentFolder
           set PathSoFar to ""
           if FolderName is not missing value and (container of currentFolder is not missing value or account of currentFolder is not missing value) then
               set ContainerName to ":::"
               set theContainer to currentFolder
               repeat while ContainerName is not ""
                   set ContainerName to ""
                   try
                       set theContainer to container of theContainer
                       set ContainerName to name of theContainer
                       if ContainerName is missing value then
                           set theAccount to account of theContainer
                           if theAccount is not missing value then
                               set AccountName to name of theAccount
                               set PathSoFar to (AccountName) & ":::" & PathSoFar
                           end if
                       else
                           set PathSoFar to (ContainerName) & ":::" & PathSoFar
                       end if
                   end try
               end repeat
               set end of AllFolders to {PathSoFar & ":::" & (FolderName)}
           end if
       end repeat
       return AllFolders
   end tell

The script works fine and for me it was never slow. Today I did some troubleshooting over Zoom for a user of my app. He has about 500 mailboxes and the script took over a minute to run. Does anyone have an idea how to speed up the script?


Filed under: Outlook

Offline

 

#2 2021-06-15 01:34:29 am

KniazidisR
Member
From:: Greece
Registered: 2019-03-03
Posts: 1954

Re: Speed up script for getting mailboxes of Outlook

One suggestion is: turn all if is not statements to if is statements, because there are faster. This way:

Applescript:


if something is missing value then
else
   -- some actions here
end if

Other suggestion is: replace set theContainer to currentFolder with set theContainer to contents of currentFolder.

Last edited by KniazidisR (2021-06-15 02:02:36 am)


Model: MacBook Pro
OS X: Catalina 10.15.4
Web Browser: Safari 14.1
Ram: 4 GB

Offline

 

#3 2021-06-15 04:14:36 am

bwill
Member
Registered: 2019-07-17
Posts: 8

Re: Speed up script for getting mailboxes of Outlook

Thanks for your reply. The language would be seriously foobared having "if is" faster than "if is not". The contents did help a bit.

I've now come to a different solution: I only need the id of the mailbox, the name of the mailbox and the id of the parent mailbox. The rest I can do much more easily in my main development language:

Applescript:

tell application id "com.microsoft.outlook"
   set allMailFolderIDs to get mail folders
   
   set allMailFolderNames to {}
   repeat with theFolder in allMailFolderIDs
       set FolderName to name of theFolder
       if FolderName is missing value then
           set end of allMailFolderNames to "xxx"
       else
           set end of allMailFolderNames to name of theFolder
       end if
   end repeat
   
   set AllMailFolderContainers to {}
   repeat with theFolder in allMailFolderIDs
       set theContainer to container of theFolder
       if theContainer is missing value then
           set end of AllMailFolderContainers to "-1"
       else
           set end of AllMailFolderContainers to container of theFolder
       end if
   end repeat
   
   return allMailFolderIDs & "||" & allMailFolderNames & "||" & AllMailFolderContainers
end tell

The original script ran in 20 seconds. The new script runs in about 5 seconds.

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)