예제 #1
0
파일: members.py 프로젝트: lslaz1/karl
def _send_aeu_emails(community, community_href, profiles, text):
    # To make reading the add_existing_user_view easier, move the mail
    # delivery part here.

    info = _get_common_email_info(community, community_href)
    subject_fmt = 'You have been added to the %s community'
    subject = subject_fmt % info['c_title']
    body_template = get_renderer(
        'templates/email_add_existing.pt').implementation()
    html_body = text

    mailer = getUtility(IMailDelivery)
    for profile in profiles:
        to_email = profile.email

        msg = MIMEMultipart('alternative')
        msg['From'] = info['mfrom']
        msg['To'] = to_email
        msg['Subject'] = subject
        bodyhtml = body_template(
            system_name=info['system_name'],
            community_href=info['c_href'],
            community_name=info['c_title'],
            community_description=info['c_description'],
            personal_message=html_body,
            )
        bodyplain = html2text.html2text(bodyhtml)
        htmlpart = MIMEText(bodyhtml.encode('UTF-8'), 'html', 'UTF-8')
        plainpart = MIMEText(bodyplain.encode('UTF-8'), 'plain', 'UTF-8')
        msg.attach(plainpart)
        msg.attach(htmlpart)
        mailer.send([to_email], msg)
예제 #2
0
파일: members.py 프로젝트: lslaz1/karl
    def send_mail(self, username, profile):
        site = find_site(self.context)
        title = get_setting(self.context, 'title')
        subject = 'Thank you for joining %s' % title
        body_template = get_renderer(
            'templates/email_accept_site_invitation.pt').implementation()

        system_email_domain = get_setting(self.context, 'system_email_domain')
        from_name = '%s invitation' % title
        from_email = 'invitation@%s' % system_email_domain
        mailer = getUtility(IMailDelivery)
        msg = MIMEMultipart('alternative')
        msg['From'] = '%s <%s>' % (from_name, from_email)
        msg['To'] = profile.email
        msg['Subject'] = subject
        bodyhtml = body_template(
            username=username,
            site_href=resource_url(site, self.request),
            system_name=title
            )
        bodyplain = html2text.html2text(bodyhtml)
        htmlpart = MIMEText(bodyhtml.encode('UTF-8'), 'html', 'UTF-8')
        plainpart = MIMEText(bodyplain.encode('UTF-8'), 'plain', 'UTF-8')
        msg.attach(plainpart)
        msg.attach(htmlpart)
        mailer.send([profile.email], msg)
예제 #3
0
파일: members.py 프로젝트: lslaz1/karl
def send_invitation_email(request, community, community_href, invitation):
    mailer = getUtility(IMailDelivery)
    info = _get_common_email_info(community, community_href)
    subject_fmt = 'Please join the %s community at %s'
    info['subject'] = subject_fmt % (info['c_title'],
                                     info['system_name'])
    body_template = get_renderer(
        'templates/email_invite_new.pt').implementation()

    msg = MIMEMultipart('alternative')
    msg['From'] = info['mfrom']
    msg['To'] = invitation.email
    msg['Subject'] = info['subject']
    bodyhtml = body_template(
        system_name=info['system_name'],
        community_href=info['c_href'],
        community_name=info['c_title'],
        community_description=info['c_description'],
        personal_message=invitation.message,
        invitation_url=resource_url(invitation.__parent__, request,
                                    invitation.__name__)
        )
    bodyplain = html2text.html2text(bodyhtml)
    htmlpart = MIMEText(bodyhtml.encode('UTF-8'), 'html', 'UTF-8')
    plainpart = MIMEText(bodyplain.encode('UTF-8'), 'plain', 'UTF-8')
    msg.attach(plainpart)
    msg.attach(htmlpart)
    mailer.send([invitation.email], msg)
예제 #4
0
파일: members.py 프로젝트: lslaz1/karl
def _send_ai_email(community, community_href, username, profile):
    """Send email to user who has accepted a community invitation.
    """
    info = _get_common_email_info(community, community_href)
    subject_fmt = 'Thank you for joining the %s community'
    subject = subject_fmt % info['c_title']
    body_template = get_renderer(
        'templates/email_accept_invitation.pt').implementation()

    mailer = getUtility(IMailDelivery)
    msg = MIMEMultipart('alternative')
    msg['From'] = info['mfrom']
    msg['To'] = profile.email
    msg['Subject'] = subject
    bodyhtml = body_template(
        community_href=info['c_href'],
        community_name=info['c_title'],
        community_description=info['c_description'],
        username=username,
        )
    bodyplain = html2text.html2text(bodyhtml)
    htmlpart = MIMEText(bodyhtml.encode('UTF-8'), 'html', 'UTF-8')
    plainpart = MIMEText(bodyplain.encode('UTF-8'), 'plain', 'UTF-8')
    msg.attach(plainpart)
    msg.attach(htmlpart)
    mailer.send([profile.email], msg)
