Jump to content

OutlookEX UDF - Help & Support (III)


water
 Share

Recommended Posts

Hello, I come back again for a question.

I was thinking of using this UDF to create a faster, better and customized personal mail archiver. Every year I do it with the autoarchive option in Outlook but hey, this should work better, I think :D

I was able to recreate my foldertree inside an empty PST but since MailItems don't have a "LocatedInFolder" thing property, I thought of going folder by folder archiving stuff.

Maybe there is another way I can accomplish this with some other function.

Just for clarification
Pseudocode of my daydreaming

$FolderTree= _OL_FolderTree (MyMails)
_OL_FolderCreate ($FolderTree)
$Old= ItemFind (Mymails, $filter=date, return= EntryID,Location)

For 1 to $Old[0]
    _OL_ItemMove(EntryID, Stringreplace ($FolderTree[x],PSTLocation))
Next

This way it would first search for all old mails and then move them all to their appropriate folders

All my dreams were crushed when I found that Mails don't have location properties :P

$FolderTree= _OL_FolderTree (MyMails)
_OL_FolderCreate ($FolderTree)

For 1 to $FolderTree[0]
    $Old= ItemFind (InMyMails, $filter=date, return= EntryID,NotRecursive)
    For 1 to $Old[0]
        _OL_ItemMove ($OldEntryID, StringReplace ($FolderTree[x],PSTLocation))
    Next
Next

This way it would go to a folder, search for old mails in it, then move them to the same folder in my PST and go to the next folder to repeat the process.

Would this be a right way or is there any other function that might work better? I took a quick look at the available functions and didn't see a better one.

Thanks in advance for any advice!

Edited by Ktulu789

AutoIt is a blessing, I don't know how I was able to use my computer before [Auto]It :-S

Link to comment
Share on other sites

1 hour ago, Ktulu789 said:

but since MailItems don't have a "LocatedInFolder" thing property

They have. it is $oMailitem.Parent

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

4 hours ago, water said:

They have. it is $oMailitem.Parent

Thank you, Water! I saw it before but I thought it was for something else.

_OL_ItemFind($oOL,$vFolder,$iObjectClass,$sRestrict,$sSearchName,$sSearchValue, $sReturn= "Parent,EntryID" ,$sSort,$iFlags)

Returns me an empty string for "Parent", I tested in an Exchange folder and in a PST folder.

Row|Col 0|Col 1
[1]||0000000008F46D420453384FB93...
[2]||0000000008F46D420453384FB93...
[3]||0000000008F46D420453384FB93...

Tested it again:

Archive(16,950000)

Func Archive($Year,$Size)
   Local $oOL=$oOutlook, $vFolder="PST\123", $iObjectClass=$olMail, $sRestrict="[Size]>="&$Size&" And [ReceivedTime]<='20"&$Year&"/31/12'"
   Local $sSearchName="", $sSearchValue="", $sReturnProperties="Parent,EntryID", $sSort="", $iFlags=1, $aItems;fg=1subfolders, $sWarningClick=""

   $aItems=_OL_ItemFind($oOL,$vFolder,$iObjectClass,$sRestrict,$sSearchName,$sSearchValue,$sReturnProperties,$sSort,$iFlags)

_ArrayDisplay($aItems, "Found mails")
EndFunc

EDIT

Just tried this too:

$array=_OL_ItemGet($oOL, "0000000002EEBA932BBC024BA619079B79491F600700A11D83082064FC46903D5CD2F6DC64F90000015F168B0000A11D83082064FC46903D5CD2F6DC64F90000015F2DD10000", "", "Parent,Size")
_ArrayDisplay($array)

;Returned empty "Parent" twice.
;Row|Col 0|Col 1|Col 2
;[0]|3|3|
;[1]|Parent||0
;[2]|Parent||0
;[3]|Size|974403|3

 

Edited by Ktulu789

AutoIt is a blessing, I don't know how I was able to use my computer before [Auto]It :-S

Link to comment
Share on other sites

33 minutes ago, Ktulu789 said:

Returns me an empty string for "Parent", I tested in an Exchange folder and in a PST folder.

