Beispiel #1
0
    def GET_s(self, urloid):
        """/s/http://..., show a given URL with the toolbar. if it's
           submitted, redirect to /tb/$id36"""
        force_html()
        path = demangle_url(request.fullpath)

        if not path:
            # it was malformed
            self.abort404()

        # if the domain is shame-banned, bail out.
        if is_shamed_domain(path)[0]:
            self.abort404()

        listing = hot_links_by_url_listing(path, sr=c.site, num=1)
        link = listing.things[0] if listing.things else None

        if link:
            # we were able to find it, let's send them to the
            # toolbar (if enabled) or comments (if not)
            return self.redirect(add_sr("/tb/" + link._id36))
        else:
            # It hasn't been submitted yet. Give them a chance to
            qs = utils.query_string({"url": path})
            return self.redirect(add_sr("/submit" + qs))
Beispiel #2
0
def valid_feed(name, feedhash, path):
    if name and feedhash and path:
        from v1.lib.template_helpers import add_sr
        path = add_sr(path)
        try:
            user = Account._by_name(name)
            if (user.pref_private_feeds and constant_time_compare(
                    feedhash, make_feedhash(user, path))):
                return user
        except NotFound:
            pass
Beispiel #3
0
 def GET_wiki_discussions(self, page, num, after, reverse, count):
     """Retrieve a list of discussions about this wiki `page`"""
     page_url = add_sr("%s/%s" % (c.wiki_base_url, page.name))
     builder = url_links_builder(page_url,
                                 num=num,
                                 after=after,
                                 reverse=reverse,
                                 count=count)
     listing = LinkListing(builder).listing()
     return WikiDiscussions(listing,
                            page=page.name,
                            may_revise=this_may_revise(page)).render()
Beispiel #4
0
    def intermediate_redirect(cls, form_path, sr_path=True, fullpath=None):
        """
        Generates a /login or /over18 redirect from the specified or current
        fullpath, after having properly reformated the path via
        format_output_url.  The reformatted original url is encoded
        and added as the "dest" parameter of the new url.
        """
        from v1.lib.template_helpers import add_sr
        params = dict(dest=cls.format_output_url(fullpath or request.fullurl))
        if c.extension == "widget" and request.GET.get("callback"):
            params['callback'] = request.GET.get("callback")

        path = add_sr(cls.format_output_url(form_path) + query_string(params),
                      sr_path=sr_path)
        abort(302, location=path)
Beispiel #5
0
 def GET_goto(self, link1, link2):
     """Support old /goto?id= urls. deprecated"""
     link = link2 if link2 else link1
     if link:
         return self.redirect(add_sr("/tb/" + link._id36))
     return self.abort404()
Beispiel #6
0
 def add_ext_to_link(link):
     url = UrlParser(link.get('href'))
     if url.is_verbify_url():
         link['href'] = add_sr(link.get('href'), sr_path=False)
Beispiel #7
0
def _absolute_url(path):
    return add_sr(path, force_https=True, sr_path=False)
Beispiel #8
0
def send_modmail_email(message):
    if not message.sr_id:
        return

    sr = Subverbify._byID(message.sr_id, data=True)

    forwarding_email = g.live_config['modmail_forwarding_email'].get(sr.name)
    if not forwarding_email:
        return

    sender = Account._byID(message.author_id, data=True)

    if sender.name in g.admins:
        distinguish = "[A]"
    elif sr.is_moderator(sender):
        distinguish = "[M]"
    else:
        distinguish = None

    if distinguish:
        from_address = "u/{username} {distinguish} <{sender_email}>".format(
            username=sender.name,
            distinguish=distinguish,
            sender_email=g.modmail_sender_email)
    else:
        from_address = "u/{username} <{sender_email}>".format(
            username=sender.name, sender_email=g.modmail_sender_email)

    reply_to = get_reply_to_address(message)
    parent_email_id, other_email_ids = get_email_ids(message)
    subject = get_message_subject(message)

    if message.from_sr and not message.first_message:
        # this is a message from the subverbify to a user. add some text that
        # shows the recipient
        recipient = Account._byID(message.to_id, data=True)
        sender_text = ("This message was sent from r/{subverbify} to "
                       "u/{user}").format(subverbify=sr.name,
                                          user=recipient.name)
    else:
        userlink = add_sr("/u/{name}".format(name=sender.name), sr_path=False)
        sender_text = "This message was sent by {userlink}".format(
            userlink=userlink, )

    reply_footer = (
        "\n\n-\n{sender_text}\n\n"
        "Reply to this email directly or view it on verbify: {link}")
    reply_footer = reply_footer.format(
        sender_text=sender_text,
        link=message.make_permalink(force_domain=True),
    )
    message_text = message.body + reply_footer

    email_id = g.email_provider.send_email(
        to_address=forwarding_email,
        from_address=from_address,
        subject=subject,
        text=message_text,
        reply_to=reply_to,
        parent_email_id=parent_email_id,
        other_email_ids=other_email_ids,
    )
    if email_id:
        g.log.info("sent %s as %s", message._id36, email_id)
        message.email_id = email_id
        message._commit()
        g.stats.simple_event("modmail_email.outgoing_email")