예제 #5
0
def request_password_reset(user, profile, request):
    profile.password_reset_key = sha1(
        str(random.random())).hexdigest()
    profile.password_reset_time = datetime.datetime.now()
    context = find_site(profile)
    reset_url = resource_url(
        context, request, "reset_confirm.html",
        query=dict(key=profile.password_reset_key))

    # send email
    mail = MIMEMultipart('alternative')
    system_name = get_setting(context, 'title', 'KARL')
    admin_email = get_setting(context, 'admin_email')
    mail["From"] = "%s Administrator <%s>" % (system_name, admin_email)
    mail["To"] = "%s <%s>" % (profile.title, profile.email)
    mail["Subject"] = "%s Password Reset Request" % system_name
    bodyhtml = render(
        "templates/email_reset_password.pt",
        dict(login=user['login'],
             reset_url=reset_url,
             system_name=system_name),
        request=request,
    )
    bodyplain = html2text.html2text(bodyhtml)
    htmlpart = MIMEText(bodyhtml.encode('UTF-8'), 'html', 'UTF-8')
    plainpart = MIMEText(bodyplain.encode('UTF-8'), 'plain', 'UTF-8')
    mail.attach(plainpart)
    mail.attach(htmlpart)
    recipients = [profile.email]
    mailer = getUtility(IMailDelivery)
    mailer.send(recipients, mail)
예제 #6
0
파일: utils.py 프로젝트: lslaz1/karl
def create_message(request, subject, html, from_email, mailify=True):
    message = MIMEMultipart('alternative')
    message['From'] = from_email
    message['Subject'] = subject

    if mailify:
        mailify_html(request, html, message)
    else:
        body_html = u'<html><body>%s</body></html>' % html
        bodyplain = html2text.html2text(body_html)
        message.attach(MIMEText(bodyplain.encode('UTF-8'), 'plain', 'UTF-8'))
        message.attach(MIMEText(body_html.encode('UTF-8'), 'html', 'UTF-8'))

    for k in request.params.keys():
        if k.startswith("attachment"):
            tmpattachment = request.params[k]
            if tmpattachment.filename:
                if tmpattachment.filename.endswith(
                    ('.png', '.tiff', '.gif', '.bmp', 'jpeg', '.tif', '.jpg')):
                    attachment = MIMEImage(tmpattachment.value)
                elif tmpattachment.filename.endswith(('.pdf', '.zip')):
                    attachment = MIMEApplication(tmpattachment.value)
                else:
                    attachment = MIMEText(tmpattachment.value)
                attachment.add_header('Content-Disposition',
                                      'attachment',
                                      filename=tmpattachment.filename)
                message.attach(attachment)

    return message
예제 #7
0
파일: utils.py 프로젝트: lslaz1/karl
def create_message(request, subject, html, from_email, mailify=True):
    message = MIMEMultipart('alternative')
    message['From'] = from_email
    message['Subject'] = subject

    if mailify:
        mailify_html(request, html, message)
    else:
        body_html = u'<html><body>%s</body></html>' % html
        bodyplain = html2text.html2text(body_html)
        message.attach(MIMEText(bodyplain.encode('UTF-8'), 'plain', 'UTF-8'))
        message.attach(MIMEText(body_html.encode('UTF-8'), 'html', 'UTF-8'))

    for k in request.params.keys():
        if k.startswith("attachment"):
            tmpattachment = request.params[k]
            if tmpattachment.filename:
                if tmpattachment.filename.endswith(('.png', '.tiff', '.gif', '.bmp', 'jpeg', '.tif', '.jpg')):
                    attachment = MIMEImage(tmpattachment.value)
                elif tmpattachment.filename.endswith(('.pdf', '.zip')):
                    attachment = MIMEApplication(tmpattachment.value)
                else:
                    attachment = MIMEText(tmpattachment.value)
                attachment.add_header('Content-Disposition',
                                      'attachment',
                                      filename=tmpattachment.filename)
                message.attach(attachment)

    return message
예제 #8
0
파일: twofactor.py 프로젝트: lslaz1/karl
 def send_mail_code(self, profile):
     mailer = getUtility(IMailDelivery)
     message = MIMEMultipart('alternative')
     message['From'] = get_setting(self.context, 'admin_email')
     message['To'] = '%s <%s>' % (profile.title, profile.email)
     message['Subject'] = '%s Authorization Request' % self.context.title
     bodyhtml = u'''<html><body>
 <p>An authorization code has been requested for the site %s.</p>
 <p>Authorization Code: <b>%s</b></p>
 </body></html>''' % (
         self.request.application_url,
         profile.current_auth_code
     )
     bodyplain = html2text.html2text(bodyhtml)
     htmlpart = MIMEText(bodyhtml.encode('UTF-8'), 'html', 'UTF-8')
     plainpart = MIMEText(bodyplain.encode('UTF-8'), 'plain', 'UTF-8')
     message.attach(plainpart)
     message.attach(htmlpart)
     mailer.send([profile.email], message)
