def test_multible_addresses_can_be_given(self): addresses = 'one <*****@*****.**>, other <*****@*****.**>, ' \ 'last <*****@*****.**>' actual = utils.encode_header('from', addresses) expected = email.header.Header(addresses) self.assertEqual(actual, expected)
def test_space_around_email_address_is_striped(self): address = ' someone <*****@*****.**> ' actual = utils.encode_header('from', address) expected = email.header.Header(address.strip()) self.assertEqual(actual, expected)
def test_spaces_in_user_names_are_accepted(self): address = 'some one <*****@*****.**>' actual = utils.encode_header('from', address) expected = email.header.Header(address) self.assertEqual(actual, expected)
def test_plain_email_addresses_are_accepted(self): address = '*****@*****.**' actual = utils.encode_header('from', address) expected = email.header.Header(address) self.assertEqual(actual, expected)
def test_email_addresses_with_empty_realnames_are_treated_like_plain(self): address = '*****@*****.**' empty_realname = '<' + address + '>' actual = utils.encode_header('from', empty_realname) expected = email.header.Header(address) self.assertEqual(str(actual), str(expected))
def apply(self, ui): # abort if command unset if not self.cmd: ui.notify(self.noop_msg, priority='error') return # get messages to pipe if self.whole_thread: thread = ui.current_buffer.get_selected_thread() if not thread: return to_print = thread.get_messages().keys() else: to_print = [ui.current_buffer.get_selected_message()] # ask for confirmation if needed if self.confirm_msg: if (yield ui.choice(self.confirm_msg, select='yes', cancel='no')) == 'no': return # prepare message sources pipestrings = [] separator = '\n\n' logging.debug('PIPETO format') logging.debug(self.output_format) if self.output_format == 'id': pipestrings = [e.get_message_id() for e in to_print] separator = '\n' elif self.output_format == 'filepath': pipestrings = [e.get_filename() for e in to_print] separator = '\n' else: for msg in to_print: mail = msg.get_email() if self.add_tags: mail['Tags'] = encode_header('Tags', ' '.join(msg.get_tags())) if self.output_format == 'raw': pipestrings.append(mail.as_string()) elif self.output_format == 'decoded': headertext = extract_headers(mail) bodytext = extract_body(mail) msgtext = '%s\n\n%s' % (headertext, bodytext) pipestrings.append(msgtext.encode('utf-8')) if not self.separately: pipestrings = [separator.join(pipestrings)] if self.shell: self.cmd = [' '.join(self.cmd)] # do teh monkey for mail in pipestrings: if self.background: logging.debug('call in background: %s' % str(self.cmd)) proc = subprocess.Popen(self.cmd, shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE) out, err = proc.communicate(mail) else: logging.debug('stop urwid screen') ui.mainloop.screen.stop() logging.debug('call: %s' % str(self.cmd)) proc = subprocess.Popen(self.cmd, shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE) out, err = proc.communicate(mail) logging.debug('start urwid screen') ui.mainloop.screen.start() if err: ui.notify(err, priority='error') return if self.notify_stdout: ui.notify(out) # display 'done' message if self.done_msg: ui.notify(self.done_msg)
def test_unicode_chars_are_encoded(self): actual = utils.encode_header('x-key', u'välüe') expected = email.header.Header('=?utf-8?b?dsOkbMO8ZQ==?=') self.assertEqual(actual, expected)
def test_comma_in_names_are_allowed(self): addresses = '"last, first" <*****@*****.**>, ' \ '"name, other" <*****@*****.**>' actual = utils.encode_header('from', addresses) expected = email.header.Header(addresses) self.assertEqual(str(actual), str(expected))
def test_utf_8_chars_in_realnames_are_accepted(self): address = u'Ümlaut <*****@*****.**>' actual = utils.encode_header('from', address) expected = email.header.Header( '=?utf-8?q?=C3=9Cmlaut?= <*****@*****.**>') self.assertEqual(actual, expected)
def test_spaces_in_user_names_are_accepted(self): address = 'some one <*****@*****.**>' actual = utils.encode_header('from', address) expected = email.header.Header(address) self.assertEqual(actual, expected)
def test_multible_addresses_can_be_given(self): addresses = 'one <*****@*****.**>, other <*****@*****.**>, ' \ 'last <*****@*****.**>' actual = utils.encode_header('from', addresses) expected = email.header.Header(addresses) self.assertEqual(actual, expected)
def test_space_around_email_address_is_striped(self): address = ' someone <*****@*****.**> ' actual = utils.encode_header('from', address) expected = email.header.Header(address.strip()) self.assertEqual(actual, expected)
def test_email_addresses_with_empty_realnames_are_treated_like_plain(self): address = '*****@*****.**' empty_realname = '<'+address+'>' actual = utils.encode_header('from', empty_realname) expected = email.header.Header(address) self.assertEqual(str(actual), str(expected))
def test_plain_email_addresses_are_accepted(self): address = '*****@*****.**' actual = utils.encode_header('from', address) expected = email.header.Header(address) self.assertEqual(actual, expected)
def test_comma_in_names_are_allowed(self): addresses = '"last, first" <*****@*****.**>, ' \ '"name, other" <*****@*****.**>' actual = utils.encode_header('from', addresses) expected = email.header.Header(addresses) self.assertEqual(str(actual), str(expected))
def test_only_value_is_used_in_output(self): actual = utils.encode_header('x-key', 'value') expected = email.header.Header('value') self.assertEqual(actual, expected)
def test_utf_8_chars_in_realnames_are_accepted(self): address = u'Ümlaut <*****@*****.**>' actual = utils.encode_header('from', address) expected = email.header.Header( '=?utf-8?q?=C3=9Cmlaut?= <*****@*****.**>') self.assertEqual(actual, expected)
def test_unicode_chars_are_encoded(self): actual = utils.encode_header('x-key', u'välüe') expected = email.header.Header('=?utf-8?b?dsOkbMO8ZQ==?=') self.assertEqual(actual, expected)
def apply(self, ui): # abort if command unset if not self.cmd: ui.notify(self.noop_msg, priority='error') return # get messages to pipe if self.whole_thread: thread = ui.current_buffer.get_selected_thread() if not thread: return to_print = thread.get_messages().keys() else: to_print = [ui.current_buffer.get_selected_message()] # ask for confirmation if needed if self.confirm_msg: if (yield ui.choice(self.confirm_msg, select='yes', cancel='no')) == 'no': return # prepare message sources pipestrings = [] separator = '\n\n' logging.debug('PIPETO format') logging.debug(self.output_format) if self.output_format == 'id': pipestrings = [e.get_message_id() for e in to_print] separator = '\n' elif self.output_format == 'filepath': pipestrings = [e.get_filename() for e in to_print] separator = '\n' else: for msg in to_print: mail = msg.get_email() if self.add_tags: mail['Tags'] = encode_header('Tags', ' '.join(msg.get_tags())) if self.output_format == 'raw': pipestrings.append(mail.as_string()) elif self.output_format == 'decoded': headertext = extract_headers(mail) bodytext = extract_body(mail) msgtext = '%s\n\n%s' % (headertext, bodytext) pipestrings.append(msgtext.encode('utf-8')) if not self.separately: pipestrings = [separator.join(pipestrings)] if self.shell: self.cmd = [' '.join(self.cmd)] # do teh monkey for mail in pipestrings: if self.background: logging.debug('call in background: %s' % str(self.cmd)) proc = subprocess.Popen(self.cmd, shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE) out, err = proc.communicate(mail) else: logging.debug('stop urwid screen') ui.mainloop.screen.stop() logging.debug('call: %s' % str(self.cmd)) proc = subprocess.Popen(self.cmd, shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE) out, err = proc.communicate(mail) logging.debug('start urwid screen') ui.mainloop.screen.start() if err: ui.notify(err, priority='error') return if self.notify_stdout: ui.notify(out) # display 'done' message if self.done_msg: ui.notify(self.done_msg)
def test_only_value_is_used_in_output(self): actual = utils.encode_header('x-key', 'value') expected = email.header.Header('value') self.assertEqual(actual, expected)