当前位置: 首页>>代码示例>>Python>>正文


Python message.UserNotification类代码示例

本文整理汇总了Python中mailman.email.message.UserNotification的典型用法代码示例。如果您正苦于以下问题:Python UserNotification类的具体用法?Python UserNotification怎么用?Python UserNotification使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了UserNotification类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: register

 def register(self, mlist, email, display_name=None, delivery_mode=None):
     """See `IUserRegistrar`."""
     if delivery_mode is None:
         delivery_mode = DeliveryMode.regular
     # First, do validation on the email address.  If the address is
     # invalid, it will raise an exception, otherwise it just returns.
     getUtility(IEmailValidator).validate(email)
     # Create a pendable for the registration.
     pendable = PendableRegistration(
         type=PendableRegistration.PEND_KEY, email=email, display_name=display_name, delivery_mode=delivery_mode.name
     )
     pendable["list_name"] = mlist.fqdn_listname
     token = getUtility(IPendings).add(pendable)
     # There are three ways for a user to confirm their subscription.  They
     # can reply to the original message and let the VERP'd return address
     # encode the token, they can reply to the robot and keep the token in
     # the Subject header, or they can click on the URL in the body of the
     # message and confirm through the web.
     subject = "confirm " + token
     confirm_address = mlist.confirm_address(token)
     # For i18n interpolation.
     confirm_url = mlist.domain.confirm_url(token)
     email_address = email
     domain_name = mlist.domain.mail_host
     contact_address = mlist.domain.contact_address
     # Send a verification email to the address.
     template = getUtility(ITemplateLoader).get(
         "mailman:///{0}/{1}/confirm.txt".format(mlist.fqdn_listname, mlist.preferred_language.code)
     )
     text = _(template)
     msg = UserNotification(email, confirm_address, subject, text)
     msg.send(mlist)
     return token
开发者ID:kaushikmit,项目名称:mailman,代码行数:33,代码来源:registrar.py

示例2: _refuse

def _refuse(mlist, request, recip, comment, origmsg=None, lang=None):
    # As this message is going to the requester, try to set the language to
    # his/her language choice, if they are a member.  Otherwise use the list's
    # preferred language.
    display_name = mlist.display_name
    if lang is None:
        member = mlist.members.get_member(recip)
        lang = (mlist.preferred_language
                if member is None
                else member.preferred_language)
    text = make('refuse.txt',
                mailing_list=mlist,
                language=lang.code,
                listname=mlist.fqdn_listname,
                request=request,
                reason=comment,
                adminaddr=mlist.owner_address,
                )
    with _.using(lang.code):
        # add in original message, but not wrap/filled
        if origmsg:
            text = NL.join(
                [text,
                 '---------- ' + _('Original Message') + ' ----------',
                 str(origmsg)
                 ])
        subject = _('Request to mailing list "$display_name" rejected')
    msg = UserNotification(recip, mlist.bounces_address, subject, text, lang)
    msg.send(mlist)
开发者ID:adam-iris,项目名称:mailman,代码行数:29,代码来源:moderator.py

示例3: hold_subscription

def hold_subscription(mlist, address, display_name, password, mode, language):
    data = dict(when=now().isoformat(),
                address=address,
                display_name=display_name,
                password=password,
                delivery_mode=mode.name,
                language=language)
    # Now hold this request.  We'll use the address as the key.
    requestsdb = IListRequests(mlist)
    request_id = requestsdb.hold_request(
        RequestType.subscription, address, data)
    vlog.info('%s: held subscription request from %s',
              mlist.fqdn_listname, address)
    # Possibly notify the administrator in default list language
    if mlist.admin_immed_notify:
        subject = _(
            'New subscription request to $mlist.display_name from $address')
        text = make('subauth.txt',
                    mailing_list=mlist,
                    username=address,
                    listname=mlist.fqdn_listname,
                    admindb_url=mlist.script_url('admindb'),
                    )
        # This message should appear to come from the <list>-owner so as
        # to avoid any useless bounce processing.
        msg = UserNotification(
            mlist.owner_address, mlist.owner_address,
            subject, text, mlist.preferred_language)
        msg.send(mlist, tomoderators=True)
    return request_id
开发者ID:adam-iris,项目名称:mailman,代码行数:30,代码来源:moderator.py

示例4: send_welcome_message

