def Respond(self): subject = "Re: %s" % (self.subject,) from_ = sysrandom.choice(self.members) para = sysrandom.choice(PARAGRAPHS) body = "Dear %s:\n\n%s\n\n-- %s\n" % (self.initiator.split("@")[0], para, from_.split("@")[0]) headers = { "In-Reply-To": self._message_id, "References": self._message_id, } SendMail(body, from_, subject, self._recipient, headers)
def _make_match_string_from_pattern(parsetree, makebad=False, groups=None): collect = [] if groups is None: groups = {} for op, val in parsetree: if op is sre_constants.LITERAL: if makebad: collect.append(chr((val ^ 4) & 0xFF)) # flip bit 4 if random.randint(0, 9) == 0: makebad = False # don't error everything else: collect.append(chr(val)) elif op is sre_constants.CATEGORY: collect.append(get_substitute(val, makebad)) elif op is sre_constants.IN: if val[0][0] is sre_constants.CATEGORY: collect.append( _make_match_string_from_pattern(val, False, groups)) else: collect.append(chr(random.choice(val)[1])) elif op is sre_constants.BRANCH: collect.append( _make_match_string_from_pattern(val[1][random.randint(0, 1)], False, groups)) elif op is sre_constants.SUBPATTERN: string = _make_match_string_from_pattern(val[1], False, groups) groups[val[0]] = string collect.append(string) elif op is sre_constants.MAX_REPEAT or op is sre_constants.MIN_REPEAT: for i in xrange(random.randint(val[0], min(val[1], 10))): collect.append( _make_match_string_from_pattern(val[2], False, groups)) elif op is sre_constants.ANY: collect.append(random.choice(ANYCHAR)) elif op is sre_constants.GROUPREF: collect.append(groups[val]) elif op is sre_constants.AT: pass # ignore anchors else: raise UnhandledOpError("Unhandled RE op: %r" % (op, )) if makebad: # in case it didn't get done yet. collect.insert(random.randrange(0, len(collect)), random.choice(ascii.printable)) return "".join(collect)
def __init__(self, number, delay, recipient=DEFAULTACCOUNT, senders=None): topic = words.get_random_word() question = sysrandom.choice(["Concerning", "A question about", "Tell me about", "What about", "Information regarding", "A declaration about", "Help me with"]) self.subject = "[mail-list] %s %r." % (question, topic) self.members = senders or DEFAULT_SENDERS self._recipient = recipient self._number = int(number) self._delay = float(delay)
def _make_match_string_from_pattern(parsetree, makebad=False, groups=None): collect = [] if groups is None: groups = {} for op, val in parsetree: if op is sre_constants.LITERAL: if makebad: collect.append(chr((val ^ 4) & 0xFF)) # flip bit 4 if random.randint(0,9) == 0: makebad = False # don't error everything else: collect.append(chr(val)) elif op is sre_constants.CATEGORY: collect.append(get_substitute(val, makebad)) elif op is sre_constants.IN: if val[0][0] is sre_constants.CATEGORY: collect.append(_make_match_string_from_pattern(val, False, groups)) else: collect.append(chr(random.choice(val)[1])) elif op is sre_constants.BRANCH: collect.append(_make_match_string_from_pattern(val[1][random.randint(0,1)], False, groups)) elif op is sre_constants.SUBPATTERN: string = _make_match_string_from_pattern(val[1], False, groups) groups[val[0]] = string collect.append(string) elif op is sre_constants.MAX_REPEAT or op is sre_constants.MIN_REPEAT: for i in xrange(random.randint(val[0], min(val[1], 10))): collect.append(_make_match_string_from_pattern(val[2], False, groups)) elif op is sre_constants.ANY: collect.append(random.choice(ANYCHAR)) elif op is sre_constants.GROUPREF: collect.append(groups[val]) elif op is sre_constants.AT: pass # ignore anchors else: raise UnhandledOpError("Unhandled RE op: %r" % (op,)) if makebad: # in case it didn't get done yet. collect.insert(random.randrange(0, len(collect)), random.choice(ascii.printable)) return "".join(collect)
def Initiate(self): self.initiator = From = sysrandom.choice(self.members) body = sysrandom.choice(PARAGRAPHS) + "\n\n-- %s\n" % (From.split("@")[0],) self._message_id = SendMail(body, From, self.subject, self._recipient)
def get_substitute(category, inverse): if inverse: return random.choice(CATEGORY_SUBS_INVERTED[category]) else: return random.choice(CATEGORY_SUBS[category])
def get_salt(n): return "".join([sysrandom.choice(SALTCHARS) for i in range(n)])