def test_add_message_with_attachment(self):
     mailinglist = Mailinglist(self.env,
                               emailaddress="LIST1", name="Sample List 1", private=True,
                               postperm="OPEN")
     mailinglist.insert()
     
     mailinglist.insert_raw_email(raw_message_with_attachment % dict(sender="Jack Sparrow",
                                                                     email="*****@*****.**",
                                                                     list="list1",
                                                                     domain="example.com",
                                                                     subject="Boats",
                                                                     asctime=time.asctime(),
                                                                     id="asdfasdf",
                                                                     body="Need images of boats."))
     
     message = mailinglist.conversations().next().messages().next()
     attachment_path = Attachment.select(self.env, message.resource.realm, message.resource.id).next().path
     assert os.path.exists(attachment_path)        
     message.delete()
     assert not os.path.exists(attachment_path)
    def test_add_messages(self):
        mailinglist = Mailinglist(self.env,
                                  emailaddress="LIST1", name="Sample List 1", private=True,
                                  postperm="OPEN")
        mailinglist.insert()
        mailinglist = Mailinglist(self.env,
                                  emailaddress="list2", name="Sample List 2", private=True,
                                  postperm="OPEN")
        mailinglist.insert()

        for rawmsg in rawmsgs:
            for listname in ("list1", "list2"):
                bytes = rawmsg % dict(sender="Jack Sparrow",
                                      email="*****@*****.**",
                                      list=listname,
                                      domain="example.com",
                                      subject="Boats",
                                      asctime=time.asctime(),
                                      id="asdfasdf",
                                      body="Need boats.")

                mailinglist = Mailinglist.select_by_address(self.env,
                                                            "*****@*****.**" % listname)
                message = mailinglist.insert_raw_email(bytes)
                
        assert len(list(Mailinglist.select(self.env))) == 2
        
        for mailinglist in Mailinglist.select(self.env):
            for conversation in mailinglist.conversations():
                assert conversation.get_first() is not None
                for message in conversation.messages():
                    assert message
                    #for attachment in Attachment.select(self.env, 'mailinglistmessage', message.id):
                    #    assert attachment

            mailinglist.delete()
            
        assert len(list(Mailinglist.select(self.env))) == 0