Commits

Sergio Oliveira  committed de0a16f

Changing the way that we verify if a message is already stored at the DB

  • Participants
  • Parent commits e3b9859

Comments (0)

Files changed (1)

File colab/super_archives/management/commands/import_emails.py

         mailinglist, created = MailingList.objects.get_or_create(name=list_name)
         mailinglist.last_imported_index = index
        
-        # If the message is already at the database don't do anything:
          if created: 
             # if the mailinglist is newly created it's sure that the message
             #   is not in the DB yet.
             self.create_email(mailinglist, email_msg)
             
         else:
-            query = Message.objects.all()
-            query = query.filter(message_id=email_msg.get('Message-ID'))
-            messages = query.filter(thread__mailinglist=mailinglist)
+            # If the message is already at the database don't do anything
+            try:
+                messages = Message.objects.get(
+                    message_id=email_msg.get('Message-ID'),
+                    thread__mailinglist=mailinglist
+                )
             
-            if not messages:
+            except Message.DoesNotExist:
                 self.create_email(mailinglist, email_msg)
         
         mailinglist.save()