예제 #9
0
def _send_moderators_changed_email(community, community_href, new_moderators,
                                   old_moderators, cur_moderators,
                                   prev_moderators):
    info = _get_common_email_info(community, community_href)
    subject_fmt = 'Change in moderators for %s'
    subject = subject_fmt % info['c_title']
    body_template = get_renderer(
        'templates/email_moderators_changed.pt').implementation()

    profiles = find_profiles(community)
    all_moderators = cur_moderators | prev_moderators
    to_profiles = [profiles[name] for name in all_moderators]
    to_addrs = ["%s <%s>" % (p.title, p.email) for p in to_profiles]

    mailer = getUtility(IMailDelivery)
    msg = MIMEMultipart('alternative')
    msg['From'] = info['mfrom']
    msg['To'] = ",".join(to_addrs)
    msg['Subject'] = subject
    bodyhtml = body_template(
        system_name=info['system_name'],
        community_href=info['c_href'],
        community_name=info['c_title'],
        new_moderators=[profiles[name].title for name in new_moderators],
        old_moderators=[profiles[name].title for name in old_moderators],
        cur_moderators=[profiles[name].title for name in cur_moderators],
        prev_moderators=[profiles[name].title for name in prev_moderators])
    bodyplain = html2text.html2text(bodyhtml)
    htmlpart = MIMEText(bodyhtml.encode('UTF-8'), 'html', 'UTF-8')
    plainpart = MIMEText(bodyplain.encode('UTF-8'), 'plain', 'UTF-8')
    msg.attach(plainpart)
    msg.attach(htmlpart)
    mailer.send(to_addrs, msg)
예제 #10
0
def _send_ai_email(community, community_href, username, profile):
    """Send email to user who has accepted a community invitation.
    """
    info = _get_common_email_info(community, community_href)
    subject_fmt = 'Thank you for joining the %s community'
    subject = subject_fmt % info['c_title']
    body_template = get_renderer(
        'templates/email_accept_invitation.pt').implementation()

    mailer = getUtility(IMailDelivery)
    msg = MIMEMultipart('alternative')
    msg['From'] = info['mfrom']
    msg['To'] = profile.email
    msg['Subject'] = subject
    bodyhtml = body_template(
        community_href=info['c_href'],
        community_name=info['c_title'],
        community_description=info['c_description'],
        username=username,
    )
    bodyplain = html2text.html2text(bodyhtml)
    htmlpart = MIMEText(bodyhtml.encode('UTF-8'), 'html', 'UTF-8')
    plainpart = MIMEText(bodyplain.encode('UTF-8'), 'plain', 'UTF-8')
    msg.attach(plainpart)
    msg.attach(htmlpart)
    mailer.send([profile.email], msg)
예제 #11
0
def _send_aeu_emails(community, community_href, profiles, text):
    # To make reading the add_existing_user_view easier, move the mail
    # delivery part here.

    info = _get_common_email_info(community, community_href)
    subject_fmt = 'You have been added to the %s community'
    subject = subject_fmt % info['c_title']
    body_template = get_renderer(
        'templates/email_add_existing.pt').implementation()
    html_body = text

    mailer = getUtility(IMailDelivery)
    for profile in profiles:
        to_email = profile.email

        msg = MIMEMultipart('alternative')
        msg['From'] = info['mfrom']
        msg['To'] = to_email
        msg['Subject'] = subject
        bodyhtml = body_template(
            system_name=info['system_name'],
            community_href=info['c_href'],
            community_name=info['c_title'],
            community_description=info['c_description'],
            personal_message=html_body,
        )
        bodyplain = html2text.html2text(bodyhtml)
        htmlpart = MIMEText(bodyhtml.encode('UTF-8'), 'html', 'UTF-8')
        plainpart = MIMEText(bodyplain.encode('UTF-8'), 'plain', 'UTF-8')
        msg.attach(plainpart)
        msg.attach(htmlpart)
        mailer.send([to_email], msg)
예제 #12
0
def request_password_reset(user, profile, request):
    profile.password_reset_key = sha1(str(random.random())).hexdigest()
    profile.password_reset_time = datetime.datetime.now()
    context = find_site(profile)
    reset_url = resource_url(context,
                             request,
                             "reset_confirm.html",
                             query=dict(key=profile.password_reset_key))

    # send email
    mail = MIMEMultipart('alternative')
    system_name = get_setting(context, 'title', 'KARL')
    admin_email = get_setting(context, 'admin_email')
    mail["From"] = "%s Administrator <%s>" % (system_name, admin_email)
    mail["To"] = "%s <%s>" % (profile.title, profile.email)
    mail["Subject"] = "%s Password Reset Request" % system_name
    bodyhtml = render(
        "templates/email_reset_password.pt",
        dict(login=user['login'], reset_url=reset_url,
             system_name=system_name),
        request=request,
    )
    bodyplain = html2text.html2text(bodyhtml)
    htmlpart = MIMEText(bodyhtml.encode('UTF-8'), 'html', 'UTF-8')
    plainpart = MIMEText(bodyplain.encode('UTF-8'), 'plain', 'UTF-8')
    mail.attach(plainpart)
    mail.attach(htmlpart)
    recipients = [profile.email]
    mailer = getUtility(IMailDelivery)
    mailer.send(recipients, mail)
