Exemplo n.º 1
0
 def get_key_as_get_content_key(self, order, key):
     def foo_getter(msg, foo=None):
         bar = msg['X-Bar-Header']
         return foo, bar
     cm = ContentManager()
     cm.add_get_handler(key, foo_getter)
     m = self._make_message()
     m['Content-Type'] = 'text/plain'
     m['X-Bar-Header'] = 'foo'
     self.assertEqual(cm.get_content(m, foo='bar'), ('bar', 'foo'))
Exemplo n.º 2
0
 def get_key_as_get_content_key(self, order, key):
     def foo_getter(msg, foo=None):
         bar = msg['X-Bar-Header']
         return foo, bar
     cm = ContentManager()
     cm.add_get_handler(key, foo_getter)
     m = self._make_message()
     m['Content-Type'] = 'text/plain'
     m['X-Bar-Header'] = 'foo'
     self.assertEqual(cm.get_content(m, foo='bar'), ('bar', 'foo'))
Exemplo n.º 3
0
 def set_key_as_set_content_key(self, order, key):
     def foo_setter(msg, obj, foo=None):
         msg['X-Foo-Header'] = foo
         msg.set_payload(obj)
     cm = ContentManager()
     cm.add_set_handler(key, foo_setter)
     m = self._make_message()
     msg_obj = self.Thing()
     cm.set_content(m, msg_obj, foo='bar')
     self.assertEqual(m['X-Foo-Header'], 'bar')
     self.assertEqual(m.get_payload(), msg_obj)
Exemplo n.º 4
0
 def test_set_content_calls_clear_content(self):
     m = self._make_message()
     m['Content-Foo'] = 'bar'
     m['Content-Type'] = 'text/html'
     m['To'] = 'test'
     m.set_payload('abc')
     cm = ContentManager()
     cm.add_set_handler(str, lambda *args, **kw: None)
     m.set_content('xyz', content_manager=cm)
     self.assertIsNone(m['Content-Foo'])
     self.assertIsNone(m['Content-Type'])
     self.assertEqual(m['To'], 'test')
     self.assertIsNone(m.get_payload())
Exemplo n.º 5
0
 def test_set_content_calls_clear_content(self):
     m = self._make_message()
     m['Content-Foo'] = 'bar'
     m['Content-Type'] = 'text/html'
     m['To'] = 'test'
     m.set_payload('abc')
     cm = ContentManager()
     cm.add_set_handler(str, lambda *args, **kw: None)
     m.set_content('xyz', content_manager=cm)
     self.assertIsNone(m['Content-Foo'])
     self.assertIsNone(m['Content-Type'])
     self.assertEqual(m['To'], 'test')
     self.assertIsNone(m.get_payload())
Exemplo n.º 6
0
 def set_key_as_set_content_key_order(self, order, key):
     def foo_setter(msg, obj):
         msg['X-FooBar-Header'] = 'foo'
         msg.set_payload(obj)
     def bar_setter(msg, obj):
         msg['X-FooBar-Header'] = 'bar'
     cm = ContentManager()
     cm.add_set_handler(key, foo_setter)
     for precedence, key in self.get_key_params.values():
         if precedence > order:
             cm.add_set_handler(key, bar_setter)
     m = self._make_message()
     msg_obj = self.Thing()
     cm.set_content(m, msg_obj)
     self.assertEqual(m['X-FooBar-Header'], 'foo')
     self.assertEqual(m.get_payload(), msg_obj)
Exemplo n.º 7
0
def scrape_inbox():
    server = get_server()
    server.select('inbox')
    emails = server.search(None, 'FROM', '"*****@*****.**"')
    ids = emails[1][0]
    ids = list((ids.decode()).split(' '))
    if ids == ['']: return

    content_manager = ContentManager()

    for id in ids:
        typ, data = server.fetch(id, '(RFC822)')
        msg = email.message_from_bytes(data[0][1])
        if msg.is_multipart():
            extract_and_write_attachment(msg)
        server.store(id, '+X-GM-LABELS', '\\Trash')