That's because "Parent" is no string but an object.
Check with IsObj if this is true.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

1 hour ago, water said:

That's because "Parent" is no string but an object.
Check with IsObj if this is true.

"Disk User error, replace disk user and hit any key" @error= OSILayer8 @extended= expected a string

LOL

And Microsoft says:  Parent Property: Returns the parent Object of the specified object. Read-only.

My bad. Thanks Water!! Sorry for bothering :> :>

AutoIt is a blessing, I don't know how I was able to use my computer before [Auto]It :-S

Link to comment
Share on other sites

:) 

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

  • 2 weeks later...

Hello! I have a little question about PST file formats and _OL_PSTCreate.

$iPSTType Optional: Type of the PST file. Possible values:
$olStoreANSI - ANSI format compatible with all previous versions of Microsoft Office Outlook format (default)
$olStoreDefault - Default format compatible with the mailbox mode in which Microsoft Office Outlook runs on the Microsoft Exchange Server
$olStoreUnicode - Unicode format compatible with Microsoft Office Outlook 2003 and later

2 Gb of ANSI is out of the question. But between OlStoreDefault and OlStoreUnicode. Which one is better in terms of capacity/size limitations?

Both formats are called "Outlook Data File" inside Outlook and I couldn't find out which type Outlook creates by default. I was able to create folder with chinese characters in both of this formats so my main interest is if there is a capacity difference or not between the latest two.

EDIT: I'm guessing that there are only two types of PST: ANSI and Unicode.
OlStoreDefault is in fact an OlStoreUnicode PST in my Outlook configuration. So when I create an OlStoreDefault pst and a OlStoreUnicode pst both files are the same thing. It's just a guess.

Edited by Ktulu789

AutoIt is a blessing, I don't know how I was able to use my computer before [Auto]It :-S

Link to comment
Share on other sites

I think the default used by Outlook depends on the version of Outlook. Older versions use ANSI newer use Unicode. 

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

  • 3 weeks later...

Hi, I have written the following code and although the email is successfully created from a template it just sits in my draft folder without being sent and I can't figure out why?

$Outlook = _OL_Open()
$olItem = _OL_ItemCreate($Outlook, 1, "", "Feedback.oft", "To=" & $Email)
_OL_ItemSend($Outlook, $olItem, Default)
_OL_Close($Outlook)

$Email is set previously in the code so it's not this.

Link to comment
Share on other sites

What is the value of @error and @extended after calling those _OL_* functions?

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

  • 2 weeks later...

Hello!

I finally made the complete Outlook Archive script thing! :D

