MacOS Mojave limits Mail directory access due to new security features

85 Views Asked by At

This weekend I upgraded to Mojave 10.14. MacOS introduced new security features in this Mojave 10.14 release. One feature identifies applications attempting to copy, modify, or use certain files and services. Cleverly done by Apple but I believe this gives me an error. My python script retrieves mail attachments send to me by a trusted source and parses the data in the attachments for further processing. I have been using RichieHindle's solution to find immediate subdirectories:

import os
def get_immediate_subdirectories(a_dir):
    return [name for name in os.listdir('/Users/userx/Library/Mail')
        if os.path.isdir(os.path.join(a_dir, name))]

Worked fine in the High Sierra release. Still works fine with other directories. However with this code I NOW get the error both in Terminal and in Pycharm (first assuming that Terminal might have been authorized).

OSError: [Errno 1] Operation not permitted: '/Users/userx/Library/Mail'

I assume this a result of Apple's new security features. I can change sharing permissions on the Mail subdirectory using 'show info' after right clicking the Mail directory. This is to no avail. System Preferences Security and Privacy offers no solace either.

Question1: Is my assumption deemed to be correct?

Question2: If so: what needs to be done or changed to access the Mail directory and list its subdirectories and content under the Mojave 10.14 release?

1

There are 1 best solutions below

0
On

Assumption is correct.

User[s] can pre-approve apps (e.g. Terminal, PYCharm) by adding them to the new System Application Data category in the System Preferences Security and Privacy pane. By doing so, the user preauthorizes those apps to access all of their privacy-sensitive data without prompting. Done accordingly and it now works for me again. (Answer found here)