Exemplo n.º 8
0
 def set_key_as_set_content_key(self, order, key):
     def foo_setter(msg, obj, foo=None):
         msg['X-Foo-Header'] = foo
         msg.set_payload(obj)
     cm = ContentManager()
     cm.add_set_handler(key, foo_setter)
     m = self._make_message()
     msg_obj = self.Thing()
     cm.set_content(m, msg_obj, foo='bar')
     self.assertEqual(m['X-Foo-Header'], 'bar')
     self.assertEqual(m.get_payload(), msg_obj)
Exemplo n.º 9
0
 def get_key_as_get_content_key_order(self, order, key):
     def bar_getter(msg):
         return msg['X-Bar-Header']
     def foo_getter(msg):
         return msg['X-Foo-Header']
     cm = ContentManager()
     cm.add_get_handler(key, foo_getter)
     for precedence, key in self.get_key_params.values():
         if precedence > order:
             cm.add_get_handler(key, bar_getter)
     m = self._make_message()
     m['Content-Type'] = 'text/plain'
     m['X-Bar-Header'] = 'bar'
     m['X-Foo-Header'] = 'foo'
     self.assertEqual(cm.get_content(m), ('foo'))
Exemplo n.º 10
0
 def set_key_as_set_content_key_order(self, order, key):
     def foo_setter(msg, obj):
         msg['X-FooBar-Header'] = 'foo'
         msg.set_payload(obj)
     def bar_setter(msg, obj):
         msg['X-FooBar-Header'] = 'bar'
     cm = ContentManager()
     cm.add_set_handler(key, foo_setter)
     for precedence, key in self.get_key_params.values():
         if precedence > order:
             cm.add_set_handler(key, bar_setter)
     m = self._make_message()
     msg_obj = self.Thing()
     cm.set_content(m, msg_obj)
     self.assertEqual(m['X-FooBar-Header'], 'foo')
     self.assertEqual(m.get_payload(), msg_obj)
Exemplo n.º 11
0
 def get_key_as_get_content_key_order(self, order, key):
     def bar_getter(msg):
         return msg['X-Bar-Header']
     def foo_getter(msg):
         return msg['X-Foo-Header']
     cm = ContentManager()
     cm.add_get_handler(key, foo_getter)
     for precedence, key in self.get_key_params.values():
         if precedence > order:
             cm.add_get_handler(key, bar_getter)
     m = self._make_message()
     m['Content-Type'] = 'text/plain'
     m['X-Bar-Header'] = 'bar'
     m['X-Foo-Header'] = 'foo'
     self.assertEqual(cm.get_content(m), ('foo'))
Exemplo n.º 12
0
 def test_get_content_raises_if_unknown_mimetype_and_no_default(self):
     cm = ContentManager()
     m = self._make_message()
     m['Content-Type'] = 'text/plain'
     with self.assertRaisesRegex(KeyError, 'text/plain'):
         cm.get_content(m)
Exemplo n.º 13
0
 def test_set_content_raises_if_unknown_type_and_no_default(self):
     cm = ContentManager()
     m = self._make_message()
     msg_obj = self.Thing()
     with self.assertRaisesRegex(KeyError, self.testobject_full_path):
         cm.set_content(m, msg_obj)
Exemplo n.º 14
0
 def test_get_content_raises_if_unknown_mimetype_and_no_default(self):
     cm = ContentManager()
     m = self._make_message()
     m['Content-Type'] = 'text/plain'
     with self.assertRaisesRegex(KeyError, 'text/plain'):
         cm.get_content(m)
Exemplo n.º 15
0
 def test_set_content_raises_if_called_on_multipart(self):
     cm = ContentManager()
     m = self._make_message()
     m['Content-Type'] = 'multipart/foo'
     with self.assertRaises(TypeError):
         cm.set_content(m, 'test')
Exemplo n.º 16
0
 def test_set_content_raises_if_unknown_type_and_no_default(self):
     cm = ContentManager()
     m = self._make_message()
     msg_obj = self.Thing()
     with self.assertRaisesRegex(KeyError, self.testobject_full_path):
         cm.set_content(m, msg_obj)
Exemplo n.º 17
0
 def test_set_content_raises_if_called_on_multipart(self):
     cm = ContentManager()
     m = self._make_message()
     m['Content-Type'] = 'multipart/foo'
     with self.assertRaises(TypeError):
         cm.set_content(m, 'test')