<commit_before>__author__ = 'layip'

import win32com.client

mailbox = 'Mailbox - Yip, Li-Aung'
folderindex = 3 # Magic?

ol_application = win32com.client.Dispatch("Outlook.Application")
ol_namespace = ol_application.GetNamespace("MAPI") # Equivalent to ol_application.Session

# Folders object: https://msdn.microsoft.com/en-us/library/office/ff860950(v=office.14).aspx
# Supports methods Add, GetFirst, GetLast, GetNext, GetPrevious, Item, Remove.
# Item() can be used to get a folder by name, i.e. Folders.Item("GroupDiscussion").
# ol_folders = ol_namespace.Folders

selected_folder = ol_namespace.PickFolder()

if selected_folder is None:
    print ("Nothing!")
else:
    print selected_folder.Name

def get_subfolders( folder ):
    # Returns a list of folders under the given folder.
    for f in folder.Folders:
        print f.Name
        get_subfolders(f)<commit_msg>Recursive folder listing and subject name printing: it works!<commit_after>__author__ = 'layip'

import win32com.client

mailbox = 'Mailbox - Yip, Li-Aung'
folderindex = 3 # Magic?

ol_application = win32com.client.Dispatch("Outlook.Application")
ol_namespace = ol_application.GetNamespace("MAPI") # Equivalent to ol_application.Session

# Folders object: https://msdn.microsoft.com/en-us/library/office/ff860950(v=office.14).aspx
# Supports methods Add, GetFirst, GetLast, GetNext, GetPrevious, Item, Remove.
# Item() can be used to get a folder by name, i.e. Folders.Item("GroupDiscussion").
# ol_folders = ol_namespace.Folders

selected_folder = ol_namespace.PickFolder()

if selected_folder is None:
    print ("Nothing!")
else:
    print selected_folder.Name

def get_subfolders( folder, f_list ):
    # `folder` is an Outlook `Folder` object, and `f_list` is an empty python list().
    # At finish, f_list contains a flat list of Outlook `Folder` objects,
    # including all sub-folders of `folder` as well as `folder` itself.
    f_list.append (folder)
    for f in folder.Folders:
        get_subfolders(f, f_list)

def print_subjects (folder):
    for i in folder.Items:
        print i.subject

folder_list = list()
get_subfolders(selected_folder, folder_list)

for n in xrange(3):
    print_subjects(folder_list[n])
{'fraction_non_alphanumeric': 0.10607434270172257, 'fraction_numerical': 0.012239347234814143, 'mean_word_length': 4.5175, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1016799', 'n_tokens_mistral': 747, 'n_tokens_neox': 712, 'n_words': 200}