def send_welcome_message(mlist, member, language, text=''):
    """Send a welcome message to a subscriber.

    Prepending to the standard welcome message template is the mailing list's
    welcome message, if there is one.

    :param mlist: The mailing list.
    :type mlist: IMailingList
    :param member: The member to send the welcome message to.
    :param address: IMember
    :param language: The language of the response.
    :type language: ILanguage
    """
    welcome_message = _get_message(mlist.welcome_message_uri, mlist, language)
    options_url = member.options_url
    # Get the text from the template.
    display_name = ('' if member.user is None else member.user.display_name)
    text = expand(welcome_message, dict(
        fqdn_listname=mlist.fqdn_listname,
        list_name=mlist.display_name,
        listinfo_uri=mlist.script_url('listinfo'),
        list_requests=mlist.request_address,
        user_name=display_name,
        user_address=member.address.email,
        user_options_uri=options_url,
        ))
    digmode = ('' if member.delivery_mode is DeliveryMode.regular
               else _(' (Digest mode)'))
    msg = UserNotification(
        formataddr((display_name, member.address.email)),
        mlist.request_address,
        _('Welcome to the "$mlist.display_name" mailing list${digmode}'),
        text, language)
    msg['X-No-Archive'] = 'yes'
    msg.send(mlist, verp=as_boolean(config.mta.verp_personalized_deliveries))
开发者ID:P-EB,项目名称:mailman3-core,代码行数:35,代码来源:notifications.py

示例5: _step_get_moderator_approval

 def _step_get_moderator_approval(self):
     # Here's the next step in the workflow, assuming the moderator
     # approves of the subscription.  If they don't, the workflow and
     # subscription request will just be thrown away.
     self._set_token(TokenOwner.moderator)
     self.push('subscribe_from_restored')
     self.save()
     log.info('{}: held subscription request from {}'.format(
         self.mlist.fqdn_listname, self.address.email))
     # Possibly send a notification to the list moderators.
     if self.mlist.admin_immed_notify:
         subject = _(
             'New subscription request to $self.mlist.display_name '
             'from $self.address.email')
         username = formataddr(
             (self.subscriber.display_name, self.address.email))
         text = make('subauth.txt',
                     mailing_list=self.mlist,
                     username=username,
                     listname=self.mlist.fqdn_listname,
                     )
         # This message should appear to come from the <list>-owner so as
         # to avoid any useless bounce processing.
         msg = UserNotification(
             self.mlist.owner_address, self.mlist.owner_address,
             subject, text, self.mlist.preferred_language)
         msg.send(self.mlist, tomoderators=True)
     # The workflow must stop running here.
     raise StopIteration
开发者ID:aswinpj,项目名称:Mailman,代码行数:29,代码来源:subscriptions.py

示例6: autorespond_to_sender

def autorespond_to_sender(mlist, sender, language=None):
    """Should Mailman automatically respond to this sender?

    :param mlist: The mailing list.
    :type mlist: `IMailingList`.
    :param sender: The sender's email address.
    :type sender: string
    :param language: Optional language.
    :type language: `ILanguage` or None
    :return: True if an automatic response should be sent, otherwise False.
        If an automatic response is not sent, a message is sent indicating
        that, er no more will be sent today.
    :rtype: bool
    """
    if language is None:
        language = mlist.preferred_language
    max_autoresponses_per_day = int(config.mta.max_autoresponses_per_day)
    if max_autoresponses_per_day == 0:
        # Unlimited.
        return True
    # Get an IAddress from an email address.
    user_manager = getUtility(IUserManager)
    address = user_manager.get_address(sender)
    if address is None:
        address = user_manager.create_address(sender)
    response_set = IAutoResponseSet(mlist)
    todays_count = response_set.todays_count(address, Response.hold)
    if todays_count < max_autoresponses_per_day:
        # This person has not reached their automatic response limit, so it's
        # okay to send a response.
        response_set.response_sent(address, Response.hold)
        return True
    elif todays_count == max_autoresponses_per_day:
        # The last one we sent was the last one we should send today.  Instead
        # of sending an automatic response, send them the "no more today"
        # message.
        log.info('hold autoresponse limit hit: %s', sender)
        response_set.response_sent(address, Response.hold)
        # Send this notification message instead.
        text = make('nomoretoday.txt',
                    language=language.code,
                    sender=sender,
                    listname=mlist.fqdn_listname,
                    count=todays_count,
                    owneremail=mlist.owner_address,
                    )
        with _.using(language.code):
            msg = UserNotification(
                sender, mlist.owner_address,
                _('Last autoresponse notification for today'),
                text, lang=language)
        msg.send(mlist)
        return False
    else:
        # We've sent them everything we're going to send them today.
        log.info('Automatic response limit discard: %s', sender)
        return False
