folder.py
2.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# GNU Mailutils -- a suite of utilities for electronic mail
# Copyright (C) 2009, 2010 Free Software Foundation, Inc.
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 3 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General
# Public License along with this library. If not, see
# <http://www.gnu.org/licenses/>.
from mailutils.c_api import folder
from mailutils import stream
from mailutils import auth
from mailutils import url
from mailutils.error import FolderError
class Folder:
__owner = False
def __init__ (self, f):
if isinstance (f, folder.FolderType):
self.folder = f
else:
self.folder = folder.FolderType ()
self.__owner = True
status = folder.create (self.folder, f)
if status:
raise FolderError (status)
def __del__ (self):
if self.__owner:
folder.destroy (self.folder)
del self.folder
def open (self):
status = folder.open (self.folder)
if status:
raise FolderError (status)
def close (self):
status = folder.close (self.folder)
if status:
raise FolderError (status)
def get_stream (self):
status, stream = folder.get_stream (self.folder)
if status:
raise FolderError (status)
return stream.Stream (stm)
def set_stream (self, stream):
status = folder.set_stream (self.folder, stream.stm)
if status:
raise FolderError (status)
def get_authority (self):
status, authority = folder.get_authority (self.folder)
if status:
raise FolderError (status)
return auth.Authority (authority)
def set_authority (self, authority):
status = folder.set_authority (self.folder, authority.authority)
if status:
raise FolderError (status)
def get_url (self):
status, u = folder.get_url (self.folder)
if status:
raise FolderError (status)
return url.Url (u)
def list (self, dirname, pattern, max_level=0):
status, lst = folder.list (self.folder, dirname, pattern, max_level)
if status:
raise FolderError (status)
return lst