<commit_before>#!/usr/bin/python2.5
# -*- coding: utf-8 -*-
"""
 gettor_config.py - Parse configuration file for gettor

 Copyright (c) 2008, <NAME> <<EMAIL>>, 
                     <NAME> <<EMAIL>>

 This is Free Software. See LICENSE for license information.

 This library implements all of the email replying features needed for gettor. 
"""

import os
import smtplib
import MimeWriter
import StringIO
import base64
import gettext

import gettor.gtlog

__all__ = ["gettorResponse"]

log = gettor.gtlog.getLogger()

class gettorResponse:

    def __init__(self, config, mailLang="en", logLang="en"):
        self.mailLang = mailLang
        self.logLang = logLang
        self.config = config

    def setLang(self, language):
        # XXX: Sorta hack, have nothing better on my mind right now
        # On every entry to a translation-needing function, call this with 
        # lang=maillang
        # On every exit of a translation-needing function, call this with 
        # lang=loglang
        # :-/
        if self.config:
            trans = gettext.translation("gettor", self.config.getLocaleDir(), [language])
            trans.install()

    def sendHelp(self, source, destination):
        """ Send a helpful message to the user interacting with us """
        self.setLang(self.mailLang)
        message = _("""
    Hello! This is the "gettor" robot.

    Unfortunately, we won't answer you at this address. We only process
    requests from email services that support "DKIM", which is an email
    feature that lets us verify that the address in the "From" line is
    actually the one who sent the mail.

    Gmail.com and Yahoo.cn use DKIM: you will have better luck sending
    us mail from one of those.

    (We apologize if you didn't ask for this mail. Since your email is from
    a service that doesn't use DKIM, we're sending a short explanation,
    and then we'll ignore this email address for the next day or so.)

    If you have any questions or it doesn't work, you can contact a
    human at this support email address: <EMAIL>

    Please note that currently, we can't process HTML emails. You will need
    to send plain text.
        """)
        help = self.constructMessage(message, source, destination)
        try:
            status = self.sendMessage(help, source, destination)
        except:
            log.error(_("Could not send help message to user"))
            status = False
        self.setLang(self.logLang)

        return status

    def sendPackageHelp(self, packageList, source, destination):
        """ Send a helpful message to the user interacting with us """
        self.setLang(self.mailLang)
        message = _("""
    Hello, This is the "gettor" robot.

    I am sorry, but your request was not understood. Please select one of the 
    following package names:

    """ + "".join([ "\t%s\n" % key for key in packageList.keys()]) + """
    Please send another mail to <EMAIL>. It only needs a
    single package name anywhere in the body of your email.

    Please note that currently, we can't process HTML emails. You will need to
    send plain text.

    If you have any questions or it doesn't work, you can contact a
    human at this support email address: <EMAIL>

        """)
        help = self.constructMessage(message, source, destination)
        try:
            status = self.sendMessage(help, source, destination)
        except:
            status = False
            log.error(_("Could not send package help message to user"))
        self.setLang(self.logLang)

        return status

    def sendGenericMessage(self, source, destination, message):
        """ Send a helpful message of some sort """
        self.setLang(self.mailLang)
        help = self.constructMessage(message, source, destination)
        try:
            status = self.sendMessage(help, source, destination)
        except:
            log.error(_("Could not send generic help message to user"))
            status = False
        self.setLang(self.logLang)<commit_msg>stop automating the list of available gettor packages. hard-code it to the right order. somebody should produce some magic for automating it again, one day.<commit_after>#!/usr/bin/python2.5
# -*- coding: utf-8 -*-
"""
 gettor_config.py - Parse configuration file for gettor

 Copyright (c) 2008, <NAME> <<EMAIL>>, 
                     <NAME> <<EMAIL>>

 This is Free Software. See LICENSE for license information.

 This library implements all of the email replying features needed for gettor. 
"""

import os
import smtplib
import MimeWriter
import StringIO
import base64
import gettext

import gettor.gtlog

__all__ = ["gettorResponse"]

log = gettor.gtlog.getLogger()

class gettorResponse:

    def __init__(self, config, mailLang="en", logLang="en"):
        self.mailLang = mailLang
        self.logLang = logLang
        self.config = config

    def setLang(self, language):
        # XXX: Sorta hack, have nothing better on my mind right now
        # On every entry to a translation-needing function, call this with 
        # lang=maillang
        # On every exit of a translation-needing function, call this with 
        # lang=loglang
        # :-/
        if self.config:
            trans = gettext.translation("gettor", self.config.getLocaleDir(), [language])
            trans.install()

    def sendHelp(self, source, destination):
        """ Send a helpful message to the user interacting with us """
        self.setLang(self.mailLang)
        message = _("""
    Hello! This is the "gettor" robot.

    Unfortunately, we won't answer you at this address. We only process
    requests from email services that support "DKIM", which is an email
    feature that lets us verify that the address in the "From" line is
    actually the one who sent the mail.

    Gmail.com and Yahoo.cn use DKIM: you will have better luck sending
    us mail from one of those.

    (We apologize if you didn't ask for this mail. Since your email is from
    a service that doesn't use DKIM, we're sending a short explanation,
    and then we'll ignore this email address for the next day or so.)

    If you have any questions or it doesn't work, you can contact a
    human at this support email address: <EMAIL>

    Please note that currently, we can't process HTML emails. You will need
    to send plain text.
        """)
        help = self.constructMessage(message, source, destination)
        try:
            status = self.sendMessage(help, source, destination)
        except:
            log.error(_("Could not send help message to user"))
            status = False
        self.setLang(self.logLang)

        return status

## XXX the following line was used below to automatically list the names
## of available packages. But they were being named in an arbitrary
## order, which caused people to always pick the first one. I listed
## tor-browser-bundle first since that's the one they should want.
## Somebody should figure out how to automate yet sort. -RD
##    """ + "".join([ "\t%s\n" % key for key in packageList.keys()]) + """

    def sendPackageHelp(self, packageList, source, destination):
        """ Send a helpful message to the user interacting with us """
        self.setLang(self.mailLang)
        message = _("""
    Hello, This is the "gettor" robot.

    I am sorry, but your request was not understood. Please select one of the
    following package names:

        tor-browser-bundle
        macosx-universal-bundle
        panther-bundle
        tor-im-browser-bundle
        source-bundle

    Please send another mail to <EMAIL>. It only needs a
    single package name anywhere in the body of your email.

    Please note that currently, we can't process HTML emails. You will need to
    send plain text.

    If you have any questions or it doesn't work, you can contact a
    human at this support email address: <EMAIL>

        """)
        help = self.constructMessage(message, source, destination)
        try:
            status = self.sendMessage(help, source, destination)
        except:
            status = False
            log.error(_("Could not send package help message to user"))
        self.setLang(self.logLang)

        return status

    def sendGenericMessage(self, source, destination, message):
        """ Send a helpful message of some sort """
        self.setLang(self.mailLang)
        help = self.constructMessage(message, source, destination)
        try:
            status = self.sendMessage(help, source, destination)
        except:
            log.error(_("Could not send generic help message to user"))
            status = False
        self.setLang(self.logLang)
{'fraction_non_alphanumeric': 0.08186528497409326, 'fraction_numerical': 0.002072538860103627, 'mean_word_length': 2.5833333333333335, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6231208', 'n_tokens_mistral': 2328, 'n_tokens_neox': 2237, 'n_words': 978}