예제 #13
0
def send_invitation_email(request, community, community_href, invitation):
    mailer = getUtility(IMailDelivery)
    info = _get_common_email_info(community, community_href)
    subject_fmt = 'Please join the %s community at %s'
    info['subject'] = subject_fmt % (info['c_title'], info['system_name'])
    body_template = get_renderer(
        'templates/email_invite_new.pt').implementation()

    msg = MIMEMultipart('alternative')
    msg['From'] = info['mfrom']
    msg['To'] = invitation.email
    msg['Subject'] = info['subject']
    bodyhtml = body_template(system_name=info['system_name'],
                             community_href=info['c_href'],
                             community_name=info['c_title'],
                             community_description=info['c_description'],
                             personal_message=invitation.message,
                             invitation_url=resource_url(
                                 invitation.__parent__, request,
                                 invitation.__name__))
    bodyplain = html2text.html2text(bodyhtml)
    htmlpart = MIMEText(bodyhtml.encode('UTF-8'), 'html', 'UTF-8')
    plainpart = MIMEText(bodyplain.encode('UTF-8'), 'plain', 'UTF-8')
    msg.attach(plainpart)
    msg.attach(htmlpart)
    mailer.send([invitation.email], msg)
예제 #14
0
파일: members.py 프로젝트: lslaz1/karl
def _send_moderators_changed_email(community,
                                   community_href,
                                   new_moderators,
                                   old_moderators,
                                   cur_moderators,
                                   prev_moderators):
    info = _get_common_email_info(community, community_href)
    subject_fmt = 'Change in moderators for %s'
    subject = subject_fmt % info['c_title']
    body_template = get_renderer(
        'templates/email_moderators_changed.pt').implementation()

    profiles = find_profiles(community)
    all_moderators = cur_moderators | prev_moderators
    to_profiles = [profiles[name] for name in all_moderators]
    to_addrs = ["%s <%s>" % (p.title, p.email) for p in to_profiles]

    mailer = getUtility(IMailDelivery)
    msg = MIMEMultipart('alternative')
    msg['From'] = info['mfrom']
    msg['To'] = ",".join(to_addrs)
    msg['Subject'] = subject
    bodyhtml = body_template(
        system_name=info['system_name'],
        community_href=info['c_href'],
        community_name=info['c_title'],
        new_moderators=[profiles[name].title for name in new_moderators],
        old_moderators=[profiles[name].title for name in old_moderators],
        cur_moderators=[profiles[name].title for name in cur_moderators],
        prev_moderators=[profiles[name].title for name in prev_moderators]
        )
    bodyplain = html2text.html2text(bodyhtml)
    htmlpart = MIMEText(bodyhtml.encode('UTF-8'), 'html', 'UTF-8')
    plainpart = MIMEText(bodyplain.encode('UTF-8'), 'plain', 'UTF-8')
    msg.attach(plainpart)
    msg.attach(htmlpart)
    mailer.send(to_addrs, msg)
예제 #15
0
파일: twofactor.py 프로젝트: lslaz1/karl
 def send_mail_code(self, profile):
     mailer = getUtility(IMailDelivery)
     message = MIMEMultipart('alternative')
     message['From'] = get_setting(self.context, 'admin_email')
     message['To'] = '%s <%s>' % (profile.title, profile.email)
     message['Subject'] = '%s Authorization Request' % self.context.title
     bodyhtml = u'''<html><body>
 <p>An authorization code has been requested for the site %s.</p>
 <p>Authorization Code: <b>%s</b></p>
 </body></html>''' % (self.request.application_url,
                      profile.current_auth_code)
     bodyplain = html2text.html2text(bodyhtml)
     htmlpart = MIMEText(bodyhtml.encode('UTF-8'), 'html', 'UTF-8')
     plainpart = MIMEText(bodyplain.encode('UTF-8'), 'plain', 'UTF-8')
     message.attach(plainpart)
     message.attach(htmlpart)
     mailer.send([profile.email], message)
예제 #16
0
    def send_mail(self, username, profile):
        site = find_site(self.context)
        title = get_setting(self.context, 'title')
        subject = 'Thank you for joining %s' % title
        body_template = get_renderer(
            'templates/email_accept_site_invitation.pt').implementation()

        system_email_domain = get_setting(self.context, 'system_email_domain')
        from_name = '%s invitation' % title
        from_email = 'invitation@%s' % system_email_domain
        mailer = getUtility(IMailDelivery)
        msg = MIMEMultipart('alternative')
        msg['From'] = '%s <%s>' % (from_name, from_email)
        msg['To'] = profile.email
        msg['Subject'] = subject
        bodyhtml = body_template(username=username,
                                 site_href=resource_url(site, self.request),
                                 system_name=title)
        bodyplain = html2text.html2text(bodyhtml)
        htmlpart = MIMEText(bodyhtml.encode('UTF-8'), 'html', 'UTF-8')
        plainpart = MIMEText(bodyplain.encode('UTF-8'), 'plain', 'UTF-8')
        msg.attach(plainpart)
        msg.attach(htmlpart)
        mailer.send([profile.email], msg)