And it was working flawlessly until I run it on a mailbox with over 40.000 mails in the Exchange server (arbitrary number but it is something like that, 30.000 didn't seem to have problem).

What it does: When I run it, it searches with OLItemFind for every mail from a year... Say 2015 (there should not be any mail from 2014).

Then it goes with OLFolderGet on every mail returned to get the folderpath for every item...

And on some folders it fails to return the path so the entire thing fails miserably :-S After that it should create those folders on a new PST, move everything it found to the PST and clear only the empty folders (those that weren't used in the last 8 months).

It's curious that the OLFolderGet doesn't return @Error. Then it fails when trying to OLFolderCreate a really long foldername (the mail ID used as folder name).

As a workaround I tell it to OLItemFind just one or two months (manually) and I keep doing it for the 12 months of the year. For some reason it doesn't work with the mailbox even when the number goes below 20.000 (I guess it's the retention period). But I tested it with other smaller mailboxes and it worked as before, perfectly. I already created more than 50 PST without problems except for, until now, two mailboxes.

After it fails, in Outlook I get this message when I try to open some folders.

Quote
Cannot display the folder. Microsoft Outlook cannot access the specified folder location. Your server administrator has limited the number of items you can open simultaneously. Try closing messages you have opened or removing attachments and images from unsent messages you are composing.

Is it that the script makes too many connections to the server or is it that the method I used is wrong?

Thanks a bunch for any advice you can give!

EDIT: This is the resulting array from OLFolderGet.

Quote

 

Col 0 Mail ItemID

Col 1 FullPath

Col 2 Path without root

293

00000000F11602E0AB69114694808945503DBCFD0700E8E221AF4D429A4284F9269BBE16E520000001B71C8C0000E8E221AF4D429A4284F9269BBE16E5200000020794110000

\\info44@corp.com.ar\Bandeja de entrada\ATTIPICA DMC

\Bandeja de entrada\ATTIPICA DMC

294

00000000F11602E0AB69114694808945503DBCFD0700E8E221AF4D429A4284F9269BBE16E520000001B71C8C0000E8E221AF4D429A4284F9269BBE16E5200000020794120000

\\info44@corp.com.ar\Bandeja de entrada\ATTIPICA DMC

\Bandeja de entrada\ATTIPICA DMC

295

00000000F11602E0AB69114694808945503DBCFD0700E8E221AF4D429A4284F9269BBE16E520000001B71C8C0000E8E221AF4D429A4284F9269BBE16E5200000020794100000

\\info44@corp.com.ar\Bandeja de entrada\ATTIPICA DMC

\Bandeja de entrada\ATTIPICA DMC

296

00000000F11602E0AB69114694808945503DBCFD0700E8E221AF4D429A4284F9269BBE16E52000000230001F0000E8E221AF4D429A4284F9269BBE16E5200000023396010000

00000000F11602E0AB69114694808945503DBCFD0100E8E221AF4D429A4284F9269BBE16E52000000230001F0000

00000000F11602E0AB69114694808945503DBCFD0100E8E221AF4D429A4284F9269BBE16E52000000230001F0000

297

00000000F11602E0AB69114694808945503DBCFD0700EC123C93FBD8BA4C84528706487417B7000014C100AD0000E8E221AF4D429A4284F9269BBE16E5200000023074060000

00000000F11602E0AB69114694808945503DBCFD0100EC123C93FBD8BA4C84528706487417B7000014C100AD0000

00000000F11602E0AB69114694808945503DBCFD0100EC123C93FBD8BA4C84528706487417B7000014C100AD0000

298

00000000F11602E0AB69114694808945503DBCFD0700EC123C93FBD8BA4C84528706487417B7000014C100AD0000E8E221AF4D429A4284F9269BBE16E5200000023074050000

00000000F11602E0AB69114694808945503DBCFD0100EC123C93FBD8BA4C84528706487417B7000014C100AD0000

00000000F11602E0AB69114694808945503DBCFD0100EC123C93FBD8BA4C84528706487417B7000014C100AD0000

The red stuff is the same on the Mail ID and the Folder ID. I guess it's the Mailbox or something common to the entire Mailbox, nevermind...

If the explanation was not clear, maybe the code below will clear things up. Sorry it is not very beatiful yet but I keep adding little pieces here and there, and some comments are in spanish.

Spoiler
;ConsoleWrite(@AutoItVersion);need 3.3.10.2 ;miPC alt AutoIt Version 3.3.10.2 ;psts pc 3.3.14.2
#include<OutlookEX.au3>
#include<AutoItConstants.au3>
TraySetIcon("%WinDir%\system32\shell32.dll",39)
Global $oOutlook=_OL_Open()
   If @error<>0 Then Exit MsgBox(16,"_OL_Open","Error connecting to Outlook. Error:"&@error&", ext:"&@extended)
Opt("WinTitleMatchMode", 2);any substring in title
Opt("TrayIconDebug",1)
WinActivate(" - Microsoft Outlook")

;~ For $StartYear=InputBox("Starting year?","Starting year to archive (oldest)"&@CRLF&"Clean Sync problems folders and deleted items",10) To 15
For $StartYear=15 To 15
   Archive($StartYear)
Next

Func Archive($Year);,$Size)
   TrayTip("Archiving 20"&$Year,"Searching..."&@CRLF&@CRLF&@CRLF&" ",60)
   Local $iObjectClass=$olMail, $sRestrict="[ReceivedTime]<='20"&$Year&"/31/01 23:59'";[Size]>="&$Size&" And
   Local $sSearchName="", $sSearchValue="", $sReturnProperties="EntryID,Parent", $sSort="", $iFlags=1, $aItems;fg=1subfolders, $sWarningClick=""
   $aItems=_OL_ItemFind($oOutlook,"*",$iObjectClass,$sRestrict,$sSearchName,$sSearchValue,$sReturnProperties,$sSort,$iFlags);[Received]>='2016/02/06' And [Received]<='2016/06/06' EntryID,Size,ReceivedTime
      If @error<>0 Then Exit MsgBox(16,"_OL_ItemFind","Error:"&@error&", ext:"&@extended)
   Beep(1000,1000)
   If IsArray($aItems) Then TrayTip("Year 20"&$Year&" found",$aItems[0][0]&" mails"&@CRLF&@CRLF&@CRLF&" ",10)
   _ArrayColInsert($aItems,2)
