4 # Copyright 2015, Olivier MATZ <zer0@droids-corp.org>
6 # Redistribution and use in source and binary forms, with or without
7 # modification, are permitted provided that the following conditions are met:
9 # * Redistributions of source code must retain the above copyright
10 # notice, this list of conditions and the following disclaimer.
11 # * Redistributions in binary form must reproduce the above copyright
12 # notice, this list of conditions and the following disclaimer in the
13 # documentation and/or other materials provided with the distribution.
14 # * Neither the name of the University of California, Berkeley nor the
15 # names of its contributors may be used to endorse or promote products
16 # derived from this software without specific prior written permission.
18 # THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY
19 # EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20 # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21 # DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS BE LIABLE FOR ANY
22 # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23 # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
25 # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27 # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 class ImapamiMail(object):
34 An email, fetched from the IMAP server
36 Depending on the fetch level, fields may be filled or set to None.
38 def __init__(self, item, inbox, flags=None, internal_date=None, date=None,
39 headers=None, body_part1=None, body_all=None):
42 The IMAP id of the mail
44 The IMAP directory where the mail is located
46 The IMAP flags of the mail
47 :arg str internal_date:
48 The IMAP date of the mail
49 :arg time.struct_time date:
50 The date of the mail, converted in python format
52 The headers of the mail
54 The first part of the body of the mail
56 The whole body of the mail
62 if headers is not None:
64 self.msghdrs = email.message_from_string(msg)
65 if body_all is not None:
67 elif body_part1 is not None:
69 self.msg = email.message_from_string(msg)
70 # fetch level >= headers
72 self.internal_date = internal_date
74 self.headers = headers
75 # fetch level >= part1
76 self.body_part1 = body_part1
78 self.body_all = body_all