예제 #17
0
파일: adapters.py 프로젝트: lslaz1/karl
    def message(self):
        if self._message is not None:
            return self._message

        community = self._community
        request = self.request
        profile = self.profile
        blogentry = self._blogentry

        community_href = resource_url(community, request)
        blogentry_href = resource_url(blogentry, request)
        manage_preferences_href = resource_url(profile, request) + '/manage_communities.html'  # noqa
        system_name = get_setting(self.context, "title", "KARL")
        system_email_domain = get_setting(self.context, "system_email_domain")

        reply_to = '"%s" <%s+blog-%s@%s>' % (community.title,
                                             community.__name__,
                                             docid_to_hex(blogentry.docid),
                                             system_email_domain)

        attachments, attachment_links, attachment_hrefs = self.attachments

        from_name = "%s | %s" % (self.creator.title, system_name)
        msg = MIMEMultipart() if attachments else Message()
        msg["From"] = '"%s" <%s>' % (from_name, self.mfrom)
        msg["To"] = '"%s" <%s>' % (profile.title, profile.email)
        msg["Reply-to"] = reply_to
        msg["Subject"] = self._subject
        msg["Precedence"] = 'bulk'
        body_text = self.template(
            context=self.context,
            community=community,
            community_href=community_href,
            blogentry=blogentry,
            blogentry_href=blogentry_href,
            attachments=attachment_links,
            attachment_hrefs=attachment_hrefs,
            manage_preferences_href=manage_preferences_href,
            profile=profile,
            profiles=self.profiles,
            creator=self.creator,
            digest=self.digest,
            alert=self,
            history=self._history,
            reply_enabled=self.reply_enabled
        )

        if self.digest:
            # Only interested in body for digest
            html = document_fromstring(body_text)
            body_element = html.cssselect('body')[0]
            span = etree.Element("span", nsmap=body_element.nsmap)
            span[:] = body_element[:]  # Copy all body elements to an empty span
            body_text = etree.tostring(span, pretty_print=True)

        if isinstance(body_text, unicode):
            body_text = body_text.encode('utf-8')

        if attachments:
            body = MIMEText(body_text, 'html', 'utf-8')
            msg.attach(body)
            for attachment in attachments:
                msg.attach(attachment)
        else:
            msg.set_payload(body_text, 'utf-8')
            msg.set_type("text/html")

        self._message = msg

        return self._message
예제 #18
0
파일: community.py 프로젝트: lslaz1/karl
def join_community_view(context, request):
    """ User sends an email to community moderator(s) asking to join
    the community.  Email contains a link to "add_existing" view, in members,
    that a moderator can use to add member to the community.

    """
    assert ICommunity.providedBy(context)

    # Get logged in user
    profiles = find_profiles(context)
    user = authenticated_userid(request)
    profile = profiles[user]

    # first off, see if the community is public, in that case,
    # it does not need to be reviewed to join
    if has_permission('edit', context, request):
        community_users = find_users(context)
        if community_users:
            community_users.add_group(profile.__name__, context.members_group_name)
            status_message = "You have joined this community!"
            community_href = resource_url(context, request,
                                          query={"status_message": status_message})
            return HTTPFound(location=community_href)

    # Handle form submission
    if "form.submitted" in request.POST:
        message = request.POST.get("message", "")
        moderators = [profiles[id] for id in context.moderator_names]
        mail = MIMEMultipart('alternative')
        mail["From"] = "%s <%s>" % (profile.title, profile.email)
        mail["To"] = ",".join(
            ["%s <%s>" % (p.title, p.email) for p in moderators]
        )
        mail["Subject"] = "Request to join %s community" % context.title

        body_template = get_renderer(
            "templates/email_join_community.pt").implementation()
        profile_url = resource_url(profile, request)
        accept_url = resource_url(
            context, request, "members", "add_existing.html",
            query={"user_id": user})
        bodyhtml = body_template(
            message=message,
            community_title=context.title,
            person_name=profile.title,
            profile_url=profile_url,
            accept_url=accept_url
        )
        bodyplain = html2text.html2text(bodyhtml)
        htmlpart = MIMEText(bodyhtml.encode('UTF-8'), 'html', 'UTF-8')
        plainpart = MIMEText(bodyplain.encode('UTF-8'), 'plain', 'UTF-8')
        mail.attach(plainpart)
        mail.attach(htmlpart)

        recipients = [p.email for p in moderators]
        mailer = getUtility(IMailDelivery)
        mailer.send(recipients, mail)

        status_message = "Your request has been sent to the moderators."
        location = resource_url(
            context, request,
            query={"status_message": status_message})

        return HTTPFound(location=location)

    # Show form
    page_title = "Join " + context.title
    api = TemplateAPI(context, request, page_title)
    return dict(
        api=api,
        profile=profile,
        community=context,
        post_url=resource_url(context, request, "join.html"),
        formfields=api.formfields)
