2

I've been trying to access folders and items in my Outlook archive using exchangelib. I can print out the tree structure in the account with print(account.root.tree()) and iterate over the messages with:

for item in account.root.all().order_by('-datetime_received')[:10]:
    print(item.subject, item.body, item.attachments)  

..but how can I achieve the same in my archive?

print(account.archive_msg_folder_root.tree()) does not return an equivalent tree-structure, and I cannot find a way to traverse the folder structure in my archive and access the messages' information in a given subfolder.

EDIT:

I should clarify. This is my folder structure in my outlook: The archive I am trying to access

I have my regular inbox and different folders, and an archive ("Tilkoblet arkiv - <myuser@domain.no>"), where items more than 3 months are moved to. I am trying to access these older items. Is archive_msg_folder_root the right way to go? Or do I need to change the primary_smtp_address?

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
McBuch
  • 43
  • 6
  • `tree()` is supposed to print the tree at the level where `tree()` is called, but looking at the code again, there *may* be situations where the cached folder structure is not populated sufficiently. I'll have to add a test for that. You may have better luck accessing the subfolder using the `account.root / 'Some Folder Name' / 'MyArchive'` syntax. You can then `walk()` through all the subfolders in that folder. – Erik Cederstrand Feb 26 '18 at 14:53
  • Actually, I cannot reproduce this since my test account does not have an archive folder structure. I tried `recoverable_items_root` but it works without issues. What's the error or output you get from `account.archive_msg_folder_root.tree()` and what did you expect? – Erik Cederstrand Feb 26 '18 at 15:03
  • `print(account.archive_msg_folder_root.tree())` returns "Øverst i informasjonslageret", or "Top of Information Store" in English. I am suspecting the archive is not contained here? – McBuch Feb 27 '18 at 08:10
  • Oh, that's surprising. Can you please open an issue on GitHub with this? The output of `account.root.tree()` and `account.archive_msg_folder_root.tree()` is necessary as a start. – Erik Cederstrand Feb 27 '18 at 08:13
  • Is `myuser@domain.no` the same as your primary account, or are the addresses different? – Erik Cederstrand Feb 27 '18 at 08:20
  • [Done](https://github.com/ecederstrand/exchangelib/issues/348) – McBuch Feb 27 '18 at 08:55
  • Yes, they are the same. – McBuch Feb 27 '18 at 08:56

0 Answers0