Jump to content

Recommended Posts

Posted (edited)

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

Posted
  On 7/26/2016 at 8:31 PM, Ktulu789 said:

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

Expand  

They have. it is $oMailitem.Parent

My UDFs and Tutorials:

  Reveal hidden contents

 

Posted (edited)
  On 7/26/2016 at 10:04 PM, water said:

They have. it is $oMailitem.Parent

Expand  

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

Posted
  On 7/27/2016 at 1:58 AM, Ktulu789 said:

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

Expand  

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

My UDFs and Tutorials:

  Reveal hidden contents

 

Posted
  On 7/27/2016 at 2:33 AM, water said:

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

Expand  

"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

Posted

:) 

My UDFs and Tutorials:

  Reveal hidden contents

 

  • 2 weeks later...
Posted (edited)

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

Posted

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

My UDFs and Tutorials:

  Reveal hidden contents

 

  • 3 weeks later...
Posted

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.

Posted

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

My UDFs and Tutorials:

  Reveal hidden contents

 

  • 2 weeks later...
Posted (edited)

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.
Expand  

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...

Expand  

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.

  Reveal hidden contents

 

Edited by Ktulu789

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

Posted

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:

  Reveal hidden contents

 

Posted (edited)

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

Posted

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:

  Reveal hidden contents

 

Posted

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

Posted

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:

  Reveal hidden contents

 

Posted (edited)

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

Posted

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:

  Reveal hidden contents

 

Posted

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

Posted

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:

  Reveal hidden contents

 

Guest
This topic is now closed to further replies.
×
×
  • Create New...