mirror of
				https://github.com/paperless-ngx/paperless-ngx.git
				synced 2025-11-02 18:47:10 -05:00 
			
		
		
		
	Use the attachment filename so downstream template matching works against it (#4931)
This commit is contained in:
		
							parent
							
								
									7ecf7f704a
								
							
						
					
					
						commit
						fbf1a051a2
					
				@ -8,6 +8,7 @@ import traceback
 | 
				
			|||||||
from datetime import date
 | 
					from datetime import date
 | 
				
			||||||
from datetime import timedelta
 | 
					from datetime import timedelta
 | 
				
			||||||
from fnmatch import fnmatch
 | 
					from fnmatch import fnmatch
 | 
				
			||||||
 | 
					from pathlib import Path
 | 
				
			||||||
from typing import Optional
 | 
					from typing import Optional
 | 
				
			||||||
from typing import Union
 | 
					from typing import Union
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -703,12 +704,15 @@ class MailAccountHandler(LoggingMixin):
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
            if is_mime_type_supported(mime_type):
 | 
					            if is_mime_type_supported(mime_type):
 | 
				
			||||||
                os.makedirs(settings.SCRATCH_DIR, exist_ok=True)
 | 
					                os.makedirs(settings.SCRATCH_DIR, exist_ok=True)
 | 
				
			||||||
                _, temp_filename = tempfile.mkstemp(
 | 
					
 | 
				
			||||||
 | 
					                temp_dir = Path(
 | 
				
			||||||
 | 
					                    tempfile.mkdtemp(
 | 
				
			||||||
                        prefix="paperless-mail-",
 | 
					                        prefix="paperless-mail-",
 | 
				
			||||||
                        dir=settings.SCRATCH_DIR,
 | 
					                        dir=settings.SCRATCH_DIR,
 | 
				
			||||||
 | 
					                    ),
 | 
				
			||||||
                )
 | 
					                )
 | 
				
			||||||
                with open(temp_filename, "wb") as f:
 | 
					                temp_filename = temp_dir / pathvalidate.sanitize_filename(att.filename)
 | 
				
			||||||
                    f.write(att.payload)
 | 
					                temp_filename.write_bytes(att.payload)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                self.log.info(
 | 
					                self.log.info(
 | 
				
			||||||
                    f"Rule {rule}: "
 | 
					                    f"Rule {rule}: "
 | 
				
			||||||
 | 
				
			|||||||
@ -1271,7 +1271,10 @@ class TestMail(
 | 
				
			|||||||
        self.assertEqual(len(self.bogus_mailbox.fetch("UNSEEN", False)), 0)
 | 
					        self.assertEqual(len(self.bogus_mailbox.fetch("UNSEEN", False)), 0)
 | 
				
			||||||
        self.assertEqual(len(self.bogus_mailbox.messages), 3)
 | 
					        self.assertEqual(len(self.bogus_mailbox.messages), 3)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def assert_queue_consumption_tasks_call_args(self, expected_call_args: list):
 | 
					    def assert_queue_consumption_tasks_call_args(
 | 
				
			||||||
 | 
					        self,
 | 
				
			||||||
 | 
					        expected_call_args: list[list[dict[str, str]]],
 | 
				
			||||||
 | 
					    ):
 | 
				
			||||||
        """
 | 
					        """
 | 
				
			||||||
        Verifies that queue_consumption_tasks has been called with the expected arguments.
 | 
					        Verifies that queue_consumption_tasks has been called with the expected arguments.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -1283,7 +1286,7 @@ class TestMail(
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        """
 | 
					        """
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        # assert number of calls to queue_consumption_tasks mathc
 | 
					        # assert number of calls to queue_consumption_tasks match
 | 
				
			||||||
        self.assertEqual(
 | 
					        self.assertEqual(
 | 
				
			||||||
            len(self._queue_consumption_tasks_mock.call_args_list),
 | 
					            len(self._queue_consumption_tasks_mock.call_args_list),
 | 
				
			||||||
            len(expected_call_args),
 | 
					            len(expected_call_args),
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user