Esempio n. 1
0
    def prepare_mail(self,
                     subject=u'',
                     to_userid=None,
                     from_userid=None,
                     data=None):
        if data is None:
            data = {}

        msg = MIMEMultipart('related')
        actor = ogds_service().fetch_user(from_userid) if from_userid else None

        if actor:
            msg['From'] = make_addr_header(actor.fullname(), actor.email,
                                           'utf-8')
        else:
            msg['From'] = make_addr_header(u'OneGov GEVER',
                                           api.portal.get().email_from_address,
                                           'utf-8')

        recipient = ogds_service().fetch_user(to_userid)
        msg['To'] = recipient.email
        msg['Subject'] = Header(subject, 'utf-8')

        # Break (potential) description out into a list element per newline
        if data.get('description'):
            data['description'] = data.get('description').splitlines()

        html = self.prepare_html(data)
        msg.attach(MIMEText(html.encode('utf-8'), 'html', 'utf-8'))
        return msg
Esempio n. 2
0
    def prepare_mail(self, subject=u'', to_userid=None, from_userid=None, data=None):
        if data is None:
            data = {}

        msg = MIMEMultipart('related')
        actor = ogds_service().fetch_user(from_userid) if from_userid else None

        if actor:
            msg['From'] = make_addr_header(actor.fullname(),
                                           actor.email, 'utf-8')
        else:
            msg['From'] = make_addr_header(
                u'OneGov GEVER', api.portal.get().email_from_address, 'utf-8')

        recipient = ogds_service().fetch_user(to_userid)
        msg['To'] = recipient.email
        msg['Subject'] = Header(subject, 'utf-8')

        # Break (potential) description out into a list element per newline
        if data.get('description'):
            data['description'] = data.get('description').splitlines()

        html = self.prepare_html(data)
        msg.attach(MIMEText(html.encode('utf-8'), 'html', 'utf-8'))
        return msg
Esempio n. 3
0
 def test_encodes_addr_name(self):
     fullname = u'Fr\xe4nzi M\xfcller'
     address = '*****@*****.**'
     header = make_addr_header(fullname, address)
     self.assertEquals(
         [('Fr\xc3\xa4nzi M\xc3\xbcller', 'utf-8'),
          ('<*****@*****.**>', None)],
         decode_header(header))
Esempio n. 4
0
    def send_button_handler(self, action):
        """Create and Send the Email."""
        data, errors = self.extractData()

        if len(errors) == 0:
            mh = getToolByName(self.context, 'MailHost')
            userid = self.context.portal_membership.getAuthenticatedMember()
            userid = userid.getId()
            intern_receiver = []
            for receiver in data.get('intern_receiver', []):
                # cut away the username
                intern_receiver.append(receiver.split(':')[0])

            extern_receiver = data.get('extern_receiver') or []
            addresses = intern_receiver + extern_receiver

            # create the mail
            msg = self.create_mail(
                data.get('message'),
                data.get('documents'),
                only_links=data.get('documents_as_links'))

            msg['Subject'] = Header(data.get('subject'), CHARSET)

            user = ogds_service().fetch_user(userid)
            sender_address = user and user.email
            if not sender_address:
                portal = self.context.portal_url.getPortalObject()
                sender_address = portal.email_from_address

            msg['From'] = make_addr_header(
                user.label(), sender_address, CHARSET)

            header_to = Header(','.join(addresses), CHARSET)
            msg['To'] = header_to

            # send it
            mfrom = u'{} <{}>'.format(
                user.label(), sender_address).encode(CHARSET)
            mh.send(msg, mfrom=mfrom, mto=','.join(addresses))

            # Store a copy of the sent mail in dossier
            if (data.get('file_copy_in_dossier', False)
                    and self._allow_save_file_copy_in_context()):
                self.file_sent_mail_in_dossier(msg)

            # let the user know that the mail was sent
            info = _(u'info_mail_sent', 'E-mail has been sent.')
            notify(DocumentSent(
                    self.context, userid, header_to, data.get('subject'),
                    data.get('message'), data.get('documents')))

            IStatusMessage(self.request).addStatusMessage(info, type='info')
            # and redirect to default view / tab
            return self.request.RESPONSE.redirect(
                get_containing_document_tab_url(data.get('documents')[0]))