예제 #19
0
파일: adapters.py 프로젝트: Falmarri/karl
    def message(self):
        if self._message is not None:
            return self._message

        community = self._community
        request = self.request
        profile = self.profile
        model = self._model

        community_href = resource_url(community, request)
        model_href = resource_url(model, request)
        manage_preferences_href = resource_url(profile, request)
        system_name = get_setting(self.context, "system_name", "KARL")
        system_email_domain = get_setting(self.context, "system_email_domain")

        attachments, attachment_links, attachment_hrefs = self.attachments

        body_template = get_renderer(self._template).implementation()
        from_name = "%s | %s" % (self.creator.title, system_name)
        msg = MIMEMultipart() if attachments else Message()
        msg["From"] = '"%s" <%s>' % (from_name, self.mfrom)
        msg["To"] = '"%s" <%s>' % (community.title, profile.email)
        msg["Subject"] = self._subject
        msg["Precedence"] = 'bulk'
        body_text = body_template(
            context=self.context,
            community=community,
            community_href=community_href,
            model=model,
            model_href=model_href,
            manage_preferences_href=manage_preferences_href,
            attachments=attachment_links,
            attachment_hrefs=attachment_hrefs,
            profile=profile,
            creator=self.creator,
            content_type=self._content_type_name,
            digest=self.digest,
            alert=self,
        )

        if self.digest:
            # Only interested in body for digest
            html = document_fromstring(body_text)
            body_element = html.cssselect('body')[0]
            span = etree.Element("span", nsmap=body_element.nsmap)
            span[:] = body_element[:] # Copy all body elements to an empty span
            body_text = etree.tostring(span, pretty_print=True)

        if isinstance(body_text, unicode):
            body_text = body_text.encode('utf-8')

        if attachments:
            body = MIMEText(body_text, 'html', 'utf-8')
            msg.attach(body)
            for attachment in attachments:
                msg.attach(attachment)
        else:
            msg.set_payload(body_text, 'utf-8')
            msg.set_type("text/html")

        self._message = msg
        return msg
예제 #20
0
파일: login.py 프로젝트: lslaz1/karl
    def create_access_request(self):
        email = self.data.get('email')
        system_name = get_setting(self.context, 'title')
        self.context.access_requests[email] = self.data
        mailer = getUtility(IMailDelivery)
        message = MIMEMultipart('alternative')
        message['Subject'] = '%s Access Request(%s)' % (
            system_name, self.data.get('fullname'))
        message['From'] = get_setting(self.context, 'admin_email')
        bodyhtml = u'''<html><body>
<p>New access request has been submitted for the site %s</p>
<p><b>Email</b>: %s <br />
%s
</p>
</body></html>''' % (
            self.request.application_url,
            email,
            '<br />'.join([_email_field_tmp % (f['label'], self.data.get(f['id'], ''))
                           for f in self.fields])
        )
        bodyplain = html2text.html2text(bodyhtml)
        htmlpart = MIMEText(bodyhtml.encode('UTF-8'), 'html', 'UTF-8')
        plainpart = MIMEText(bodyplain.encode('UTF-8'), 'plain', 'UTF-8')
        message.attach(plainpart)
        message.attach(htmlpart)

        # First, send mail to all admins
        users = find_users(self.context)
        search = ICatalogSearch(self.context)
        count, docids, resolver = search(interfaces=[IProfile])
        for docid in docids:
            profile = resolver(docid)
            if getattr(profile, 'security_state', None) == 'inactive':
                continue
            userid = profile.__name__
            if not users.member_of_group(userid, 'group.KarlAdmin'):
                continue
            copyofmsg = copy.deepcopy(message)
            fullemail = '%s <%s>' % (profile.title, profile.email)
            copyofmsg['To'] = fullemail
            mailer.send([profile.email], copyofmsg)

        # next, send to person that submitted
        message = MIMEMultipart('alternative')
        message['Subject'] = 'Access Request to %s' % system_name
        message['From'] = get_setting(self.context, 'admin_email')
        user_message = get_setting(self.context, 'request_access_user_message', '') % (
            SafeDict(self.data, {
                'system_name': system_name
                }))
        bodyhtml = u'<html><body>%s</body></html>' % user_message
        bodyplain = html2text.html2text(bodyhtml)
        htmlpart = MIMEText(bodyhtml.encode('UTF-8'), 'html', 'UTF-8')
        plainpart = MIMEText(bodyplain.encode('UTF-8'), 'plain', 'UTF-8')
        message.attach(plainpart)
        message.attach(htmlpart)
        copyofmsg = copy.deepcopy(message)
        fullemail = '%s <%s>' % (self.data.get('fullname', ''), email)
        copyofmsg['To'] = fullemail
        mailer.send([email], copyofmsg)

        self.submitted = True
        self.errors.append('Successfully requested access')
