Skip to content

Added conditional code to create directories if attachment file path … #6

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion naomi/mail/backends/naomi.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import datetime
import os
import pathlib
import six
import webbrowser
from django.conf import settings
Expand All @@ -20,7 +21,14 @@ def write_message(self, message):
if hasattr(message, 'attachments') and message.attachments:
temporary_path = settings.EMAIL_FILE_PATH
for attachment in message.attachments:
new_file = open(os.path.join(temporary_path, attachment.name), 'wb+')
if '/' in attachment:
file_parts = attachment.split('/')
full_path = os.path.join(temporary_path,
'/'.join(file_parts[:-1]))
pathlib.Path(full_path).mkdir(parents=True, exist_ok=True)

new_file = open(os.path.join(
temporary_path, attachment.name), 'wb+')
new_file.write(attachment.read())
attachments.append([attachment.name, new_file.name])
new_file.close()
Expand Down