Esempio n. 5
0
    def send_button_handler(self, action):
        """Create and Send the Email."""
        data, errors = self.extractData()

        if len(errors) == 0:
            mh = getToolByName(self.context, 'MailHost')
            userid = self.context.portal_membership.getAuthenticatedMember()
            userid = userid.getId()
            intern_receiver = []
            for receiver in data.get('intern_receiver', []):
                # cut away the username
                intern_receiver.append(receiver.split(':')[0])

            extern_receiver = data.get('extern_receiver') or []
            addresses = intern_receiver + extern_receiver

            # create the mail
            msg = self.create_mail(
                data.get('message'),
                data.get('documents'),
                only_links=data.get('documents_as_links'))

            msg['Subject'] = Header(data.get('subject'), CHARSET)

            user = ogds_service().fetch_user(userid)
            sender_address = user and user.email
            if not sender_address:
                portal = self.context.portal_url.getPortalObject()
                sender_address = portal.email_from_address

            msg['From'] = make_addr_header(
                user.label(), sender_address, CHARSET)

            header_to = Header(','.join(addresses), CHARSET)
            msg['To'] = header_to

            # send it
            mfrom = u'{} <{}>'.format(
                user.label(), sender_address).encode(CHARSET)
            mh.send(msg, mfrom=mfrom, mto=','.join(addresses))

            # Store a copy of the sent mail in dossier
            if (data.get('file_copy_in_dossier', False)
                    and self._allow_save_file_copy_in_context()):
                self.file_sent_mail_in_dossier(msg)

            # let the user know that the mail was sent
            info = _(u'info_mail_sent', 'E-mail has been sent.')
            notify(DocumentSent(
                    self.context, userid, header_to, data.get('subject'),
                    data.get('message'), data.get('documents')))

            IStatusMessage(self.request).addStatusMessage(info, type='info')
            # and redirect to default view / tab
            return self.request.RESPONSE.redirect(
                get_containing_document_tab_url(data.get('documents')[0]))
Esempio n. 6
0
    def prepare_mail(self, notification):
        msg = MIMEMultipart('alternative')

        actor = ogds_service().fetch_user(notification.activity.actor_id)
        msg['From'] = make_addr_header(actor.fullname(), actor.email, 'utf-8')

        recipient = ogds_service().fetch_user(notification.userid)
        msg['To'] = recipient.email
        msg['Subject'] = self.get_subject(notification)

        html = self.prepare_html(notification)
        msg.attach(MIMEText(html.encode('utf-8'), 'html', 'utf-8'))

        return msg
Esempio n. 7
0
    def prepare_mail(self, notification):
        msg = MIMEMultipart('alternative')

        actor = ogds_service().fetch_user(notification.activity.actor_id)
        msg['From'] = make_addr_header(actor.fullname(), actor.email, 'utf-8')

        recipient = ogds_service().fetch_user(notification.userid)
        msg['To'] = recipient.email
        msg['Subject'] = self.get_subject(notification)

        html = self.prepare_html(notification)
        msg.attach(MIMEText(html.encode('utf-8'), 'html', 'utf-8'))

        return msg
Esempio n. 8
0
    def prepare_mail(self,
                     subject=u'',
                     to_userid=None,
                     from_userid=None,
                     data={}):
        msg = MIMEMultipart('related')

        if from_userid:
            actor = ogds_service().fetch_user(from_userid)
            msg['From'] = make_addr_header(actor.fullname(), actor.email,
                                           'utf-8')
        else:
            msg['From'] = make_addr_header(u'OneGov GEVER',
                                           api.portal.get().email_from_address,
                                           'utf-8')

        recipient = ogds_service().fetch_user(to_userid)
        msg['To'] = recipient.email
        msg['Subject'] = Header(subject, 'utf-8')

        html = self.prepare_html(data)
        msg.attach(MIMEText(html.encode('utf-8'), 'html', 'utf-8'))
        return msg
Esempio n. 9
0
 def test_preserves_bails_on_bytestring_names(self):
     fullname = 'bytestring'
     address = ''
     with self.assertRaises(ValueError):
         make_addr_header(fullname, address)
Esempio n. 10
0
 def test_preserves_addr_spec(self):
     fullname = u'Fr\xe4nzi M\xfcller'
     address = '*****@*****.**'
     header = make_addr_header(fullname, address)
     self.assertIn(' <*****@*****.**>', str(header))