예제 #21
0
파일: login.py 프로젝트: lslaz1/karl
    def create_access_request(self):
        email = self.data.get('email')
        system_name = get_setting(self.context, 'title')
        self.context.access_requests[email] = self.data
        mailer = getUtility(IMailDelivery)
        message = MIMEMultipart('alternative')
        message['Subject'] = '%s Access Request(%s)' % (
            system_name, self.data.get('fullname'))
        message['From'] = get_setting(self.context, 'admin_email')
        bodyhtml = u'''<html><body>
<p>New access request has been submitted for the site %s</p>
<p><b>Email</b>: %s <br />
%s
</p>
</body></html>''' % (self.request.application_url, email, '<br />'.join([
            _email_field_tmp % (f['label'], self.data.get(f['id'], ''))
            for f in self.fields
        ]))
        bodyplain = html2text.html2text(bodyhtml)
        htmlpart = MIMEText(bodyhtml.encode('UTF-8'), 'html', 'UTF-8')
        plainpart = MIMEText(bodyplain.encode('UTF-8'), 'plain', 'UTF-8')
        message.attach(plainpart)
        message.attach(htmlpart)

        # First, send mail to all admins
        users = find_users(self.context)
        search = ICatalogSearch(self.context)
        count, docids, resolver = search(interfaces=[IProfile])
        for docid in docids:
            profile = resolver(docid)
            if getattr(profile, 'security_state', None) == 'inactive':
                continue
            userid = profile.__name__
            if not users.member_of_group(userid, 'group.KarlAdmin'):
                continue
            copyofmsg = copy.deepcopy(message)
            fullemail = '%s <%s>' % (profile.title, profile.email)
            copyofmsg['To'] = fullemail
            mailer.send([profile.email], copyofmsg)

        # next, send to person that submitted
        message = MIMEMultipart('alternative')
        message['Subject'] = 'Access Request to %s' % system_name
        message['From'] = get_setting(self.context, 'admin_email')
        user_message = get_setting(
            self.context, 'request_access_user_message', '') % (SafeDict(
                self.data, {'system_name': system_name}))
        bodyhtml = u'<html><body>%s</body></html>' % user_message
        bodyplain = html2text.html2text(bodyhtml)
        htmlpart = MIMEText(bodyhtml.encode('UTF-8'), 'html', 'UTF-8')
        plainpart = MIMEText(bodyplain.encode('UTF-8'), 'plain', 'UTF-8')
        message.attach(plainpart)
        message.attach(htmlpart)
        copyofmsg = copy.deepcopy(message)
        fullemail = '%s <%s>' % (self.data.get('fullname', ''), email)
        copyofmsg['To'] = fullemail
        mailer.send([email], copyofmsg)

        self.submitted = True
        self.errors.append('Successfully requested access')
예제 #22
0
    def message(self):
        if self._message is not None:
            return self._message

        community = self._community
        request = self.request
        profile = self.profile
        blogentry = self._blogentry

        community_href = resource_url(community, request)
        blogentry_href = resource_url(blogentry, request)
        manage_preferences_href = resource_url(profile, request)
        system_name = get_setting(self.context, "system_name", "KARL")
        system_email_domain = get_setting(self.context, "system_email_domain")

        reply_to = '"%s" <%s+blog-%s@%s>' % (
            community.title, community.__name__, docid_to_hex(
                blogentry.docid), system_email_domain)

        attachments, attachment_links, attachment_hrefs = self.attachments

        body_template = get_renderer(self._template).implementation()
        from_name = "%s | %s" % (self.creator.title, system_name)
        msg = MIMEMultipart() if attachments else Message()
        msg["From"] = '"%s" <%s>' % (from_name, self.mfrom)
        msg["To"] = '"%s" <%s>' % (profile.title, profile.email)
        msg["Reply-to"] = reply_to
        msg["Subject"] = self._subject
        msg["Precedence"] = 'bulk'
        body_text = body_template(
            context=self.context,
            community=community,
            community_href=community_href,
            blogentry=blogentry,
            blogentry_href=blogentry_href,
            attachments=attachment_links,
            attachment_hrefs=attachment_hrefs,
            manage_preferences_href=manage_preferences_href,
            profile=profile,
            profiles=self.profiles,
            creator=self.creator,
            digest=self.digest,
            alert=self,
            history=self._history,
        )

        if self.digest:
            # Only interested in body for digest
            html = document_fromstring(body_text)
            body_element = html.cssselect('body')[0]
            span = etree.Element("span", nsmap=body_element.nsmap)
            span[:] = body_element[:]  # Copy all body elements to an empty span
            body_text = etree.tostring(span, pretty_print=True)

        if isinstance(body_text, unicode):
            body_text = body_text.encode('utf-8')

        if attachments:
            body = MIMEText(body_text, 'html', 'utf-8')
            msg.attach(body)
            for attachment in attachments:
                msg.attach(attachment)
        else:
            msg.set_payload(body_text, 'utf-8')
            msg.set_type("text/html")

        self._message = msg

        return self._message