开发者ID:aditigupta96,项目名称:mailman3,代码行数:57,代码来源:hold.py

示例7: send_welcome_message

def send_welcome_message(mlist, address, language, delivery_mode, text=''):
    """Send a welcome message to a subscriber.

    Prepending to the standard welcome message template is the mailing list's
    welcome message, if there is one.

    :param mlist: the mailing list
    :type mlist: IMailingList
    :param address: The address to respond to
    :type address: string
    :param language: the language of the response
    :type language: ILanguage
    :param delivery_mode: the type of delivery the subscriber is getting
    :type delivery_mode: DeliveryMode
    """
    if mlist.welcome_message_uri:
        try:
            uri = expand(mlist.welcome_message_uri, dict(
                listname=mlist.fqdn_listname,
                language=language.code,
                ))
            welcome_message = getUtility(ITemplateLoader).get(uri)
        except URLError:
            log.exception('Welcome message URI not found ({0}): {1}'.format(
                mlist.fqdn_listname, mlist.welcome_message_uri))
            welcome = ''
        else:
            welcome = wrap(welcome_message)
    else:
        welcome = ''
    # Find the IMember object which is subscribed to the mailing list, because
    # from there, we can get the member's options url.
    member = mlist.members.get_member(address)
    user_name = member.user.display_name
    options_url = member.options_url
    # Get the text from the template.
    text = expand(welcome, dict(
        fqdn_listname=mlist.fqdn_listname,
        list_name=mlist.display_name,
        listinfo_uri=mlist.script_url('listinfo'),
        list_requests=mlist.request_address,
        user_name=user_name,
        user_address=address,
        user_options_uri=options_url,
        ))
    if delivery_mode is not DeliveryMode.regular:
        digmode = _(' (Digest mode)')
    else:
        digmode = ''
    msg = UserNotification(
        formataddr((user_name, address)),
        mlist.request_address,
        _('Welcome to the "$mlist.display_name" mailing list${digmode}'),
        text, language)
    msg['X-No-Archive'] = 'yes'
    msg.send(mlist, verp=as_boolean(config.mta.verp_personalized_deliveries))
开发者ID:bksim,项目名称:mailman,代码行数:56,代码来源:notifications.py

示例8: bounce_message

def bounce_message(mlist, msg, error=None):
    """Bounce the message back to the original author.

    :param mlist: The mailing list that the message was posted to.
    :type mlist: `IMailingList`
    :param msg: The original message.
    :type msg: `email.message.Message`
    :param error: Optional exception causing the bounce.  The exception
        instance must have a `.message` attribute.
    :type error: Exception
    """
    # Bounce a message back to the sender, with an error message if provided
    # in the exception argument.  .sender might be None or the empty string.
    if not msg.sender:
        # We can't bounce the message if we don't know who it's supposed to go
        # to.
        return
    subject = msg.get('subject', _('(no subject)'))
    subject = oneline(subject, mlist.preferred_language.charset)
    if error is None:
        notice = _('[No bounce details are available]')
    else:
        notice = _(error.message)
    # Currently we always craft bounces as MIME messages.
    bmsg = UserNotification(msg.sender, mlist.owner_address, subject,
                            lang=mlist.preferred_language)
    # BAW: Be sure you set the type before trying to attach, or you'll get
    # a MultipartConversionError.
    bmsg.set_type('multipart/mixed')
    txt = MIMEText(notice, _charset=mlist.preferred_language.charset)
    bmsg.attach(txt)
    bmsg.attach(MIMEMessage(msg))
    bmsg.send(mlist)
开发者ID:maxking,项目名称:mailman,代码行数:33,代码来源:bounces.py

示例9: main

def main():
    opts, args, parser = parseargs()
    initialize(opts.config)

    for name in config.list_manager.names:
        # The list must be locked in order to open the requests database
        mlist = MailList.MailList(name)
        try:
            count = IListRequests(mlist).count
            # While we're at it, let's evict yesterday's autoresponse data
            midnight_today = midnight()
            evictions = []
            for sender in mlist.hold_and_cmd_autoresponses.keys():
                date, respcount = mlist.hold_and_cmd_autoresponses[sender]
                if midnight(date) < midnight_today:
                    evictions.append(sender)
            if evictions:
                for sender in evictions:
                    del mlist.hold_and_cmd_autoresponses[sender]
                # This is the only place we've changed the list's database
                mlist.Save()
            if count:
                # Set the default language the the list's preferred language.
                _.default = mlist.preferred_language
                realname = mlist.real_name
                discarded = auto_discard(mlist)
                if discarded:
                    count = count - discarded
                    text = _('Notice: $discarded old request(s) '
                             'automatically expired.\n\n')
                else:
                    text = ''
                if count:
                    text += Utils.maketext(
                        'checkdbs.txt',
                        {'count'    : count,
                         'mail_host': mlist.mail_host,
                         'adminDB'  : mlist.GetScriptURL('admindb',
                                                         absolute=1),
                         'real_name': realname,
                         }, mlist=mlist)
                    text += '\n' + pending_requests(mlist)
                    subject = _('$count $realname moderator '
                                'request(s) waiting')
                else:
                    subject = _('$realname moderator request check result')
                msg = UserNotification(mlist.GetOwnerEmail(),
                                       mlist.GetBouncesEmail(),
                                       subject, text,
                                       mlist.preferred_language)
                msg.send(mlist, **{'tomoderators': True})
        finally:
            mlist.Unlock()