;~    MsgBox(0,"",$aItems[0][0])
   _ArrayDisplay($aItems,"OLItemFind result")
   $FirstFolder=_OL_FolderTree($oOutlook,"*",1)
      If @error<>0 Then MsgBox(16,"_OL_FolderTree","Error:"&@error&", ext:"&@extended)
   $FirstFolder=$FirstFolder[0]
   $TrimFirstFolder=StringTrimLeft($FirstFolder,2)
;~    If $aItems[0][0]<>0 Then
   $PSTName=KPstChk($FirstFolder,$Year)

   For $i=1 To $aItems[0][0];Strip ParentObjects in path and folder "MailBox\Folder\Folder\Destination >> MailBox\Folder\Folder  Destination"
      $FolderProp=_OL_FolderGet($oOutlook,$aItems[$i][1])
         If @error<>0 Then MsgBox(16,"_OL_FolderGet","Error:"&@error&", ext:"&@extended)
      $aItems[$i][1]=$FolderProp[6];queda la ruta completa en la columna 1
      $aItems[$i][2]=StringReplace($FolderProp[6],$FirstFolder,"");borra el nombre del buzón en la columna 2
   Next
;~    _ArrayDisplay($aItems,"folderget");asdf

   $TreeUniques=_ArrayUnique($aItems,3,1);Gets the list of folders to create them in the new PST
   _FileWriteFromArray(@ScriptDir&"\TreeUniques.txt",$TreeUniques,0,Default,"¬");asdf una columna?
;~    $TreeUniques=FileReadToArray(@ScriptDir&"\TreeUniques.txt");asdf
   _ArrayColInsert($TreeUniques,1)
   _ArrayColInsert($TreeUniques,2)