예제 #23
0
    def message(self):
        if self._message is not None:
            return self._message

        community = self._community
        request = self.request
        profile = self.profile
        model = self._model

        community_href = resource_url(community, request)
        model_href = resource_url(model, request)
        manage_preferences_href = resource_url(
            profile, request) + '/manage_communities.html'  # noqa
        system_name = get_setting(self.context, "title", "KARL")

        attachments, attachment_links, attachment_hrefs = self.attachments

        from_name = "%s | %s" % (self.creator.title, system_name)
        msg = MIMEMultipart() if attachments else Message()
        msg["From"] = '"%s" <%s>' % (from_name, self.mfrom)
        msg["To"] = '"%s" <%s>' % (community.title, profile.email)
        msg["Subject"] = self._subject
        msg["Precedence"] = 'bulk'
        body_text = self.template(
            context=self.context,
            community=community,
            community_href=community_href,
            model=model,
            model_href=model_href,
            manage_preferences_href=manage_preferences_href,
            attachments=attachment_links,
            attachment_hrefs=attachment_hrefs,
            profile=profile,
            profiles=self.profiles,
            creator=self.creator,
            content_type=self._content_type_name,
            digest=self.digest,
            alert=self,
            resource_url=resource_url,
            request=request,
            reply_enabled=self.reply_enabled)

        if self.digest:
            # Only interested in body for digest
            html = document_fromstring(body_text)
            body_element = html.cssselect('body')[0]
            span = etree.Element("span", nsmap=body_element.nsmap)
            span[:] = body_element[:]  # Copy all body elements to an empty span
            body_text = etree.tostring(span, pretty_print=True)

        if isinstance(body_text, unicode):
            body_text = body_text.encode('utf-8')

        if attachments:
            body = MIMEText(body_text, 'html', 'utf-8')
            msg.attach(body)
            for attachment in attachments:
                msg.attach(attachment)
        else:
            msg.set_payload(body_text, 'utf-8')
            msg.set_type("text/html")

        self._message = msg
        return msg
예제 #24
0
파일: community.py 프로젝트: lslaz1/karl
def join_community_view(context, request):
    """ User sends an email to community moderator(s) asking to join
    the community.  Email contains a link to "add_existing" view, in members,
    that a moderator can use to add member to the community.

    """
    assert ICommunity.providedBy(context)

    # Get logged in user
    profiles = find_profiles(context)
    user = authenticated_userid(request)
    profile = profiles[user]

    # first off, see if the community is public, in that case,
    # it does not need to be reviewed to join
    if has_permission('edit', context, request):
        community_users = find_users(context)
        if community_users:
            community_users.add_group(profile.__name__,
                                      context.members_group_name)
            status_message = "You have joined this community!"
            community_href = resource_url(
                context, request, query={"status_message": status_message})
            return HTTPFound(location=community_href)

    # Handle form submission
    if "form.submitted" in request.POST:
        message = request.POST.get("message", "")
        moderators = [profiles[id] for id in context.moderator_names]
        mail = MIMEMultipart('alternative')
        mail["From"] = "%s <%s>" % (profile.title, profile.email)
        mail["To"] = ",".join(
            ["%s <%s>" % (p.title, p.email) for p in moderators])
        mail["Subject"] = "Request to join %s community" % context.title

        body_template = get_renderer(
            "templates/email_join_community.pt").implementation()
        profile_url = resource_url(profile, request)
        accept_url = resource_url(context,
                                  request,
                                  "members",
                                  "add_existing.html",
                                  query={"user_id": user})
        bodyhtml = body_template(message=message,
                                 community_title=context.title,
                                 person_name=profile.title,
                                 profile_url=profile_url,
                                 accept_url=accept_url)
        bodyplain = html2text.html2text(bodyhtml)
        htmlpart = MIMEText(bodyhtml.encode('UTF-8'), 'html', 'UTF-8')
        plainpart = MIMEText(bodyplain.encode('UTF-8'), 'plain', 'UTF-8')
        mail.attach(plainpart)
        mail.attach(htmlpart)

        recipients = [p.email for p in moderators]
        mailer = getUtility(IMailDelivery)
        mailer.send(recipients, mail)

        status_message = "Your request has been sent to the moderators."
        location = resource_url(context,
                                request,
                                query={"status_message": status_message})

        return HTTPFound(location=location)

    # Show form
    page_title = "Join " + context.title
    api = TemplateAPI(context, request, page_title)
    return dict(api=api,
                profile=profile,
                community=context,
                post_url=resource_url(context, request, "join.html"),
                formfields=api.formfields)