开发者ID:aregee,项目名称:Mailman,代码行数:53,代码来源:checkdbs.py

示例10: setUp

 def setUp(self):
     self._mlist = create_list('[email protected]')
     self._msg = UserNotification(
         '[email protected]',
         '[email protected]',
         'Something you need to know',
         'I needed to tell you this.')
开发者ID:adam-iris,项目名称:mailman,代码行数:7,代码来源:test_message.py

示例11: send_welcome_message

def send_welcome_message(mlist, member, language, text=''):
    """Send a welcome message to a subscriber.

    Prepending to the standard welcome message template is the mailing list's
    welcome message, if there is one.

    :param mlist: The mailing list.
    :type mlist: IMailingList
    :param member: The member to send the welcome message to.
    :param address: IMember
    :param language: The language of the response.
    :type language: ILanguage
    """
    welcome_message = _get_message(mlist.welcome_message_uri, mlist, language)
    options_url = member.options_url
    # Try to find a non-empty display name.  We first look at the directly
    # subscribed record, which will either be the address or the user.  That's
    # handled automatically by going through member.subscriber.  If that
    # doesn't give us something useful, try whatever user is linked to the
    # subscriber.
    if member.subscriber.display_name:
        display_name = member.subscriber.display_name
    # If an unlinked address is subscribed tehre will be no .user.
    elif member.user is not None and member.user.display_name:
        display_name = member.user.display_name
    else:
        display_name = ''
    # Get the text from the template.
    text = expand(welcome_message, dict(
        fqdn_listname=mlist.fqdn_listname,
        list_name=mlist.display_name,
        listinfo_uri=mlist.script_url('listinfo'),
        list_requests=mlist.request_address,
        user_name=display_name,
        user_address=member.address.email,
        user_options_uri=options_url,
        ))
    digmode = (''                                   # noqa
               if member.delivery_mode is DeliveryMode.regular
               else _(' (Digest mode)'))
    msg = UserNotification(
        formataddr((display_name, member.address.email)),
        mlist.request_address,
        _('Welcome to the "$mlist.display_name" mailing list${digmode}'),
        text, language)
    msg['X-No-Archive'] = 'yes'
    msg.send(mlist, verp=as_boolean(config.mta.verp_personalized_deliveries))
开发者ID:aswinpj,项目名称:Mailman,代码行数:47,代码来源:notifications.py

示例12: send_probe

def send_probe(member, msg):
    """Send a VERP probe to the member.

    :param member: The member to send the probe to.  From this object, both
        the user and the mailing list can be determined.
    :type member: IMember
    :param msg: The bouncing message that caused the probe to be sent.
    :type msg:
    :return: The token representing this probe in the pendings database.
    :rtype: string
    """
    mlist = getUtility(IListManager).get_by_list_id(
        member.mailing_list.list_id)
    text = make('probe.txt', mlist, member.preferred_language.code,
                listname=mlist.fqdn_listname,
                address=member.address.email,
                optionsurl=member.options_url,
                owneraddr=mlist.owner_address,
                )
    message_id = msg['message-id']
    if isinstance(message_id, bytes):
        message_id = message_id.decode('ascii')
    pendable = _ProbePendable(
        # We can only pend unicodes.
        member_id=member.member_id.hex,
        message_id=message_id,
        )
    token = getUtility(IPendings).add(pendable)
    mailbox, domain_parts = split_email(mlist.bounces_address)
    probe_sender = Template(config.mta.verp_probe_format).safe_substitute(
        bounces=mailbox,
        token=token,
        domain=DOT.join(domain_parts),
        )
    # Calculate the Subject header, in the member's preferred language.
    with _.using(member.preferred_language.code):
        subject = _('$mlist.display_name mailing list probe message')
    # Craft the probe message.  This will be a multipart where the first part
    # is the probe text and the second part is the message that caused this
    # probe to be sent.
    probe = UserNotification(member.address.email, probe_sender,
                             subject, lang=member.preferred_language)
    probe.set_type('multipart/mixed')
    notice = MIMEText(text, _charset=mlist.preferred_language.charset)
    probe.attach(notice)
    probe.attach(MIMEMessage(msg))
    # Probes should not have the Precedence: bulk header.
    probe.send(mlist, envsender=probe_sender, verp=False, probe_token=token,
               add_precedence=False)
    return token
