Exemple #1
0
 def process(self, thread, matches):
     fn_glob = evaluate_expression(self.value, **locals())
     destinations = self._get_destinations(thread, matches)
     for fn in sorted(glob(fn_glob)):  # sort for ut behavior
         data = open(fn, 'rb').read()
         self.ld('Adding attachement from file: {}'.format(fn))
         thread.add_attachment_to_draft(data, fn, destinations)
Exemple #2
0
 def process(self, thread, matches):
     # use the values we saved in the constructor to run the appropriate code
     label_string = evaluate_expression(self.value, **locals())
     if self.unset:
         self.ld('removing label: {} on thread {}'.format(
             label_string, thread))
     else:
         self.ld('adding label: {} on thread {}'.format(
             label_string, thread))
     thread.set_label(label_string, unset=self.unset)
Exemple #3
0
 def matches(self, thread):
     if evaluate_expression(self.expression, **locals()):
         self.ld('{} returns true {}'.format(self.expression, thread))
         return True
     elif super().force_match():
         self.ld('\'{}\' forced to return true for {}'.format(
             self.expression, thread))
         return True
     self.ld('{} returns false {}'.format(self.expression, thread))
     return False
Exemple #4
0
 def process(self, thread, matches):
     self.ld('processing a thread')
     found_threads = evaluate_expression(self.thread_finder_expression, **{
         **locals(),
         **self.__dict__
     })
     if not found_threads:
         self.li('No found_threads matched the expression: {}'.format(
             self.thread_finder_expression))
     for found_thread in found_threads:
         super().process(found_thread, matches)
Exemple #5
0
 def process(self, thread, matches):
     self.ld('processing a thread')
     destinations = self._get_destinations(thread, matches)
     if self.value:
         draft_content = evaluate_expression(self.value, **locals())
     else:
         draft_content = ''
     if self.prepend:
         thread.prepend_to_draft(draft_content, destinations)
     else:
         thread.append_to_draft(draft_content, destinations)
     self.label_action.process(thread, matches)
Exemple #6
0
    def process(self, thread, matches):
        evaluated_command = evaluate_expression(self.command, **locals())
        self.ld('Command evaluated to: {}'.format(evaluated_command))
        if BaseValidator.force_matches:
            return 0
        child = subprocess.Popen(evaluated_command.split(),
                                 stdout=subprocess.PIPE,
                                 stderr=subprocess.PIPE)
        out, error = child.communicate()
        rc = child.returncode

        self.li('stdout: {}'.format(out))
        self.li('stderr: {}'.format(error))

        if rc != 0:
            self.le('subprocess failed.\nstdout: {}\n\nstderr: {}\n\nrc: {}'.
                    format(out, error, rc))
        return rc
Exemple #7
0
 def process(self, thread, matches):
     found_threads = evaluate_expression(self.thread_finder_expression, **{
         **locals(),
         **self.__dict__
     })
     if not found_threads:
         self.lw('No found_threads matched the expression: {}'.format(
             self.thread_finder_expression))
     found = False
     for found_thread in found_threads:
         for label in found_thread.labels():
             if self.label_re.match(label):
                 self.ld('Match label: {} with re: {}'.format(
                     label, self.label_regex_string))
                 thread.set_label(label)
                 found = True
     if not found:
         self.lw('No labels in any found threads matched re: {}'.format(
             self.label_regex_string))
Exemple #8
0
 def _get_destinations(self, thread, matches):
     if self.destinations:
         return self.__convert_string_emails_to_list(
             evaluate_expression(self.destinations, **locals()))
     else:
         return []