;~    _ArrayDisplay($TreeUniques,"Uniques")
   For $i=1 To $TreeUniques[0][0];Found no better way to trim backwards and leave the Destination folder when there was no path
      $TreeUniques[$i][1]=StringReverse($TreeUniques[$i][0]);Path
      $TreeUniques[$i][1]=StringTrimLeft($TreeUniques[$i][1],StringInStr($TreeUniques[$i][1],"\","",1))
      $TreeUniques[$i][1]=StringReverse($TreeUniques[$i][1])

      $TreeUniques[$i][2]=StringReverse($TreeUniques[$i][0]);Destination folder
      $TreeUniques[$i][2]=StringLeft($TreeUniques[$i][2],StringInStr($TreeUniques[$i][2],"\","",1)-1)
      $TreeUniques[$i][2]=StringReverse($TreeUniques[$i][2])
   Next
;~    _ArrayDisplay($TreeUniques,"Uniques stripped");asdf
   Local $ErrCreatePSTFolder
   For $i=1 To $TreeUniques[0][0];Creates the needed folders in the new PST (just the ones that will be populated)
      If StringRight($i,2)=="00" Then
         Beep(400,75)
         TrayTip("CreateFolder 20"&$Year&" "&$i&"/"&$TreeUniques[0][0],$TreeUniques[$i][0]&@CRLF&@CRLF&@CRLF&" ",5);asdf
      EndIf
      If _OL_FolderExists($oOutlook,$PSTName&$TreeUniques[$i][1])=0 Then KFolderChk($TreeUniques[$i][1],$PSTName)
      If _OL_FolderExists($oOutlook,$PSTName&$TreeUniques[$i][0])=0 Then _OL_FolderCreate($oOutlook,$TreeUniques[$i][2],$olFolderInbox,$PSTName&$TreeUniques[$i][1])
         If @error<>0 Then
            MsgBox(16,"_OL_FolderCreate","Error:"&@error&", ext:"&@extended&@CRLF&$TreeUniques[$i][0])
            _ArrayInsert($ErrCreatePSTFolder,$TreeUniques[$i][0])
         EndIf
   Next
   If IsArray($ErrCreatePSTFolder) Then _ArrayDisplay($ErrCreatePSTFolder);asdfg

   Global $Console
   Beep(2000,1000)
   For $i=1 To $aItems[0][0];Moving Mails
      Local $vItem=$aItems[$i][0], $sStoreID= Default, $vTargetFolder= $PSTName&$aItems[$i][2];asdf no usa el folder original, se puede reemplazar ese texto directo y evitar la tercera columna en $aItems
      _OL_ItemMove($oOutlook, $vItem, $sStoreID, $vTargetFolder)
         If @error<>0 Then $Console=ConsoleWrite("OLItemMove error:"&@error&", ext:"&@extended&@CRLF)
      If StringRight($i,2)=="00" Then
         Beep(400,75)
         TrayTip("Moving mails to PST 20"&$Year,$i&"/"&$aItems[0][0]&@CRLF&@CRLF&@CRLF&" ",5)
      EndIf
   Next

   Beep(3000,1500)
   Local $SpecialFolders[13]=[12,"Bandeja de entrada","Inbox","Bandeja de salida","Outbox","Borrador","Drafts","Elementos enviados","Sent items","Elementos eliminados","Deleted items","Correo electrónico no deseado","Spam"]
   For $i=1 To $TreeUniques[0][0];Clearing empty folders
      If StringRight($i,2)=="00" Then
         Beep(400,75)
         TrayTip("Delete Empty Folders "&$i&"/"&$TreeUniques[0][0],$TreeUniques[$i][0]&@CRLF&@CRLF&@CRLF&" ",5);asdf
      EndIf
      $FullPath=$TrimFirstFolder&$TreeUniques[$i][0]
      If _OL_FolderExists($oOutlook,$FullPath)==1 Or _OL_FolderExists($oOutlook,$FullPath&" ")==1 Then
         If _OL_FolderExists($oOutlook,$FullPath&" ")==1 Then $FullPath&=" "

         $UniqueFG=_OL_FolderGet($oOutlook,$FullPath)
            If @error<>0 Then MsgBox(16,"_OL_FolderGet","Error:"&@error&", ext:"&@extended&@CRLF&$FullPath)
;~          _OL_FolderSet($oOutlook,$FullPath);asdf
;~             If @error<>0 Then MsgBox(16,"_OL_FolderSet","Error:"&@error&", ext:"&@extended)
         $FT=_OL_FolderTree($oOutlook,$FullPath,3)
            If @error<>0 Then MsgBox(16,"_OL_Foldertree","Error:"&@error&", ext:"&@extended&@CRLF&$FullPath)
         $FT[0]=_ArrayInsert($FT,0,"")-1
;~          _ArrayDisplay($FT);asdf
         If $UniqueFG[7]==0 And $UniqueFG[8]==0 And $FT[0]==1 Then;if no mails and no subfolders
            $IsSpecial=0
            If StringInStr($TreeUniques[$i][0],"\",0,2)=0 Then;if no second \
               For $k=1 To $SpecialFolders[0]
                  If StringInStr($TreeUniques[$i][0],$SpecialFolders[$k])<>0 Then $IsSpecial=$k
               Next
            EndIf
            If $IsSpecial=0 Then _OL_FolderDelete($oOutlook,$TrimFirstFolder&$TreeUniques[$i][0])
               If @error <> 0 Then
                  MsgBox(16,"_OL_FolderDelete","Error:"&@error&", ext:"&@extended&@CRLF&$FullPath);-2147352567
                  FileWriteLine(@ScriptDir&"\FolderDelFailed.txt",$FullPath)
               EndIf
         EndIf
      Else
         FileWriteLine(@ScriptDir&"\FolderDelNotExists.txt",$FullPath)
      EndIf
   Next
EndFunc

Func KPstChk($PSTName,$Year)
   $PSTName=StringLeft($PSTName,StringInStr($PSTName,"@")-1)
   $PSTName=StringReplace($PSTName,"admin","A")&" "&$Year
   $PSTName=StringReplace($PSTName,"info","I")
   $PSTName=StringReplace($PSTName,"ventas","V")
   $PSTName=StringReplace($PSTName,"test","T");asdf
   $PSTName=StringReplace($PSTName,"\\","")
   $PSTName=StringUpper(StringLeft($PSTName,2))&StringLower(StringTrimLeft($PSTName,2))
;~    MsgBox(0,"",$PSTName)
   Local $PstFullPath=@ScriptDir&"\"&$PSTName&".pst"

   If FileExists($PstFullPath) Then
      Local $oPST=_OL_PSTAccess($oOutlook,$PstFullPath,$PSTName)
         If @error<>0 Then Exit MsgBox(16,"_OL_PSTAccess", "Error accessing '"&$PstFullPath&"' archive. Error:"&@error&", ext:"&@extended)
      $PstFGet=_OL_FolderGet($oOutlook,$oPST)
   Else
      Local $oPST=_OL_PSTCreate($oOutlook,$PstFullPath,$PSTName,$olStoreUnicode)
         If @error <> 0 Then Exit MsgBox(16, "_OL_PSTCreate", "Error creating '"&$PstFullPath&"' archive. Error:"&@error&", ext:"&@extended)
;~       $PstFGet=_OL_FolderGet($oOutlook,$oPST)
   EndIf
   Return $PSTName
EndFunc

Func KFolderChk($FolderPath,$PSTName)
;~    MsgBox(0,"",$FolderPath)
   $FolderPath=StringSplit($FolderPath,"\")
   _ArrayColInsert($FolderPath,1)
;~    _ArrayDisplay($FolderPath,"strip")
   For $i=2 To $FolderPath[0][0]
      $FolderPath[$i][1]=$FolderPath[$i][0]
;~       $FolderPath[$i][2]=$FolderPath[$i][0]
      $FolderPath[$i][1]=$FolderPath[$i-1][1]&"\"&$FolderPath[$i][1]
      If _OL_FolderExists($oOutlook,$PSTName&$FolderPath[$i][1])=0 Then _OL_FolderCreate($oOutlook,$FolderPath[$i][0],$olFolderInbox,$PSTName&$FolderPath[$i-1][1])
   Next
;~    _ArrayDisplay($FolderPath,"strip2")

EndFunc

Func _ArrayColInsert(ByRef $avArray, $iColumn)
    If Not IsArray($avArray) Then Return SetError(1, 0, -1)
    Local $iDim_1 = UBound($avArray, $UBOUND_ROWS)
    Switch UBound($avArray, $UBOUND_DIMENSIONS)
        Case 1
            Local $aTempArray[$iDim_1][2]
            Switch $iColumn
                Case 0, 1
                    For $i = 0 To $iDim_1 - 1
                        $aTempArray[$i][(Not $iColumn)] = $avArray[$i]
                    Next
                Case Else
                    Return SetError(3, 0, -1)
            EndSwitch
            $avArray = $aTempArray
        Case 2
            Local $iDim_2 = UBound($avArray, $UBOUND_COLUMNS)
            If $iColumn < 0 Or $iColumn > $iDim_2 Then Return SetError(3, 0, -1)
            ReDim $avArray[$iDim_1][$iDim_2 + 1]
            For $i = 0 To $iDim_1 - 1
                For $j = $iDim_2 To $iColumn + 1 Step -1
                    $avArray[$i][$j] = $avArray[$i][$j - 1]
                Next
                $avArray[$i][$iColumn] = ""
            Next

        Case Else
            Return SetError(2, 0, -1)
    EndSwitch
    Return UBound($avArray, $UBOUND_COLUMNS)
EndFunc   ;==>_ArrayColInsert
If $Console Then MsgBox(0,"ver consola","errores")
_OL_Close($oOutlook)

 

 

Edited by Ktulu789

AutoIt is a blessing, I don't know how I was able to use my computer before [Auto]It :-S

Link to comment
Share on other sites

Can you check the type of property parent in the cases you describe? Is it an object or just empty or even Null?

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

I edited and added just that I think. I didn't know you replied :P

I get IDs or some long hex strings. Not empty nor null.

 

 

Col 0 Mail ItemID

Col 1 FullPath

Col 2 Path without root

293

00000000F11602E0AB69114694808945503DBCFD0700E8E221AF4D429A4284F9269BBE16E520000001B71C8C0000E8E221AF4D429A4284F9269BBE16E5200000020794110000

\\info44@corp.com.ar\Bandeja de entrada\ATTIPICA DMC

\Bandeja de entrada\ATTIPICA DMC

294

00000000F11602E0AB69114694808945503DBCFD0700E8E221AF4D429A4284F9269BBE16E520000001B71C8C0000E8E221AF4D429A4284F9269BBE16E5200000020794120000

\\info44@corp.com.ar\Bandeja de entrada\ATTIPICA DMC

\Bandeja de entrada\ATTIPICA DMC

295

00000000F11602E0AB69114694808945503DBCFD0700E8E221AF4D429A4284F9269BBE16E520000001B71C8C0000E8E221AF4D429A4284F9269BBE16E5200000020794100000

\\info44@corp.com.ar\Bandeja de entrada\ATTIPICA DMC

\Bandeja de entrada\ATTIPICA DMC

296

00000000F11602E0AB69114694808945503DBCFD0700E8E221AF4D429A4284F9269BBE16E52000000230001F0000E8E221AF4D429A4284F9269BBE16E5200000023396010000

00000000F11602E0AB69114694808945503DBCFD0100E8E221AF4D429A4284F9269BBE16E52000000230001F0000

00000000F11602E0AB69114694808945503DBCFD0100E8E221AF4D429A4284F9269BBE16E52000000230001F0000

297

00000000F11602E0AB69114694808945503DBCFD0700EC123C93FBD8BA4C84528706487417B7000014C100AD0000E8E221AF4D429A4284F9269BBE16E5200000023074060000

00000000F11602E0AB69114694808945503DBCFD0100EC123C93FBD8BA4C84528706487417B7000014C100AD0000

00000000F11602E0AB69114694808945503DBCFD0100EC123C93FBD8BA4C84528706487417B7000014C100AD0000

298

00000000F11602E0AB69114694808945503DBCFD0700EC123C93FBD8BA4C84528706487417B7000014C100AD0000E8E221AF4D429A4284F9269BBE16E5200000023074050000

00000000F11602E0AB69114694808945503DBCFD0100EC123C93FBD8BA4C84528706487417B7000014C100AD0000

00000000F11602E0AB69114694808945503DBCFD0100EC123C93FBD8BA4C84528706487417B7000014C100AD0000

Edited by Ktulu789

AutoIt is a blessing, I don't know how I was able to use my computer before [Auto]It :-S

Link to comment
Share on other sites

Are this items stored in the root folder? So that the parent object doesn't return a folder but the StoreID?

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

No, there are no mails in the root folder.

Probably if that was the problem it wouldn't work with smaller searches (months). My first thought was that there was a problem with the server or the storage database, thankfully it is ok.

AutoIt is a blessing, I don't know how I was able to use my computer before [Auto]It :-S

Link to comment
Share on other sites

At the moment I have no idea why some mails do not return a correct path.
Would it be possible to strip down your script to just a few lines that show the undesired behaviour?
Would be much easier to debug ;)

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

I will try to simplify the script, meanwhile, maybe this throws some light.

I did a manual search for items from March 28, 2015 or older (Advanced search function in Outlook). There are no mails older than March so it returns just that month. There were 745 mails...

The same search with OLItemFind returned 710 results. O.o

This is the specific search I'm doing:

$Year=15
Local $iObjectClass=$olMail, $sRestrict="[ReceivedTime]<='20"&$Year&"/28/03 23:59'";[Size]>="&$Size&" And
Local $sSearchName="", $sSearchValue="", $sReturnProperties="EntryID,Parent", $sSort="", $iFlags=1, $aItems;fg=1subfolders, $sWarningClick=""
$aItems=_OL_ItemFind($oOutlook,"*",$iObjectClass,$sRestrict,$sSearchName,$sSearchValue,$sReturnProperties,$sSort,$iFlags);[Received]>='2016/02/06' And [Received]<='2016/06/06' EntryID,Size,ReceivedTime

When it finished moving the stuff, it left those 35 mails untouched. So I expected that running the script again would return 0 mails, but it somewhat worked and returned 32. It moved them without problems and left the remaining 3 untouched.

I repeated it again and it returned the final 3 mails that were left and moved them fine.

A final run returned no mails as expected.

-----------

Then I went on and changed 28/03 > 28/04, it returned the same number of items that the advanced search gave and worked fine.

After that, I tried to do the advanced search on may and I got this message:

Outlook cannot perform your search.  Your server administrator has limited the number of items you can open simultaneously. Try closing messages you have opened or removing attachments and images from unsent messages you are composing.

I have no other window open besides Outlook and the Advanced find window, of course. Maybe if I can simplify the OLItemFind function it might work.

How can I change this part in OutlookEX so it only asks for the two properties I need (EntryID and Parent)? This is in lines 2809 to 2815 in OutlookEX. Maybe if I only ask two properties instead of iterate over the entire possible mail properties it wont fail afterwards.

I see that line 2811 is the one that shows most of the time with opt "TrayIconDebug" enabled.

If BitAND($iFlags, 4) <> 4 Then
            For $iIndex = 1 To $aReturnProperties[0]
                $aItems[$iCounter][$iIndex - 1] = $oItem.ItemProperties.Item($aReturnProperties[$iIndex]).value
                If @error Then Return SetError(4, @error, "")
                If BitAND($iFlags, 2) = 2 And $iCounter = 1 Then $aItems[0][$iIndex - 1] = $oItem.ItemProperties.Item($aReturnProperties[$iIndex]).Name
            Next
        EndIf

 

Edited by Ktulu789

AutoIt is a blessing, I don't know how I was able to use my computer before [Auto]It :-S

Link to comment
Share on other sites

I see.
The problem is caused by the "Parent" property.
With "EntryID" the actual data is being returned, with "Parent" you just get a reference to the mail item's property. This means that e.g. if _OL_ItemFind returns 20000 entries then 20000 mail items remain "open" until you drop the returned array.
A solution would be to just retrieve property "EntryID" with _OL_ItemFind and then do a _OL_ItemGet for each item in the loop. So there is just a single mail item open at any time.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Wow! I see!

I will change that then! Thanks a bunch, Water!

I will have to make some serious changes in it! xD

 

About the other question, how can I speed up the OLItemfind function?

An Outlook advanced search is always faster, like ten times faster, than the same OLItemFind search.

I'm not using Index/Windows search as every time is a new, different mailbox, no use in indexing every mailbox for that. Also, no local OST file.

I think that if I can change the Function loop that returns the results to just return the "ItemID" it might be a lot faster but I'm not as good as you with Outlook stuff to even understand that part of your Function.

If BitAND($iFlags, 4) <> 4 Then
            For $iIndex = 1 To $aReturnProperties[0]
                $aItems[$iCounter][$iIndex - 1] = $oItem.ItemProperties.Item($aReturnProperties[$iIndex]).value
                If @error Then Return SetError(4, @error, "")
                If BitAND($iFlags, 2) = 2 And $iCounter = 1 Then $aItems[0][$iIndex - 1] = $oItem.ItemProperties.Item($aReturnProperties[$iIndex]).Name
            Next
EndIf

This is in lines 2809 to 2815 in OutlookEX. Maybe if I only ask ItemID instead of iterate over the entire possible mail properties it will be faster.

I see that line 2811 is the one that shows most of the time with opt "TrayIconDebug" enabled.

AutoIt is a blessing, I don't know how I was able to use my computer before [Auto]It :-S

Link to comment
Share on other sites

I do not think that modifying _OL_ItemFind will greatly enhance performance. The loop only grabs those properties you specify to be returned.
But maybe _OL_ItemSearch is faster?

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
 Share

×
×
  • Create New...