开发者ID:maxking,项目名称:mailman,代码行数:50,代码来源:bounces.py

示例13: send_goodbye_message

def send_goodbye_message(mlist, address, language):
    """Send a goodbye message to a subscriber.

    Prepending to the standard goodbye message template is the mailing list's
    goodbye message, if there is one.

    :param mlist: the mailing list
    :type mlist: IMailingList
    :param address: The address to respond to
    :type address: string
    :param language: the language of the response
    :type language: string
    """
    goodbye_message = _get_message(mlist.goodbye_message_uri,
                                   mlist, language)
    msg = UserNotification(
        address, mlist.bounces_address,
        _('You have been unsubscribed from the $mlist.display_name '
          'mailing list'),
        goodbye_message, language)
    msg.send(mlist, verp=as_boolean(config.mta.verp_personalized_deliveries))
开发者ID:P-EB,项目名称:mailman3-core,代码行数:21,代码来源:notifications.py

示例14: process

 def process(self, mlist, msg, msgdata):
     """See `IHandler`."""
     # Extract the sender's address and find them in the user database
     sender = msgdata.get('original_sender', msg.sender)
     member = mlist.members.get_member(sender)
     if member is None or not member.acknowledge_posts:
         # Either the sender is not a member, in which case we can't know
         # whether they want an acknowlegment or not, or they are a member
         # who definitely does not want an acknowlegment.
         return
     # Okay, they are a member that wants an acknowledgment of their post.
     # Give them their original subject.  BAW: do we want to use the
     # decoded header?
     original_subject = msgdata.get(
         'origsubj', msg.get('subject', _('(no subject)')))
     # Get the user's preferred language.
     language_manager = getUtility(ILanguageManager)
     language = (language_manager[msgdata['lang']]
                 if 'lang' in msgdata
                 else member.preferred_language)
     charset = language_manager[language.code].charset
     # Now get the acknowledgement template.
     display_name = mlist.display_name
     text = make('postack.txt',
                 mailing_list=mlist,
                 language=language.code,
                 wrap=False,
                 subject=oneline(original_subject, charset),
                 list_name=mlist.list_name,
                 display_name=display_name,
                 listinfo_url=mlist.script_url('listinfo'),
                 optionsurl=member.options_url,
                 )
     # Craft the outgoing message, with all headers and attributes
     # necessary for general delivery.  Then enqueue it to the outgoing
     # queue.
     subject = _('$display_name post acknowledgment')
     usermsg = UserNotification(sender, mlist.bounces_address,
                                subject, text, language)
     usermsg.send(mlist)
开发者ID:aregee,项目名称:Mailman,代码行数:40,代码来源:acknowledge.py

示例15: handle_ConfirmationNeededEvent

def handle_ConfirmationNeededEvent(event):
    if not isinstance(event, ConfirmationNeededEvent):
        return
    # There are three ways for a user to confirm their subscription.  They
    # can reply to the original message and let the VERP'd return address
    # encode the token, they can reply to the robot and keep the token in
    # the Subject header, or they can click on the URL in the body of the
    # message and confirm through the web.
    subject = 'confirm ' + event.token
    confirm_address = event.mlist.confirm_address(event.token)
    # For i18n interpolation.
    confirm_url = event.mlist.domain.confirm_url(event.token)
    email_address = event.email
    domain_name = event.mlist.domain.mail_host
    contact_address = event.mlist.owner_address
    # Send a verification email to the address.
    template = getUtility(ITemplateLoader).get(
        'mailman:///{0}/{1}/confirm.txt'.format(
            event.mlist.fqdn_listname,
            event.mlist.preferred_language.code))
    text = _(template)
    msg = UserNotification(email_address, confirm_address, subject, text)
    msg.send(event.mlist, add_precedence=False)
开发者ID:P-EB,项目名称:mailman3-core,代码行数:23,代码来源:registrar.py


注:本文中的mailman.email.message.UserNotification类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。