<commit_before>from __future__ import print_function

import base64
import datetime
import hmac
import hashlib
import re

timestamp_format = '%Y%m%d%H%M%S'

signed_cmd_regex = re.compile(r'^(?P<cmd>.+)\s+(?P<signature>[\da-zA-Z+/]{27}=)(?P<timestamp>\d{14})$')

from config import signing_key, signed_validity_interval
from sestools import msg_get_header, msg_get_response_address

import boto3

ses = boto3.client('ses')

from commands import run

class NotSignedException(Exception):
    pass

class ExpiredSignatureException(Exception):
    pass

class InvalidSignatureException(Exception):
    pass

def handle_command(command_address, msg):
    auto_submitted = msg_get_header(msg, 'auto-submitted')
    if auto_submitted and auto_submitted.lower() != 'no':
        # Auto-submitted: header, https://www.iana.org/assignments/auto-submitted-keywords/auto-submitted-keywords.xhtml
        print("Message appears to be automatically generated ({}), so ignoring it.".format(auto_submitted))
        return

    # Grab the address to which to respond and the subject
    reply_to = msg_get_response_address(msg)
    if reply_to is None:
        print("Failed to get an email address from the Reply-To, From, or Sender headers.")
        return
    subject = msg_get_header(msg, 'subject').replace('\n', ' ')
    print("Subject: " + subject)
    print("Responding to: " + reply_to)

    # Strip off any re:, fwd:, etc. (everything up to the last :, then trim whitespace)
    if ':' in subject:
        subject = subject[subject.rfind(':') + 1:]
    subject = subject.strip()

    try:
        cmd = get_signed_command(subject, reply_to)<commit_msg>Ensure that newlines/line breaks are completely removed from subject commands.<commit_after>from __future__ import print_function

import base64
import datetime
import hmac
import hashlib
import re

timestamp_format = '%Y%m%d%H%M%S'

signed_cmd_regex = re.compile(r'^(?P<cmd>.+)\s+(?P<signature>[\da-zA-Z+/]{27}=)(?P<timestamp>\d{14})$')

from config import signing_key, signed_validity_interval
from sestools import msg_get_header, msg_get_response_address

import boto3

ses = boto3.client('ses')

from commands import run

class NotSignedException(Exception):
    pass

class ExpiredSignatureException(Exception):
    pass

class InvalidSignatureException(Exception):
    pass

def handle_command(command_address, msg):
    auto_submitted = msg_get_header(msg, 'auto-submitted')
    if auto_submitted and auto_submitted.lower() != 'no':
        # Auto-submitted: header, https://www.iana.org/assignments/auto-submitted-keywords/auto-submitted-keywords.xhtml
        print("Message appears to be automatically generated ({}), so ignoring it.".format(auto_submitted))
        return

    # Grab the address to which to respond and the subject
    reply_to = msg_get_response_address(msg)
    if reply_to is None:
        print("Failed to get an email address from the Reply-To, From, or Sender headers.")
        return
    subject = msg_get_header(msg, 'subject').replace('\n', '').replace('\r', '')
    print("Subject: " + subject)
    print("Responding to: " + reply_to)

    # Strip off any re:, fwd:, etc. (everything up to the last :, then trim whitespace)
    if ':' in subject:
        subject = subject[subject.rfind(':') + 1:]
    subject = subject.strip()

    try:
        cmd = get_signed_command(subject, reply_to)
{'fraction_non_alphanumeric': 0.11700236966824644, 'fraction_numerical': 0.00533175355450237, 'mean_word_length': 4.195384615384615, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, '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': '328062', 'n_tokens_mistral': 1067, 'n_tokens_neox': 1033, 'n_words': 275}