예제 #1
0
    def send_to_managers(self, subject, message, extra_headers={}):
        # create a list of valid manager emails
        manager_emails = []
        for manager in self.context.managers:
            if not is_email(manager):
                manager = lookup_email(manager.encode('ascii'), self.context)
            if manager not in manager_emails and manager:
                manager_emails.append(manager)

        if not len(manager_emails):
            return False

        list_manager_emails = ', '.join(manager_emails)
        sender = '"%s" <%s>' % ('[' + self.context.title + '] List Manager',
                                self.context.manager_email)
        try:
            message = translate(message)
        except UnicodeDecodeError:
            # Argh, a raw byte string.
            encoding = getSiteEncoding(self)
            message = translate(message.decode(encoding))

        self.context.sendCommandRequestMail(list_manager_emails,
                                            subject,
                                            translate(message),
                                            sender,
                                            extra_headers=extra_headers)
 def createMessage(self):
     """Generate a basic message, MailBoxer will take care of all the
        important headers, hopefully."""
     headers = {'Message-Id': self.new_message_id(),
                'Date': self.rfc_date(),}
     ml = self.getMailingList()
     encoding = getSiteEncoding(ml)
     body = decode(self.request.get('body'), ml)
     subject = decode(self.request.get('subject'), ml)
     message = construct_simple_encoded_message(from_addr=self.member_address(),
                                                to_addr=self.list_address(),
                                                subject=subject,
                                                body=body,
                                                other_headers=headers,
                                                encoding=encoding)
     return message.as_string()
 def createMessage(self):
     """Generate a basic message, MailBoxer will take care of all the
        important headers, hopefully."""
     headers = {
         'Message-Id': self.new_message_id(),
         'Date': self.rfc_date(),
     }
     ml = self.getMailingList()
     encoding = getSiteEncoding(ml)
     body = decode(self.request.get('body'), ml)
     subject = decode(self.request.get('subject'), ml)
     message = construct_simple_encoded_message(
         from_addr=self.member_address(),
         to_addr=self.list_address(),
         subject=subject,
         body=body,
         other_headers=headers,
         encoding=encoding)
     return message.as_string()
 def getValueFor(self, key):
     # value = MailBoxer.getValueFor(self, key)
     # Simplify: we have no need for all the strange 'getter' magic that
     # MailBoxer does
     value = self.getProperty(key)
     encoding = getSiteEncoding(self)
     try:
         if hasattr(value, 'encode'):
             value = self._encodedHeader(value, encoding)
         elif isinstance(value, list) or isinstance(value, tuple):
             value = [self._encodedHeader(v, encoding) for v in value]
     except (UnicodeEncodeError, UnicodeDecodeError):
         # Just in case one of our 'utf-8' encoding attempts fails, we
         # give up
         pass
     except AttributeError:
         # No 'encode' method on a list element, so give up
         pass
     return value
예제 #5
0
 def getValueFor(self, key):
     # value = MailBoxer.getValueFor(self, key)
     # Simplify: we have no need for all the strange 'getter' magic that
     # MailBoxer does
     value = self.getProperty(key)
     encoding = getSiteEncoding(self)
     try:
         if hasattr(value, 'encode'):
             value = self._encodedHeader(value, encoding)
         elif isinstance(value, list) or isinstance(value, tuple):
             value = [self._encodedHeader(v, encoding) for v in value]
     except (UnicodeEncodeError, UnicodeDecodeError):
         # Just in case one of our 'utf-8' encoding attempts fails, we
         # give up
         pass
     except AttributeError:
         # No 'encode' method on a list element, so give up
         pass
     return value
    def adaptMail(self, REQUEST):
        """Adapts an incoming request to a specialized view for handling
        mail if requested."""

        mailString = self.getMailFromRequest(REQUEST)
        (header, body) = splitMail(mailString)

        encoding = getSiteEncoding(self)
        subject = decode_header(str(Header(header.get('subject',''), 
                                           encoding,
                                           errors='replace')))

        command_match = re.search(mail_command_re, subject)
        if command_match:
            command_name = command_match.groups()[0]
            adapter = queryMultiAdapter((self, REQUEST), IMessageHandler,
                                        name=command_name)
            if adapter is not None:
                adapter.processMail()
                return True
        return False
예제 #7
0
    def adaptMail(self, REQUEST):
        """Adapts an incoming request to a specialized view for handling
        mail if requested."""

        mailString = self.getMailFromRequest(REQUEST)
        (header, body) = splitMail(mailString)

        encoding = getSiteEncoding(self)
        subject = decode_header(str(Header(header.get('subject',''), 
                                           encoding,
                                           errors='replace')))

        command_match = re.search(mail_command_re, subject)
        if command_match:
            command_name = command_match.groups()[0]
            adapter = queryMultiAdapter((self, REQUEST), IMessageHandler,
                                        name=command_name)
            if adapter is not None:
                adapter.processMail()
                return True
        return False
예제 #8
0
    def send_to_managers(self, subject, message, extra_headers={}):
        # create a list of valid manager emails 
        manager_emails = []
        for manager in self.context.managers:
            if not is_email(manager):
                manager = lookup_email(manager.encode('ascii'), self.context)
            if manager not in manager_emails and manager:
                manager_emails.append(manager)

        if not len(manager_emails):
            return False

        list_manager_emails = ', '.join(manager_emails)
        sender = '"%s" <%s>' % ('[' + self.context.title + '] List Manager', self.context.manager_email)
        try:
            message = translate(message)
        except UnicodeDecodeError:
            # Argh, a raw byte string.
            encoding = getSiteEncoding(self)
            message = translate(message.decode(encoding))
            
        self.context.sendCommandRequestMail(list_manager_emails, subject, translate(message), sender, extra_headers=extra_headers)
    def sendCommandRequestMail(self, address, subject, body, from_address=None, extra_headers={}):
        if not address: 
            print ('Products.listen.content.MailBoxerMailingList.sendCommandRequestMail() '
                   'invalid address; user may have been deleted')
            return

        if from_address is None:
            from_address = self.mailto

        # Default headers:
        headers = {'X-Mailer': self.getValueFor('xmailer')}
        headers.update(extra_headers)
        encoding = getSiteEncoding(self)
        message = construct_simple_encoded_message(from_addr=from_address,
                                                   to_addr=address,
                                                   subject=subject,
                                                   body=body,
                                                   other_headers=headers,
                                                   encoding=encoding)
            
        # XXX: Acquire the MailHost, yuck
        mh = getToolByName(self, 'MailHost')
        mh.send(str(message))
예제 #10
0
    def sendCommandRequestMail(self, address, subject, body, from_address=None, extra_headers={}):
        if not address: 
            print ('Products.listen.content.MailBoxerMailingList.sendCommandRequestMail() '
                   'invalid address; user may have been deleted')
            return

        if from_address is None:
            from_address = self.mailto

        # Default headers:
        headers = {'X-Mailer': self.getValueFor('xmailer')}
        headers.update(extra_headers)
        encoding = getSiteEncoding(self)
        message = construct_simple_encoded_message(from_addr=from_address,
                                                   to_addr=address,
                                                   subject=subject,
                                                   body=body,
                                                   other_headers=headers,
                                                   encoding=encoding)
            
        # XXX: Acquire the MailHost, yuck
        mh = getToolByName(self, 'MailHost')
        mh.send(str(message))