@@ -19,13 +19,13 @@ class AbstractBaseEmailMessage(models.Model):
1919 # Technically optional, but really should be there according to RFC 5322 section 3.6.4
2020 # and Django always creates the message_id on the main part of the message so we know
2121 # it will be there, but not for all sub-parts of a multi-part message
22- message_id = models .CharField (max_length = 250 , blank = True , default = '' )
22+ message_id = models .CharField (max_length = 250 , blank = True , default = "" )
2323 # Would love to make message_headers be a JSONField, but do not want to tie this to
2424 # postgres only.
2525 message_headers = models .TextField ()
26- content = models .TextField (blank = True , default = '' )
26+ content = models .TextField (blank = True , default = "" )
2727 parent = models .ForeignKey (
28- ' self' , blank = True , null = True , default = None , related_name = ' parts' , on_delete = models .CASCADE
28+ " self" , blank = True , null = True , default = None , related_name = " parts" , on_delete = models .CASCADE
2929 )
3030 created_at = models .DateTimeField (auto_now_add = True )
3131 updated_at = models .DateTimeField (auto_now = True )
@@ -38,8 +38,8 @@ def __init__(self, *args, **kwargs):
3838
3939 # methods here expect the concrete subclasses to implement the file_attachment field
4040 # should only be necessary until django 2.2 support is dropped... I hope
41- if TYPE_CHECKING and not hasattr (self , ' file_attachment' ):
42- self .file_attachment = models .FileField (blank = True , default = '' , upload_to = ' mailviewer_attachments' )
41+ if TYPE_CHECKING and not hasattr (self , " file_attachment" ):
42+ self .file_attachment = models .FileField (blank = True , default = "" , upload_to = " mailviewer_attachments" )
4343
4444 # I really only need/use get_filename(), get_content_type(), get_payload(), walk()
4545 # returns Any due to failobj
@@ -59,14 +59,14 @@ def get(self, attr: str, failobj: Any = None) -> Any:
5959 return failobj
6060
6161 def date (self ) -> str :
62- return self .get (' date' )
62+ return self .get (" date" )
6363
6464 def is_multipart (self ) -> bool :
6565 """
6666 Returns True if the message is multipart
6767 """
6868 # Not certain the self.parts.all() is accurate
69- return self .get_content_type () == ' rfc/822' or self .parts .exists () # type: ignore
69+ return self .get_content_type () == " rfc/822" or self .parts .exists () # type: ignore
7070
7171 def headers (self ) -> Dict [str , str ]:
7272 """
@@ -81,13 +81,13 @@ def values(self) -> Dict[str, str]:
8181 # not sure this is right...
8282 return self .headers ()
8383
84- def walk (self ) -> ' Union[models.QuerySet[AbstractBaseEmailMessage], List[AbstractBaseEmailMessage]]' :
84+ def walk (self ) -> " Union[models.QuerySet[AbstractBaseEmailMessage], List[AbstractBaseEmailMessage]]" :
8585 if not self .parts .all ().exists (): # type: ignore
8686 # Or should I be saving a main message all the time and even just a plaintext has a child part, hmm
8787 return [self ]
88- return self .parts .all ().order_by (' -created_at' , 'id' ) # type: ignore
88+ return self .parts .all ().order_by (" -created_at" , "id" ) # type: ignore
8989
90- def get_param (self , param : str , failobj = None , header : str = ' content-type' , unquote : bool = True ) -> str :
90+ def get_param (self , param : str , failobj = None , header : str = " content-type" , unquote : bool = True ) -> str :
9191 """
9292 Return the value of the Content-Type header’s parameter param as a string. If the message has no Content-Type header or if there is no such parameter, then failobj is returned (defaults to None).
9393
@@ -97,24 +97,24 @@ def get_param(self, param: str, failobj=None, header: str = 'content-type', unqu
9797 # TODO: error handling skipped for sure here... need to see what the real email message does
9898 # Should also consider using cgi.parse_header
9999 h = self .get (header )
100- params = h .split (';' )
100+ params = h .split (";" )
101101 for part in params [1 :]:
102- part_name , part_val = part .split ('=' )
102+ part_name , part_val = part .split ("=" )
103103 part_name = part_name .strip ()
104104 part_val = part_val .strip ()
105105 if part_name == param :
106106 return part_val
107- return ''
107+ return ""
108108
109109 def get_payload (
110110 self , i : Union [int , None ] = None , decode : bool = False
111- ) -> ' Union[bytes, AbstractBaseEmailMessage, models.QuerySet[AbstractBaseEmailMessage]]' :
111+ ) -> " Union[bytes, AbstractBaseEmailMessage, models.QuerySet[AbstractBaseEmailMessage]]" :
112112 """
113113 Temporary backwards compatibility with email.message.Message
114114 """
115115 # TODO: sort out type hint for return value here. Maybe use monkeytype to figure this out.
116116 if not self .is_multipart ():
117- charset = self .get_param (' charset' )
117+ charset = self .get_param (" charset" )
118118 if self .file_attachment :
119119 self .file_attachment .seek (0 )
120120 try :
@@ -134,18 +134,18 @@ def get_content_type(self) -> str:
134134 """
135135 Return's the message's content-type or mime type.
136136 """
137- h = self .get (' content-type' )
138- params = h .split (';' )
137+ h = self .get (" content-type" )
138+ params = h .split (";" )
139139 return params [0 ]
140140
141141 def get_filename (self , failobj = None ) -> str :
142- content_disposition = self .headers ().get (' Content-Disposition' , '' )
143- parts = content_disposition .split (';' )
142+ content_disposition = self .headers ().get (" Content-Disposition" , "" )
143+ parts = content_disposition .split (";" )
144144 for part in parts :
145- if part .strip ().startswith (' filename' ):
146- filename = part .split ('=' )[1 ].strip ('"' ).strip ()
145+ if part .strip ().startswith (" filename" ):
146+ filename = part .split ("=" )[1 ].strip ('"' ).strip ()
147147 return email .utils .unquote (filename )
148- return ''
148+ return ""
149149
150150
151151class EmailMessage (AbstractBaseEmailMessage ):
@@ -160,9 +160,9 @@ class EmailMessage(AbstractBaseEmailMessage):
160160 it just needs to be stored elsewhere, such as locally, or a different s3 bucket than the default storage.
161161 """
162162
163- file_attachment = models .FileField (blank = True , default = '' , upload_to = ' mailviewer_attachments' )
163+ file_attachment = models .FileField (blank = True , default = "" , upload_to = " mailviewer_attachments" )
164164
165165 class Meta :
166- db_table = ' mail_viewer_emailmessage'
167- ordering = ('id' ,)
168- indexes = [models .Index (fields = [' message_id' ])]
166+ db_table = " mail_viewer_emailmessage"
167+ ordering = ("id" ,)
168+ indexes = [models .Index (fields = [" message_id" ])]
0 commit comments