Esempio n. 1
0
 def test_basic(self):
     htmlsrc = "<html><head></head><body></body></html>"
     textsrc = ""
     urlbase = 'http://example.com'
     uuid = '0'*32
     inst = _email.email_instantiator(textsrc, htmlsrc, urlbase)
     text, html = inst(uuid)
     self.assertEquals(text, textsrc)
     self.assertEquals(html, htmlsrc)
Esempio n. 2
0
 def render(self, uuid, disable_pixelimages=True):
     """ Render the content but with pixelimages disabled by default.  The 
         given uuid is not validated, so a dummy uuid can be used to create 
         previews. """
     urlbase = app_settings.URLBASE
     einstantiator = _email.email_instantiator(self.txtmsg, self.htmlmsg, 
                                  urlbase, 
                                  disable_pixelimages=disable_pixelimages)
     text, html = einstantiator(uuid)
     # Grab and return the content of the body element.
     m = re.search(r'<body>(?P<content>.*)</body>', html, re.DOTALL)
     return m.group('content')    
Esempio n. 3
0
 def send(self, recipients):
     """Attempt to send the email.  This may be called on emails that have 
        already been sent.
     
        recipients: A sequence of Visitor objects who will be sent this 
                    message.
     """
     if not recipients or not recipients.exists():
         return
     urlbase = app_settings.URLBASE
     einstantiator = _email.email_instantiator(self.txtmsg, self.htmlmsg, 
                                               urlbase)
     
     # Note: msgs = list of django.core.mail.EmailMultiAlternatives
     msgs = []
     cx = mail.get_connection()
     
     # Build the emails
     for recipient in recipients:
         i = TrackedInstance(tracker=self.tracker, 
                             visitor=recipient)
         i.save()
         text, html = einstantiator(i.uuid)
         
         msg = self._create_multipart_email(text, html, recipient, cx)
         msgs.append((msg, i, recipient,))
     
     rs = []  # recipients to whom the email was sent
     today = datetime.date.today()
     
     # Send the emails
     cx.open()
     try:
         for msg, i, rec in msgs:
             msg.send()
             i.notified = today
             i.save()
             rs.append(rec)
     finally:
         cx.close()  # Close the connection!
         
         # Record the recipients
         er = EmailRecipients(email=self, datesent=today)
         er.save()
         for recipient in rs:
             er.recipients.add(recipient)
         er.save()
Esempio n. 4
0
    def test_trail(self):
        htmlsrc = "<html><head></head><body>"
        htmlsrc += "{% trackedurl linkid 'linkanalytics/r/path/to/file.ext' %}"
        htmlsrc += "</body></html>"
        textsrc = "{% trackedurl linkid 'linkanalytics/r/path/to/file.ext' %}"
        urlbase = 'http://example.com'
        uuid = '0'*32
        inst = _email.email_instantiator(textsrc, htmlsrc, urlbase)
        text, html = inst(uuid)
        url = urlex.hashedurl_redirect_local(uuid, 'path/to/file.ext')
        self.assertEquals(text, '{0}{1}'.format(urlbase, url))
        expecthtml = "<html><head></head><body>{0}{1}</body></html>"
        expecthtml = expecthtml.format(urlbase, url)
        self.assertEquals(html, expecthtml)

        
#==============================================================================#