Commit fef67bbd fef67bbdc7399fb7b2820057431bd4d703686c73 by Wojciech Polak

Add new Python interface and example programs.

1 parent eb9e1ecf
Showing 77 changed files with 8509 additions and 3 deletions
...@@ -17,5 +17,5 @@ Sergey Poznyakoff <gray@Mirddin.farlep.net> ...@@ -17,5 +17,5 @@ Sergey Poznyakoff <gray@Mirddin.farlep.net>
17 Sam Roberts <sroberts@uniserve.com> 17 Sam Roberts <sroberts@uniserve.com>
18 The parsing code for email addresses. 18 The parsing code for email addresses.
19 Wojciech Polak <polak@gnu.org> 19 Wojciech Polak <polak@gnu.org>
20 TLS, NLS, libmu_cpp, docs, misc hacking. 20 TLS, NLS, Python interface, libmu_cpp, docs, misc hacking.
21 21
......
...@@ -54,7 +54,8 @@ SUBDIRS = \ ...@@ -54,7 +54,8 @@ SUBDIRS = \
54 dotlock\ 54 dotlock\
55 mh\ 55 mh\
56 movemail\ 56 movemail\
57 mimeview 57 mimeview\
58 python
58 59
59 EXTRA_DIST = COPYING.LESSER 60 EXTRA_DIST = COPYING.LESSER
60 61
......
...@@ -158,6 +158,10 @@ mailutils-specific configuration options: ...@@ -158,6 +158,10 @@ mailutils-specific configuration options:
158 Enable GSSAPI authentication. For this to work, you will have 158 Enable GSSAPI authentication. For this to work, you will have
159 to have Kerberos V installed on your system. 159 to have Kerberos V installed on your system.
160 160
161 --without-python
162
163 Do not build Python interface library.
164
161 --without-guile 165 --without-guile
162 166
163 Do not build Guile interface library. 167 Do not build Guile interface library.
......
...@@ -22,6 +22,7 @@ AC_CONFIG_SRCDIR([mailbox/mailbox.c]) ...@@ -22,6 +22,7 @@ AC_CONFIG_SRCDIR([mailbox/mailbox.c])
22 AC_CONFIG_AUX_DIR([scripts]) 22 AC_CONFIG_AUX_DIR([scripts])
23 AM_INIT_AUTOMAKE 23 AM_INIT_AUTOMAKE
24 AC_CONFIG_HEADERS([config.h]) 24 AC_CONFIG_HEADERS([config.h])
25 AC_CONFIG_MACRO_DIR([m4])
25 26
26 AC_PREREQ(2.60) 27 AC_PREREQ(2.60)
27 28
...@@ -1092,6 +1093,35 @@ if test "$EMACS" != "no"; then ...@@ -1092,6 +1093,35 @@ if test "$EMACS" != "no"; then
1092 fi 1093 fi
1093 AC_SUBST(lisp_LISP) 1094 AC_SUBST(lisp_LISP)
1094 1095
1096 # Check for Python
1097 AC_ARG_WITH([python],
1098 AC_HELP_STRING([--without-python],
1099 [do not build Python interface]),
1100 [
1101 case "${withval}" in
1102 yes) status_python=yes ;;
1103 no) status_python=no ;;
1104 *) AC_MSG_ERROR(bad value ${withval} for --without-python) ;;
1105 esac],[status_python=yes])
1106
1107 if test "$status_python" = yes; then
1108 AM_PATH_PYTHON(2.5.0,, [status_python=no])
1109 if test "$status_python" = yes; then
1110 AC_ARG_VAR([PYTHON_CONFIG], [The name of python-config binary])
1111 AC_PATH_PROG([PYTHON_CONFIG], python-config)
1112 if test -n "$PYTHON_CONFIG"; then
1113 AC_SUBST(PYTHON_LIBS,`python-config --libs`)
1114 AC_SUBST(PYTHON_INCLUDES,`python-config --includes`)
1115 else
1116 status_python=no
1117 fi
1118
1119 if test "$status_python" = yes; then
1120 AC_SUBST(MU_PYTHON_LTLIBS,'$(MU_PYTHON_LTLIBS)')
1121 fi
1122 fi
1123 fi
1124
1095 # Default mailbox record 1125 # Default mailbox record
1096 # Note: 1. Support for mbox type is always enabled. 1126 # Note: 1. Support for mbox type is always enabled.
1097 # 2. Only local mailbox types are allowed for MU_DEFAULT_SCHEME 1127 # 2. Only local mailbox types are allowed for MU_DEFAULT_SCHEME
...@@ -1162,6 +1192,7 @@ Use GNU TLS.................... $status_gnutls ...@@ -1162,6 +1192,7 @@ Use GNU TLS.................... $status_gnutls
1162 Use GSASL...................... $status_gsasl 1192 Use GSASL...................... $status_gsasl
1163 Use GSSAPI..................... $status_gssapi 1193 Use GSSAPI..................... $status_gssapi
1164 Use Guile...................... $status_guile 1194 Use Guile...................... $status_guile
1195 Use Python..................... $status_python
1165 Use TCP wrappers............... $status_tcpwrap 1196 Use TCP wrappers............... $status_tcpwrap
1166 Pthread support................ $status_pthread 1197 Pthread support................ $status_pthread
1167 Readline support............... $status_readline 1198 Readline support............... $status_readline
...@@ -1198,6 +1229,7 @@ status_gnutls=$WITH_GNUTLS ...@@ -1198,6 +1229,7 @@ status_gnutls=$WITH_GNUTLS
1198 status_gsasl=$status_gsasl 1229 status_gsasl=$status_gsasl
1199 status_gssapi=$WITH_GSSAPI 1230 status_gssapi=$WITH_GSSAPI
1200 status_guile=$useguile 1231 status_guile=$useguile
1232 status_python=$status_python
1201 status_tcpwrap=$status_tcpwrap 1233 status_tcpwrap=$status_tcpwrap
1202 status_pthread=$usepthread 1234 status_pthread=$usepthread
1203 status_readline=$usereadline 1235 status_readline=$usereadline
...@@ -1226,6 +1258,7 @@ AC_CONFIG_FILES([Makefile ...@@ -1226,6 +1258,7 @@ AC_CONFIG_FILES([Makefile
1226 examples/Makefile 1258 examples/Makefile
1227 examples/config/Makefile 1259 examples/config/Makefile
1228 examples/cpp/Makefile 1260 examples/cpp/Makefile
1261 examples/python/Makefile
1229 examples/scheme/Makefile 1262 examples/scheme/Makefile
1230 frm/Makefile 1263 frm/Makefile
1231 frm/testsuite/Makefile 1264 frm/testsuite/Makefile
...@@ -1271,6 +1304,9 @@ AC_CONFIG_FILES([Makefile ...@@ -1271,6 +1304,9 @@ AC_CONFIG_FILES([Makefile
1271 po/Makefile.in 1304 po/Makefile.in
1272 pop3d/Makefile 1305 pop3d/Makefile
1273 pop3d/testsuite/Makefile 1306 pop3d/testsuite/Makefile
1307 python/Makefile
1308 python/c_api/Makefile
1309 python/mailutils/Makefile
1274 readmsg/Makefile 1310 readmsg/Makefile
1275 readmsg/testsuite/Makefile 1311 readmsg/testsuite/Makefile
1276 scripts/Makefile 1312 scripts/Makefile
......
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
17 ## Foundation, Inc. 51 Franklin Street, Fifth Floor, Boston, MA 17 ## Foundation, Inc. 51 Franklin Street, Fifth Floor, Boston, MA
18 ## 02110-1301 USA 18 ## 02110-1301 USA
19 19
20 SUBDIRS = config cpp scheme 20 SUBDIRS = config cpp python scheme
21 21
22 noinst_PROGRAMS = \ 22 noinst_PROGRAMS = \
23 aclck\ 23 aclck\
......
1 ## Process this file with GNU Automake to create Makefile.in
2
3 ## Copyright (C) 2009 Free Software Foundation, Inc.
4 ##
5 ## GNU Mailutils is free software; you can redistribute it and/or
6 ## modify it under the terms of the GNU General Public License as
7 ## published by the Free Software Foundation; either version 3, or (at
8 ## your option) any later version.
9 ##
10 ## This program is distributed in the hope that it will be useful, but
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 ## General Public License for more details.
14 ##
15 ## You should have received a copy of the GNU General Public License
16 ## along with this program; if not, write to the Free Software
17 ## Foundation, Inc. 51 Franklin Street, Fifth Floor, Boston, MA
18 ## 02110-1301 USA
19
20 EXTRA_DIST = \
21 addr.py\
22 auth.py\
23 iconv.py\
24 lsf.py\
25 mailcap.py\
26 mimetest.py\
27 msg-send.py\
28 sfrom.py\
29 url-parse.py
30
1 # GNU Mailutils -- a suite of utilities for electronic mail
2 # Copyright (C) 2009 Free Software Foundation, Inc.
3 #
4 # GNU Mailutils is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 3, or (at your option)
7 # any later version.
8 #
9 # GNU Mailutils is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with GNU Mailutils; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
17 # MA 02110-1301 USA
18
19 import sys
20 from mailutils import address
21 from mailutils import util
22 from mailutils.error import *
23
24 def parse (str):
25 util.set_user_email_domain ("localhost")
26
27 try:
28 addr = address.Address (str)
29
30 count = addr.get_count ()
31 print "%s => count %d" % (addr, len (addr))
32
33 for no in range (1, count + 1):
34 isgroup = addr.is_group (no)
35 print "%d " % no,
36
37 if isgroup:
38 print "group <%s>" % addr.get_personal (no)
39 else:
40 print "email <%s>" % addr.get_email (no)
41
42 if not isgroup:
43 print " personal <%s>" % addr.get_personal (no)
44
45 print " comments <%s>" % addr.get_comments (no)
46 print " local-part <%s> domain <%s>" % (addr.get_local_part (no),
47 addr.get_domain (no))
48 print " route <%s>" % addr.get_route (no)
49 except AddressError, e:
50 print e
51 print
52
53 def parseinput ():
54 try:
55 while True:
56 line = sys.stdin.readline ().strip ()
57 if line == '':
58 break
59 parse (line)
60 except KeyboardInterrupt:
61 sys.exit ()
62
63 if __name__ == '__main__':
64 if len (sys.argv) == 1:
65 parseinput ()
66 sys.exit ()
67
68 for arg in sys.argv[1:]:
69 if arg == '-':
70 parseinput ()
71 else:
72 parse (arg)
1 # GNU Mailutils -- a suite of utilities for electronic mail
2 # Copyright (C) 2009 Free Software Foundation, Inc.
3 #
4 # GNU Mailutils is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 3, or (at your option)
7 # any later version.
8 #
9 # GNU Mailutils is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with GNU Mailutils; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
17 # MA 02110-1301 USA
18
19 import sys
20 import getopt
21 import getpass
22 from mailutils import auth
23 from mailutils.error import AuthError
24
25 if __name__ == '__main__':
26 key_type = 'name'
27
28 try:
29 opts, args = getopt.getopt (sys.argv[1:], 'p:un',
30 ['password=', 'uid', 'name'])
31 for o, arg in opts:
32 if o in ('-p', '--password'):
33 password = arg
34 elif o in ('-u', '--uid'):
35 key_type = 'uid'
36 elif o in ('-n', '--name'):
37 key_type = 'name'
38 except getopt.GetoptError:
39 print "Usage: %s [OPTION...] key" % sys.argv[0]
40 print """%s -- test mailutils authentication and authorization schemes
41
42 -n, --name test getpwnam functions
43 -p, --password=STRING user password
44 -u, --uid test getpwuid functions
45 """ % sys.argv[0]
46 sys.exit (0)
47
48 if not len (args):
49 print "%s: not enough arguments, try --help" % sys.argv[0]
50 sys.exit (0)
51
52 if key_type == 'uid':
53 key = int (args[0])
54 else:
55 key = args[0]
56
57 auth.register_module (('system', 'generic'))
58
59 if key_type == 'name':
60 auth_data = auth.get_auth_by_name (key)
61 elif key_type == 'uid':
62 auth_data = auth.get_auth_by_uid (key)
63
64 if not auth_data:
65 print '"%s" not found' % key
66 sys.exit (0)
67
68 print "source: %s" % auth_data.source
69 print "user name: %s" % auth_data.name
70 print "password: %s" % auth_data.passwd
71 print "uid: %d" % auth_data.uid
72 print "gid: %d" % auth_data.gid
73 print "gecos: %s" % auth_data.gecos
74 print "home: %s" % auth_data.dir
75 print "shell: %s" % auth_data.shell
76 print "mailbox: %s" % auth_data.mailbox
77 print "quota: %d" % auth_data.quota
78 print "change_uid: %d" % auth_data.change_uid
79
80 if not vars ().has_key ('password'):
81 password = getpass.getpass ()
82
83 try:
84 auth.authenticate (auth_data, password)
85 print 'Authenticated!'
86 except AuthError, e:
87 print e
1 # GNU Mailutils -- a suite of utilities for electronic mail
2 # Copyright (C) 2009 Free Software Foundation, Inc.
3 #
4 # GNU Mailutils is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 3, or (at your option)
7 # any later version.
8 #
9 # GNU Mailutils is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with GNU Mailutils; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
17 # MA 02110-1301 USA
18
19 import sys
20 from mailutils import stream
21 from mailutils import filter
22
23 if len (sys.argv) != 3:
24 print "usage: %s from-code to-code" % sys.argv[0]
25 sys.exit (0)
26
27 sti = stream.StdioStream (sys.stdin)
28 sti.open ()
29
30 cvt = filter.FilterIconvStream (sti, sys.argv[1], sys.argv[2])
31 cvt.open ()
32
33 out = stream.StdioStream (sys.stdout, 0)
34 out.open ()
35
36 total = 0
37 while True:
38 buf = cvt.read (total)
39 out.sequential_write (buf)
40 total += cvt.read_count
41 if not cvt.read_count:
42 break
43
44 out.flush ()
45 out.close ()
46 sti.close ()
1 # GNU Mailutils -- a suite of utilities for electronic mail
2 # Copyright (C) 2009 Free Software Foundation, Inc.
3 #
4 # GNU Mailutils is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 3, or (at your option)
7 # any later version.
8 #
9 # GNU Mailutils is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with GNU Mailutils; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
17 # MA 02110-1301 USA
18
19 import sys
20 from mailutils import folder
21 from mailutils import registrar
22 from mailutils.error import *
23
24 def ls_folders (fname, ref, pattern, level):
25 try:
26 fld = folder.Folder (fname)
27 fld.open ()
28
29 list = fld.list (ref, pattern, level)
30 for f in list:
31 print f
32 print "Number of folders: %d" % len (list)
33
34 fld.close ()
35 except Error, e:
36 print e
37
38 if __name__ == '__main__':
39 pattern = "*"
40 level = 0
41 argc = len (sys.argv)
42
43 if argc == 5:
44 level = int (sys.argv[4])
45 pattern = sys.argv[3]
46 ref = sys.argv[2]
47 fname = sys.argv[1]
48 elif argc == 4:
49 pattern = sys.argv[3]
50 ref = sys.argv[2]
51 fname = sys.argv[1]
52 elif argc == 3:
53 ref = sys.argv[2]
54 fname = sys.argv[1]
55 elif argc == 2:
56 fname = sys.argv[1]
57 else:
58 print "usage: lsf folder [ref] [pattern] [recursion-level]"
59 sys.exit (0)
60
61 registrar.register_format ()
62 ls_folders (fname, ref, pattern, level)
1 # GNU Mailutils -- a suite of utilities for electronic mail
2 # Copyright (C) 2009 Free Software Foundation, Inc.
3 #
4 # GNU Mailutils is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 3, or (at your option)
7 # any later version.
8 #
9 # GNU Mailutils is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with GNU Mailutils; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
17 # MA 02110-1301 USA
18
19 from mailutils import stream, mailcap
20
21 stm = stream.FileStream ("/etc/mailcap")
22 stm.open ()
23
24 mc = mailcap.Mailcap (stm)
25
26 for i, entry in enumerate (mc):
27 print "entry[%d]" % (i + 1)
28
29 # typefield
30 print "\ttypefield: %s" % entry.get_typefield ()
31
32 # view-command
33 print "\tview-command: %s" % entry.get_viewcommand ()
34
35 # fields
36 for j, ent in enumerate (entry):
37 print "\tfields[%d]: %s" % ((j + 1), ent)
38
39 print
1 # GNU Mailutils -- a suite of utilities for electronic mail
2 # Copyright (C) 2009 Free Software Foundation, Inc.
3 #
4 # GNU Mailutils is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 3, or (at your option)
7 # any later version.
8 #
9 # GNU Mailutils is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with GNU Mailutils; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
17 # MA 02110-1301 USA
18
19 import sys
20 import getopt
21 from mailutils import *
22 from mailutils.header import *
23
24 print_attachments = False
25 indent_level = 4
26
27 def print_file (fname, indent):
28 try:
29 fp = open (fname, 'r')
30 for line in fp:
31 print "%*.*s%s" % (indent, indent, '', line)
32 fp.close ()
33 remove (fname)
34 except OSError, e:
35 print e
36
37 def print_message_part_sizes (part, indent):
38 print "%*.*sMessage part size - %d/%d: %d/%d, %d/%d" % \
39 (indent, indent, '',
40 part.size, part.lines,
41 part.header.size, part.header.lines,
42 part.body.size, part.body.lines)
43
44 def message_display_parts (msg, indent):
45 # How many parts does the message has?
46 nparts = msg.get_num_parts ()
47
48 # Iterate through all the parts. Treat type "message/rfc822"
49 # differently, since it is a message of its own that can have other
50 # subparts (recursive).
51 for j in range (1, nparts + 1):
52 part = msg.get_part (j)
53 hdr = part.get_header ()
54
55 type = hdr.get_value (MU_HEADER_CONTENT_TYPE, 'text/plain')
56 encoding = hdr.get_value (MU_HEADER_CONTENT_TRANSFER_ENCODING, '7bit')
57
58 print "%*.*sType of part %d = %s" % (indent, indent, '', j, type)
59 print_message_part_sizes (part, indent)
60
61 ismulti = part.is_multipart ()
62 if type == "message/rfc822" or ismulti:
63 if not ismulti:
64 part = part.unencapsulate ()
65
66 hdr = part.get_header ()
67 frm = hdr.get_value (MU_HEADER_FROM, "[none]")
68 subject = hdr.get_value (MU_HEADER_SUBJECT, "[none]")
69
70 print "%*.*sEncapsulated message : %s\t%s" % \
71 (indent, indent, '', frm, subject)
72 print "%*.*sBegin" % (indent, indent, '')
73
74 nsubparts = part.get_num_parts ()
75 message_display_parts (part, indent + indent_level)
76 elif (type.startswith ("text/plain") or
77 type.startswith ("text/html") or type == ''):
78 print "%*.*sText Message" % (indent, indent, '')
79 print "%*.*sBegin" % (indent, indent, '')
80
81 flt = filter.FilterStream (part.body.get_stream (), encoding)
82 offset = 0
83
84 while True:
85 buf = flt.readline (offset)
86 offset += flt.read_count
87 if not flt.read_count:
88 break
89 print "%*.*s%s" % (indent, indent, '', buf),
90 else:
91 # Save the attachements.
92 try:
93 fname = part.get_attachment_name ()
94 except:
95 fname = util.tempname ()
96
97 print "%*.*sAttachment - saving [%s]" % \
98 (indent, indent, '', fname)
99 print "%*.*sBegin" % (indent, indent, '')
100
101 part.save_attachment ()
102 if print_attachments:
103 print_file (fname, indent)
104
105 print "%*.*sEnd" % (indent, indent, '')
106
107
108 if __name__ == '__main__':
109 optdebug = False
110
111 try:
112 opts, args = getopt.getopt (sys.argv[1:], 'dpi:')
113 for o, a in opts:
114 if o == '-d':
115 optdebug = True
116 elif o == '-p':
117 print_attachments = True
118 elif o == '-i':
119 indent_level = int (a)
120 except getopt.GetoptError:
121 sys.exit (0)
122
123 # Registration.
124 registrar.register_format (('imap', 'pop', 'mbox'))
125 registrar.set_default_format ('mbox')
126
127 if args:
128 args = args[0]
129 else:
130 args = ''
131
132 mbox = mailbox.MailboxDefault (args)
133
134 # Debugging trace.
135 if optdebug:
136 mbox.debug.set_level (debug.MU_DEBUG_PROT)
137
138 # Open the mailbox for reading only.
139 mbox.open ()
140
141 # Iterate through the entire message set.
142 for i, msg in enumerate (mbox):
143 print "Message: %d" % (i + 1)
144 print "From: %s" % msg.header.get_value (MU_HEADER_FROM, "[none]")
145 print "Subject: %s" % msg.header.get_value (MU_HEADER_SUBJECT, "[none]")
146 print "Number of parts in message - %d" % msg.get_num_parts ()
147 print "Total message size - %d/%d" % (msg.size, msg.lines)
148
149 try:
150 message_display_parts (msg, 0)
151 except Error, e:
152 print e
153
154 mbox.close ()
1 # GNU Mailutils -- a suite of utilities for electronic mail
2 # Copyright (C) 2009 Free Software Foundation, Inc.
3 #
4 # GNU Mailutils is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 3, or (at your option)
7 # any later version.
8 #
9 # GNU Mailutils is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with GNU Mailutils; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
17 # MA 02110-1301 USA
18
19 import sys
20 import getopt
21 from mailutils import *
22
23 USAGE = "usage: mailer [-hd] [-m mailer] [-f from] [to]..."
24 HELP = """
25 -h print this helpful message
26 -m a mailer URL (default is \"sendmail:\")
27 -f the envelope from address (default is from user environment)
28 to a list of envelope to addresses (default is from message)
29
30 An RFC2822 formatted message is read from stdin and delivered using
31 the mailer."""
32
33 optmailer = "sendmail:"
34 optfrom = False
35 optdebug = False
36
37 try:
38 opts, args = getopt.getopt (sys.argv[1:], 'hdm:f:')
39 for o, a in opts:
40 if o == '-h':
41 print USAGE
42 print HELP
43 sys.exit (0)
44 elif o == '-d':
45 optdebug = True
46 elif o == '-m':
47 optmailer = a
48 elif o == '-f':
49 optfrom = a
50 except getopt.GetoptError:
51 print USAGE
52 sys.exit (0)
53
54 registrar.register_format ('sendmail')
55
56 frm = None
57 to = None
58
59 if optfrom:
60 frm = address.Address (optfrom)
61 if args:
62 to = address.Address (args)
63
64 sti = stream.StdioStream (sys.stdin, stream.MU_STREAM_SEEKABLE)
65 sti.open ()
66
67 msg = message.Message ()
68 msg.set_stream (sti)
69
70 mlr = mailer.Mailer (optmailer)
71 if optdebug:
72 mlr.debug.set_level (debug.MU_DEBUG_PROT)
73
74 mlr.open ()
75 mlr.send_message (msg, frm, to)
76 mlr.close ()
1 # GNU Mailutils -- a suite of utilities for electronic mail
2 # Copyright (C) 2009 Free Software Foundation, Inc.
3 #
4 # GNU Mailutils is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 3, or (at your option)
7 # any later version.
8 #
9 # GNU Mailutils is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with GNU Mailutils; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
17 # MA 02110-1301 USA
18
19 import sys
20 from mailutils import *
21 from mailutils.header import *
22
23 args = ''
24 if len (sys.argv) > 1:
25 args = sys.argv[1]
26
27 registrar.register_format ()
28
29 mbox = mailbox.MailboxDefault (args)
30 mbox.open ()
31
32 print "Total: %d" % len (mbox)
33
34 for msg in mbox:
35 print "%s %s" % (msg.header[MU_HEADER_FROM],
36 msg.header.get_value (MU_HEADER_SUBJECT, "(NO SUBJECT)"))
37
38 mbox.close ()
1 # GNU Mailutils -- a suite of utilities for electronic mail
2 # Copyright (C) 2009 Free Software Foundation, Inc.
3 #
4 # GNU Mailutils is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 3, or (at your option)
7 # any later version.
8 #
9 # GNU Mailutils is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with GNU Mailutils; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
17 # MA 02110-1301 USA
18
19 import sys
20 from mailutils import url
21 from mailutils.error import *
22
23 def parse (str):
24 try:
25 u = url.Url (str)
26 u.parse ()
27 print "URL: %s" % u
28
29 print "\tscheme <%s>" % u.get_scheme ()
30 print "\tuser <%s>" % u.get_user ()
31 print "\tpasswd <%s>" % u.get_passwd ()
32 print "\tauth <%s>" % u.get_auth ()
33 print "\thost <%s>" % u.get_host ()
34 print "\tport %d" % u.get_port ()
35 print "\tpath <%s>" % u.get_path ()
36
37 for i, param in enumerate (u.get_query ()):
38 print "\tquery[%d] %s" % (i, param)
39
40 except UrlError, e:
41 print e
42
43 def parseinput ():
44 try:
45 while True:
46 line = sys.stdin.readline ().strip ()
47 if line == '':
48 break
49 parse (line)
50 except KeyboardInterrupt:
51 sys.exit ()
52
53 if __name__ == '__main__':
54 if len (sys.argv) == 1:
55 parseinput ()
56 sys.exit ()
57
58 for arg in sys.argv[1:]:
59 if arg == '-':
60 parseinput ()
61 else:
62 parse (arg)
1 ## Process this file with GNU Automake to create Makefile.in
2
3 ## Copyright (C) 2009 Free Software Foundation, Inc.
4 ##
5 ## GNU Mailutils is free software; you can redistribute it and/or
6 ## modify it under the terms of the GNU General Public License as
7 ## published by the Free Software Foundation; either version 3, or (at
8 ## your option) any later version.
9 ##
10 ## This program is distributed in the hope that it will be useful, but
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 ## General Public License for more details.
14 ##
15 ## You should have received a copy of the GNU General Public License
16 ## along with this program; if not, write to the Free Software
17 ## Foundation, Inc. 51 Franklin Street, Fifth Floor, Boston, MA
18 ## 02110-1301 USA
19
20 SUBDIRS = c_api mailutils
21
1 ## Process this file with GNU Automake to create Makefile.in
2
3 ## Copyright (C) 2009 Free Software Foundation, Inc.
4 ##
5 ## GNU Mailutils is free software; you can redistribute it and/or
6 ## modify it under the terms of the GNU General Public License as
7 ## published by the Free Software Foundation; either version 3, or (at
8 ## your option) any later version.
9 ##
10 ## This program is distributed in the hope that it will be useful, but
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 ## General Public License for more details.
14 ##
15 ## You should have received a copy of the GNU General Public License
16 ## along with this program; if not, write to the Free Software
17 ## Foundation, Inc. 51 Franklin Street, Fifth Floor, Boston, MA
18 ## 02110-1301 USA
19
20 INCLUDES = @MU_COMMON_INCLUDES@ $(PYTHON_INCLUDES)
21
22 MU_PYTHON_LTLIBS = c_api.la
23 EXTRA_LTLIBRARIES = c_api.la
24 pkgpyexec_LTLIBRARIES = @MU_PYTHON_LTLIBS@
25 c_api_la_LDFLAGS = -avoid-version -module -rpath $(pkgpyexecdir)
26 c_api_la_LIBADD = $(PYTHON_LIBS) @MU_COMMON_LIBRARIES@ \
27 ${MU_LIB_MBOX}\
28 ${MU_LIB_IMAP}\
29 ${MU_LIB_POP}\
30 ${MU_LIB_NNTP}\
31 ${MU_LIB_MH}\
32 ${MU_LIB_MAILDIR}\
33 ${MU_LIB_AUTH}\
34 ${MU_LIB_MAILER}\
35 @MU_AUTHLIBS@\
36 ${MU_LIB_MAILUTILS}
37
38 c_api_la_SOURCES = \
39 c_api.c \
40 c_api.h \
41 error.c \
42 address.c \
43 address-private.h \
44 attribute.c \
45 attribute-private.h \
46 auth.c \
47 auth-private.h \
48 body.c \
49 body-private.h \
50 debug.c \
51 debug-private.h \
52 envelope.c \
53 envelope-private.h \
54 filter.c \
55 folder.c \
56 folder-private.h \
57 list.c \
58 list-private.h \
59 header.c \
60 header-private.h \
61 mailer.c \
62 mailer-private.h \
63 mailbox.c \
64 mailbox-private.h \
65 mailcap.c \
66 mailcap-private.h \
67 message.c \
68 message-private.h \
69 mime.c \
70 mime-private.h \
71 stream.c \
72 stream-private.h \
73 registrar.c \
74 url.c \
75 url-private.h \
76 util.c
77
1 /*
2 GNU Mailutils -- a suite of utilities for electronic mail
3 Copyright (C) 2009 Free Software Foundation, Inc.
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 3 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General
16 Public License along with this library; if not, write to the
17 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301 USA
19 */
20
21 #ifndef _MUCAPI_ADDRESS_H
22 #define _MUCAPI_ADDRESS_H
23
24 #include <mailutils/address.h>
25
26 typedef struct {
27 PyObject_HEAD;
28 mu_address_t addr;
29 } PyAddress;
30
31 extern PyAddress * PyAddress_NEW ();
32 extern int PyAddress_Check (PyObject *x);
33
34 #endif /* not _MUCAPI_ADDRESS_H */
1 /*
2 GNU Mailutils -- a suite of utilities for electronic mail
3 Copyright (C) 2009 Free Software Foundation, Inc.
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 3 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General
16 Public License along with this library; if not, write to the
17 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301 USA
19 */
20
21 #include "c_api.h"
22 #include "address-private.h"
23
24 #define PY_MODULE "address"
25 #define PY_CSNAME "AddressType"
26
27 static PyObject *
28 _repr (PyObject *self)
29 {
30 char buf[80];
31 sprintf (buf, "<" PY_MODULE "." PY_CSNAME " instance at %p>", self);
32 return PyString_FromString (buf);
33 }
34
35 static PyTypeObject PyAddressType = {
36 PyObject_HEAD_INIT(NULL)
37 0, /* ob_size */
38 PY_MODULE "." PY_CSNAME, /* tp_name */
39 sizeof (PyAddress), /* tp_basicsize */
40 0, /* tp_itemsize */
41 (destructor)py_dealloc, /* tp_dealloc */
42 0, /* tp_print */
43 0, /* tp_getattr; __getattr__ */
44 0, /* tp_setattr; __setattr__ */
45 0, /* tp_compare; __cmp__ */
46 _repr, /* tp_repr; __repr__ */
47 0, /* tp_as_number */
48 0, /* tp_as_sequence */
49 0, /* tp_as_mapping */
50 0, /* tp_hash; __hash__ */
51 0, /* tp_call; __call__ */
52 _repr, /* tp_str; __str__ */
53 0, /* tp_getattro */
54 0, /* tp_setattro */
55 0, /* tp_as_buffer */
56 Py_TPFLAGS_DEFAULT, /* tp_flags */
57 "", /* tp_doc */
58 0, /* tp_traverse */
59 0, /* tp_clear */
60 0, /* tp_richcompare */
61 0, /* tp_weaklistoffset */
62 0, /* tp_iter */
63 0, /* tp_iternext */
64 0, /* tp_methods */
65 0, /* tp_members */
66 0, /* tp_getset */
67 0, /* tp_base */
68 0, /* tp_dict */
69 0, /* tp_descr_get */
70 0, /* tp_descr_set */
71 0, /* tp_dictoffset */
72 0, /* tp_init */
73 0, /* tp_alloc */
74 0, /* tp_new */
75 };
76
77 PyAddress *
78 PyAddress_NEW ()
79 {
80 return (PyAddress *)PyObject_NEW (PyAddress, &PyAddressType);
81 }
82
83 int
84 PyAddress_Check (PyObject *x)
85 {
86 return x->ob_type == &PyAddressType;
87 }
88
89 static PyObject *
90 api_address_create (PyObject *self, PyObject *args)
91 {
92 int status;
93 char *str;
94 PyAddress *py_addr;
95
96 if (!PyArg_ParseTuple (args, "O!s", &PyAddressType, &py_addr, &str))
97 return NULL;
98
99 status = mu_address_create (&py_addr->addr, str);
100 return _ro (PyInt_FromLong (status));
101 }
102
103 static PyObject *
104 api_address_createv (PyObject *self, PyObject *args)
105 {
106 int status;
107 char *str;
108 PyAddress *py_addr;
109 PyObject *py_seq;
110 char **sv;
111 size_t len;
112
113 if (!PyArg_ParseTuple (args, "O!O", &PyAddressType, &py_addr, &py_seq))
114 return NULL;
115
116 if (!PySequence_Check (py_seq))
117 {
118 PyErr_SetString (PyExc_TypeError, "");
119 return NULL;
120 }
121
122 len = PySequence_Size (py_seq);
123 sv = (char **) malloc ((len + 1) * sizeof (char *));
124 if (!sv)
125 {
126 PyErr_NoMemory ();
127 return NULL;
128 }
129 else
130 {
131 PyObject *py_item;
132 int i;
133
134 for (i = 0; i < len; i++) {
135 py_item = PySequence_GetItem (py_seq, i);
136 if (py_item && PyString_Check (py_item))
137 sv[i] = strdup (PyString_AsString (py_item));
138 Py_DECREF (py_item);
139 }
140 if (PyErr_Occurred ()) {
141 PyErr_Print ();
142 return NULL;
143 }
144 }
145 status = mu_address_createv (&py_addr->addr, (const char**)sv, len);
146 return _ro (PyInt_FromLong (status));
147 }
148
149 static PyObject *
150 api_address_destroy (PyObject *self, PyObject *args)
151 {
152 PyAddress *py_addr;
153
154 if (!PyArg_ParseTuple (args, "O!", &PyAddressType, &py_addr))
155 return NULL;
156
157 mu_address_destroy (&py_addr->addr);
158 return _ro (Py_None);
159 }
160
161 static PyObject *
162 api_address_is_group (PyObject *self, PyObject *args)
163 {
164 int status, n, isgroup;
165 PyAddress *py_addr;
166
167 if (!PyArg_ParseTuple (args, "O!i", &PyAddressType, &py_addr, &n))
168 return NULL;
169
170 status = mu_address_is_group (py_addr->addr, n, &isgroup);
171 return status_object (status, PyBool_FromLong (isgroup));
172 }
173
174 static PyObject *
175 api_address_get_count (PyObject *self, PyObject *args)
176 {
177 size_t count = 0;
178 PyAddress *py_addr;
179
180 if (!PyArg_ParseTuple (args, "O!", &PyAddressType, &py_addr))
181 return NULL;
182
183 mu_address_get_count (py_addr->addr, &count);
184 return _ro (PyInt_FromLong (count));
185 }
186
187 static PyObject *
188 api_address_get_email (PyObject *self, PyObject *args)
189 {
190 int status, n;
191 const char *buf = NULL;
192 PyAddress *py_addr;
193
194 if (!PyArg_ParseTuple (args, "O!i", &PyAddressType, &py_addr, &n))
195 return NULL;
196
197 status = mu_address_sget_email (py_addr->addr, n, &buf);
198 return status_object (status, PyString_FromString (buf ? buf : ""));
199 }
200
201 static PyObject *
202 api_address_get_local_part (PyObject *self, PyObject *args)
203 {
204 int status, n;
205 const char *buf = NULL;
206 PyAddress *py_addr;
207
208 if (!PyArg_ParseTuple (args, "O!i", &PyAddressType, &py_addr, &n))
209 return NULL;
210
211 status = mu_address_sget_local_part (py_addr->addr, n, &buf);
212 return status_object (status, PyString_FromString (buf ? buf : ""));
213 }
214
215 static PyObject *
216 api_address_get_domain (PyObject *self, PyObject *args)
217 {
218 int status, n;
219 const char *buf = NULL;
220 PyAddress *py_addr;
221
222 if (!PyArg_ParseTuple (args, "O!i", &PyAddressType, &py_addr, &n))
223 return NULL;
224
225 status = mu_address_sget_domain (py_addr->addr, n, &buf);
226 return status_object (status, PyString_FromString (buf ? buf : ""));
227 }
228
229 static PyObject *
230 api_address_get_personal (PyObject *self, PyObject *args)
231 {
232 int status, n;
233 const char *buf = NULL;
234 PyAddress *py_addr;
235
236 if (!PyArg_ParseTuple (args, "O!i", &PyAddressType, &py_addr, &n))
237 return NULL;
238
239 status = mu_address_sget_personal (py_addr->addr, n, &buf);
240 return status_object (status, PyString_FromString (buf ? buf : ""));
241 }
242
243 static PyObject *
244 api_address_get_comments (PyObject *self, PyObject *args)
245 {
246 int status, n;
247 const char *buf = NULL;
248 PyAddress *py_addr;
249
250 if (!PyArg_ParseTuple (args, "O!i", &PyAddressType, &py_addr, &n))
251 return NULL;
252
253 status = mu_address_sget_comments (py_addr->addr, n, &buf);
254 return status_object (status, PyString_FromString (buf ? buf : ""));
255 }
256
257 static PyObject *
258 api_address_get_route (PyObject *self, PyObject *args)
259 {
260 int status, n;
261 const char *buf = NULL;
262 PyAddress *py_addr;
263
264 if (!PyArg_ParseTuple (args, "O!i", &PyAddressType, &py_addr, &n))
265 return NULL;
266
267 status = mu_address_sget_route (py_addr->addr, n, &buf);
268 return status_object (status, PyString_FromString (buf ? buf : ""));
269 }
270
271 static PyObject *
272 api_address_to_string (PyObject *self, PyObject *args)
273 {
274 int status, n;
275 char buf[256];
276 PyAddress *py_addr;
277
278 memset (buf, 0, sizeof (buf));
279
280 if (!PyArg_ParseTuple (args, "O!", &PyAddressType, &py_addr))
281 return NULL;
282
283 status = mu_address_to_string (py_addr->addr, buf, sizeof (buf), &n);
284 return status_object (status, PyString_FromString (buf));
285 }
286
287 static PyMethodDef methods[] = {
288 { "create", (PyCFunction) api_address_create, METH_VARARGS,
289 "Allocate and initialize ADDR by parsing the RFC822 "
290 "address-list STRING." },
291
292 { "createv", (PyCFunction) api_address_createv, METH_VARARGS,
293 "Allocate and initialize ADDR by parsing the RFC822 address-list." },
294
295 { "destroy", (PyCFunction) api_address_destroy, METH_VARARGS,
296 "Destroy ADDR." },
297
298 { "is_group", (PyCFunction) api_address_is_group, METH_VARARGS,
299 "Return True if address is just the name of a group, False otherwise." },
300
301 { "get_count", (PyCFunction) api_address_get_count, METH_VARARGS,
302 "Return a count of the addresses in the address list." },
303
304 { "get_email", (PyCFunction) api_address_get_email, METH_VARARGS,
305 "Return the Nth email address component of the address list." },
306
307 { "get_local_part", (PyCFunction) api_address_get_local_part, METH_VARARGS,
308 "Return local part of the Nth email address from the address list." },
309
310 { "get_domain", (PyCFunction) api_address_get_domain, METH_VARARGS,
311 "Return domain part of the Nth email address from the address list." },
312
313 { "get_personal", (PyCFunction) api_address_get_personal, METH_VARARGS,
314 "Return personal part of the Nth email address from the address list." },
315
316 { "get_comments", (PyCFunction) api_address_get_comments, METH_VARARGS,
317 "Return comment part of the Nth email address from the list." },
318
319 { "get_route", (PyCFunction) api_address_get_route, METH_VARARGS,
320 "Return route part of the Nth email address from the list." },
321
322 { "to_string", (PyCFunction) api_address_to_string, METH_VARARGS,
323 "Return the entire address list as a single RFC822 formatted address list." },
324
325 { NULL, NULL, 0, NULL }
326 };
327
328 void
329 init_address ()
330 {
331 PyObject *m;
332
333 PyAddressType.tp_new = PyType_GenericNew;
334 if (PyType_Ready (&PyAddressType) < 0)
335 return;
336
337 if ((m = attach_module (PY_MODULE, methods)))
338 {
339 Py_INCREF (&PyAddressType);
340 PyModule_AddObject (m, PY_CSNAME, (PyObject *)&PyAddressType);
341 }
342 }
1 /*
2 GNU Mailutils -- a suite of utilities for electronic mail
3 Copyright (C) 2009 Free Software Foundation, Inc.
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 3 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General
16 Public License along with this library; if not, write to the
17 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301 USA
19 */
20
21 #ifndef _MUCAPI_ATTRIBUTE_H
22 #define _MUCAPI_ATTRIBUTE_H
23
24 #include <mailutils/attribute.h>
25
26 typedef struct {
27 PyObject_HEAD;
28 mu_attribute_t attr;
29 } PyAttribute;
30
31 extern PyAttribute * PyAttribute_NEW ();
32
33 #endif /* not _MUCAPI_ATTRIBUTE_H */
1 /*
2 GNU Mailutils -- a suite of utilities for electronic mail
3 Copyright (C) 2009 Free Software Foundation, Inc.
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 3 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General
16 Public License along with this library; if not, write to the
17 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301 USA
19 */
20
21 #include "c_api.h"
22 #include "attribute-private.h"
23
24 #define PY_MODULE "attribute"
25 #define PY_CSNAME "AttributeType"
26
27 static PyObject *
28 _repr (PyObject *self)
29 {
30 char buf[80];
31 sprintf (buf, "<" PY_MODULE "." PY_CSNAME " instance at %p>", self);
32 return PyString_FromString (buf);
33 }
34
35 static PyTypeObject PyAttributeType = {
36 PyObject_HEAD_INIT(NULL)
37 0, /* ob_size */
38 PY_MODULE "." PY_CSNAME, /* tp_name */
39 sizeof (PyAttribute), /* tp_basicsize */
40 0, /* tp_itemsize */
41 (destructor)py_dealloc, /* tp_dealloc */
42 0, /* tp_print */
43 0, /* tp_getattr; __getattr__ */
44 0, /* tp_setattr; __setattr__ */
45 0, /* tp_compare; __cmp__ */
46 _repr, /* tp_repr; __repr__ */
47 0, /* tp_as_number */
48 0, /* tp_as_sequence */
49 0, /* tp_as_mapping */
50 0, /* tp_hash; __hash__ */
51 0, /* tp_call; __call__ */
52 _repr, /* tp_str; __str__ */
53 0, /* tp_getattro */
54 0, /* tp_setattro */
55 0, /* tp_as_buffer */
56 Py_TPFLAGS_DEFAULT, /* tp_flags */
57 "", /* tp_doc */
58 0, /* tp_traverse */
59 0, /* tp_clear */
60 0, /* tp_richcompare */
61 0, /* tp_weaklistoffset */
62 0, /* tp_iter */
63 0, /* tp_iternext */
64 0, /* tp_methods */
65 0, /* tp_members */
66 0, /* tp_getset */
67 0, /* tp_base */
68 0, /* tp_dict */
69 0, /* tp_descr_get */
70 0, /* tp_descr_set */
71 0, /* tp_dictoffset */
72 0, /* tp_init */
73 0, /* tp_alloc */
74 0, /* tp_new */
75 };
76
77 PyAttribute *
78 PyAttribute_NEW ()
79 {
80 return (PyAttribute *)PyObject_NEW (PyAttribute, &PyAttributeType);
81 }
82
83 static PyObject *
84 api_attribute_create (PyObject *self, PyObject *args)
85 {
86 int status;
87 PyAttribute *py_attr;
88
89 if (!PyArg_ParseTuple (args, "O!", &PyAttributeType, &py_attr))
90 return NULL;
91
92 status = mu_attribute_create (&py_attr->attr, NULL);
93 return _ro (PyInt_FromLong (status));
94 }
95
96 static PyObject *
97 api_attribute_destroy (PyObject *self, PyObject *args)
98 {
99 PyAttribute *py_attr;
100
101 if (!PyArg_ParseTuple (args, "O!", &PyAttributeType, &py_attr))
102 return NULL;
103
104 mu_attribute_destroy (&py_attr->attr, NULL);
105 return _ro (Py_None);
106 }
107
108 static PyObject *
109 api_attribute_is_modified (PyObject *self, PyObject *args)
110 {
111 int state;
112 PyAttribute *py_attr;
113
114 if (!PyArg_ParseTuple (args, "O!", &PyAttributeType, &py_attr))
115 return NULL;
116
117 state = mu_attribute_is_modified (py_attr->attr);
118 return _ro (PyBool_FromLong (state));
119 }
120
121 static PyObject *
122 api_attribute_clear_modified (PyObject *self, PyObject *args)
123 {
124 PyAttribute *py_attr;
125
126 if (!PyArg_ParseTuple (args, "O!", &PyAttributeType, &py_attr))
127 return NULL;
128
129 mu_attribute_clear_modified (py_attr->attr);
130 return _ro (Py_None);
131 }
132
133 static PyObject *
134 api_attribute_set_modified (PyObject *self, PyObject *args)
135 {
136 PyAttribute *py_attr;
137
138 if (!PyArg_ParseTuple (args, "O!", &PyAttributeType, &py_attr))
139 return NULL;
140
141 mu_attribute_set_modified (py_attr->attr);
142 return _ro (Py_None);
143 }
144
145 static PyObject *
146 api_attribute_get_flags (PyObject *self, PyObject *args)
147 {
148 int status, flags = 0;
149 PyAttribute *py_attr;
150
151 if (!PyArg_ParseTuple (args, "O!", &PyAttributeType, &py_attr))
152 return NULL;
153
154 status = mu_attribute_get_flags (py_attr->attr, &flags);
155 return status_object (status, PyInt_FromLong (flags));
156 }
157
158 static PyObject *
159 api_attribute_set_flags (PyObject *self, PyObject *args)
160 {
161 int status, flags;
162 PyAttribute *py_attr;
163
164 if (!PyArg_ParseTuple (args, "O!i", &PyAttributeType, &py_attr, &flags))
165 return NULL;
166
167 status = mu_attribute_set_flags (py_attr->attr, flags);
168 return _ro (PyInt_FromLong (status));
169 }
170
171 static PyObject *
172 api_attribute_unset_flags (PyObject *self, PyObject *args)
173 {
174 int status, flags;
175 PyAttribute *py_attr;
176
177 if (!PyArg_ParseTuple (args, "O!i", &PyAttributeType, &py_attr, &flags))
178 return NULL;
179
180 status = mu_attribute_unset_flags (py_attr->attr, flags);
181 return _ro (PyInt_FromLong (status));
182 }
183
184 static PyObject *
185 api_attribute_to_string (PyObject *self, PyObject *args)
186 {
187 char buf[MU_STATUS_BUF_SIZE];
188 size_t na = 0;
189 PyAttribute *py_attr;
190
191 memset (buf, 0, sizeof (buf));
192
193 if (!PyArg_ParseTuple (args, "O!", &PyAttributeType, &py_attr))
194 return NULL;
195
196 mu_attribute_to_string (py_attr->attr, buf, sizeof (buf), &na);
197 return _ro (PyString_FromString (buf));
198 }
199
200 static PyMethodDef methods[] = {
201 { "create", (PyCFunction) api_attribute_create, METH_VARARGS,
202 "" },
203
204 { "destroy", (PyCFunction) api_attribute_destroy, METH_VARARGS,
205 "" },
206
207 { "is_modified", (PyCFunction) api_attribute_is_modified, METH_VARARGS,
208 "Return TRUE or FALSE whether attribute has been modified." },
209
210 { "clear_modified", (PyCFunction) api_attribute_clear_modified,
211 METH_VARARGS, "" },
212
213 { "set_modified", (PyCFunction) api_attribute_set_modified, METH_VARARGS,
214 "" },
215
216 { "get_flags", (PyCFunction) api_attribute_get_flags, METH_VARARGS,
217 "" },
218
219 { "set_flags", (PyCFunction) api_attribute_set_flags, METH_VARARGS,
220 "" },
221
222 { "unset_flags", (PyCFunction) api_attribute_unset_flags, METH_VARARGS,
223 "" },
224
225 { "to_string", (PyCFunction) api_attribute_to_string, METH_VARARGS,
226 "" },
227
228 { NULL, NULL, 0, NULL }
229 };
230
231 void
232 init_attribute ()
233 {
234 PyObject *m;
235
236 PyAttributeType.tp_new = PyType_GenericNew;
237 if (PyType_Ready (&PyAttributeType) < 0)
238 return;
239
240 if ((m = attach_module (PY_MODULE, methods)))
241 {
242 Py_INCREF (&PyAttributeType);
243 PyModule_AddObject (m, PY_CSNAME, (PyObject *)&PyAttributeType);
244 }
245 }
1 /*
2 GNU Mailutils -- a suite of utilities for electronic mail
3 Copyright (C) 2009 Free Software Foundation, Inc.
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 3 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General
16 Public License along with this library; if not, write to the
17 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301 USA
19 */
20
21 #ifndef _MUCAPI_AUTH_H
22 #define _MUCAPI_AUTH_H
23
24 #include <mailutils/auth.h>
25 #include <mailutils/mu_auth.h>
26
27 typedef struct {
28 PyObject_HEAD;
29 mu_authority_t auth;
30 } PyAuthority;
31
32 typedef struct {
33 PyObject_HEAD;
34 mu_ticket_t ticket;
35 } PyTicket;
36
37 typedef struct {
38 PyObject_HEAD;
39 mu_wicket_t wicket;
40 } PyWicket;
41
42 typedef struct {
43 PyObject_HEAD;
44 struct mu_auth_data *auth_data;
45 } PyAuthData;
46
47 extern PyAuthority * PyAuthority_NEW ();
48 extern int PyAuthority_Check (PyObject *x);
49
50 extern PyTicket * PyTicket_NEW ();
51 extern int PyTicket_Check (PyObject *x);
52
53 extern PyWicket * PyWicket_NEW ();
54 extern int PyWicket_Check (PyObject *x);
55
56 extern PyAuthData * PyAuthData_NEW ();
57 extern int PyAuthData_Check (PyObject *x);
58
59 #endif /* not _MUCAPI_AUTH_H */
1 /*
2 GNU Mailutils -- a suite of utilities for electronic mail
3 Copyright (C) 2009 Free Software Foundation, Inc.
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 3 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General
16 Public License along with this library; if not, write to the
17 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301 USA
19 */
20
21 #include "c_api.h"
22 #include "auth-private.h"
23
24 #define PY_MODULE "auth"
25 #define PY_CSNAME1 "AuthorityType"
26 #define PY_CSNAME2 "TicketType"
27 #define PY_CSNAME3 "WicketType"
28 #define PY_CSNAME4 "AuthDataType"
29
30 static PyObject *
31 _repr1 (PyObject *self)
32 {
33 char buf[80];
34 sprintf (buf, "<" PY_MODULE "." PY_CSNAME1 " instance at %p>", self);
35 return PyString_FromString (buf);
36 }
37
38 static PyObject *
39 _repr2 (PyObject *self)
40 {
41 char buf[80];
42 sprintf (buf, "<" PY_MODULE "." PY_CSNAME2 " instance at %p>", self);
43 return PyString_FromString (buf);
44 }
45
46 static PyObject *
47 _repr3 (PyObject *self)
48 {
49 char buf[80];
50 sprintf (buf, "<" PY_MODULE "." PY_CSNAME3 " instance at %p>", self);
51 return PyString_FromString (buf);
52 }
53
54 static PyObject *
55 _repr4 (PyObject *self)
56 {
57 char buf[80];
58 sprintf (buf, "<" PY_MODULE "." PY_CSNAME4 " instance at %p>", self);
59 return PyString_FromString (buf);
60 }
61
62
63 static PyTypeObject PyAuthorityType = {
64 PyObject_HEAD_INIT(NULL)
65 0, /* ob_size */
66 PY_MODULE "." PY_CSNAME1, /* tp_name */
67 sizeof (PyAuthority), /* tp_basicsize */
68 0, /* tp_itemsize */
69 (destructor)py_dealloc, /* tp_dealloc */
70 0, /* tp_print */
71 0, /* tp_getattr; __getattr__ */
72 0, /* tp_setattr; __setattr__ */
73 0, /* tp_compare; __cmp__ */
74 _repr1, /* tp_repr; __repr__ */
75 0, /* tp_as_number */
76 0, /* tp_as_sequence */
77 0, /* tp_as_mapping */
78 0, /* tp_hash; __hash__ */
79 0, /* tp_call; __call__ */
80 _repr1, /* tp_str; __str__ */
81 0, /* tp_getattro */
82 0, /* tp_setattro */
83 0, /* tp_as_buffer */
84 Py_TPFLAGS_DEFAULT, /* tp_flags */
85 "", /* tp_doc */
86 0, /* tp_traverse */
87 0, /* tp_clear */
88 0, /* tp_richcompare */
89 0, /* tp_weaklistoffset */
90 0, /* tp_iter */
91 0, /* tp_iternext */
92 0, /* tp_methods */
93 0, /* tp_members */
94 0, /* tp_getset */
95 0, /* tp_base */
96 0, /* tp_dict */
97 0, /* tp_descr_get */
98 0, /* tp_descr_set */
99 0, /* tp_dictoffset */
100 0, /* tp_init */
101 0, /* tp_alloc */
102 0, /* tp_new */
103 };
104
105 static PyTypeObject PyTicketType = {
106 PyObject_HEAD_INIT(NULL)
107 0, /* ob_size */
108 PY_MODULE "." PY_CSNAME2, /* tp_name */
109 sizeof (PyTicket), /* tp_basicsize */
110 0, /* tp_itemsize */
111 (destructor)py_dealloc, /* tp_dealloc */
112 0, /* tp_print */
113 0, /* tp_getattr; __getattr__ */
114 0, /* tp_setattr; __setattr__ */
115 0, /* tp_compare; __cmp__ */
116 _repr2, /* tp_repr; __repr__ */
117 0, /* tp_as_number */
118 0, /* tp_as_sequence */
119 0, /* tp_as_mapping */
120 0, /* tp_hash; __hash__ */
121 0, /* tp_call; __call__ */
122 _repr2, /* tp_str; __str__ */
123 0, /* tp_getattro */
124 0, /* tp_setattro */
125 0, /* tp_as_buffer */
126 Py_TPFLAGS_DEFAULT, /* tp_flags */
127 "", /* tp_doc */
128 0, /* tp_traverse */
129 0, /* tp_clear */
130 0, /* tp_richcompare */
131 0, /* tp_weaklistoffset */
132 0, /* tp_iter */
133 0, /* tp_iternext */
134 0, /* tp_methods */
135 0, /* tp_members */
136 0, /* tp_getset */
137 0, /* tp_base */
138 0, /* tp_dict */
139 0, /* tp_descr_get */
140 0, /* tp_descr_set */
141 0, /* tp_dictoffset */
142 0, /* tp_init */
143 0, /* tp_alloc */
144 0, /* tp_new */
145 };
146
147 static PyTypeObject PyWicketType = {
148 PyObject_HEAD_INIT(NULL)
149 0, /* ob_size */
150 PY_MODULE "." PY_CSNAME3, /* tp_name */
151 sizeof (PyWicket), /* tp_basicsize */
152 0, /* tp_itemsize */
153 (destructor)py_dealloc, /* tp_dealloc */
154 0, /* tp_print */
155 0, /* tp_getattr; __getattr__ */
156 0, /* tp_setattr; __setattr__ */
157 0, /* tp_compare; __cmp__ */
158 _repr3, /* tp_repr; __repr__ */
159 0, /* tp_as_number */
160 0, /* tp_as_sequence */
161 0, /* tp_as_mapping */
162 0, /* tp_hash; __hash__ */
163 0, /* tp_call; __call__ */
164 _repr3, /* tp_str; __str__ */
165 0, /* tp_getattro */
166 0, /* tp_setattro */
167 0, /* tp_as_buffer */
168 Py_TPFLAGS_DEFAULT, /* tp_flags */
169 "", /* tp_doc */
170 0, /* tp_traverse */
171 0, /* tp_clear */
172 0, /* tp_richcompare */
173 0, /* tp_weaklistoffset */
174 0, /* tp_iter */
175 0, /* tp_iternext */
176 0, /* tp_methods */
177 0, /* tp_members */
178 0, /* tp_getset */
179 0, /* tp_base */
180 0, /* tp_dict */
181 0, /* tp_descr_get */
182 0, /* tp_descr_set */
183 0, /* tp_dictoffset */
184 0, /* tp_init */
185 0, /* tp_alloc */
186 0, /* tp_new */
187 };
188
189 void
190 _dealloc4 (PyObject *self)
191 {
192 PyAuthData *py_ad = (PyAuthData *)self;
193 if (py_ad->auth_data)
194 mu_auth_data_free (py_ad->auth_data);
195 self->ob_type->tp_free (self);
196 }
197
198 static PyObject *
199 _getattr4 (PyObject *self, char *name)
200 {
201 PyAuthData *py_ad = (PyAuthData *)self;
202 struct mu_auth_data *ad = py_ad->auth_data;
203
204 if (!ad)
205 return NULL;
206
207 if (strcmp (name, "name") == 0) {
208 return PyString_FromString (ad->name);
209 }
210 else if (strcmp (name, "passwd") == 0) {
211 return PyString_FromString (ad->passwd);
212 }
213 else if (strcmp (name, "uid") == 0) {
214 return PyInt_FromLong (ad->uid);
215 }
216 else if (strcmp (name, "gid") == 0) {
217 return PyInt_FromLong (ad->gid);
218 }
219 else if (strcmp (name, "gecos") == 0) {
220 return PyString_FromString (ad->gecos);
221 }
222 else if (strcmp (name, "dir") == 0) {
223 return PyString_FromString (ad->dir);
224 }
225 else if (strcmp (name, "shell") == 0) {
226 return PyString_FromString (ad->shell);
227 }
228 else if (strcmp (name, "mailbox") == 0) {
229 return PyString_FromString (ad->mailbox);
230 }
231 else if (strcmp (name, "source") == 0) {
232 return PyString_FromString (ad->source);
233 }
234 else if (strcmp (name, "quota") == 0) {
235 return PyInt_FromLong (ad->quota);
236 }
237 else if (strcmp (name, "flags") == 0) {
238 return PyInt_FromLong (ad->flags);
239 }
240 else if (strcmp (name, "change_uid") == 0) {
241 return PyInt_FromLong (ad->change_uid);
242 }
243 return NULL;
244 }
245
246 static PyTypeObject PyAuthDataType = {
247 PyObject_HEAD_INIT(NULL)
248 0, /* ob_size */
249 PY_MODULE "." PY_CSNAME4, /* tp_name */
250 sizeof (PyAuthData), /* tp_basicsize */
251 0, /* tp_itemsize */
252 (destructor)_dealloc4, /* tp_dealloc */
253 0, /* tp_print */
254 _getattr4, /* tp_getattr; __getattr__ */
255 0, /* tp_setattr; __setattr__ */
256 0, /* tp_compare; __cmp__ */
257 _repr4, /* tp_repr; __repr__ */
258 0, /* tp_as_number */
259 0, /* tp_as_sequence */
260 0, /* tp_as_mapping */
261 0, /* tp_hash; __hash__ */
262 0, /* tp_call; __call__ */
263 _repr4, /* tp_str; __str__ */
264 0, /* tp_getattro */
265 0, /* tp_setattro */
266 0, /* tp_as_buffer */
267 Py_TPFLAGS_DEFAULT, /* tp_flags */
268 "", /* tp_doc */
269 0, /* tp_traverse */
270 0, /* tp_clear */
271 0, /* tp_richcompare */
272 0, /* tp_weaklistoffset */
273 0, /* tp_iter */
274 0, /* tp_iternext */
275 0, /* tp_methods */
276 0, /* tp_members */
277 0, /* tp_getset */
278 0, /* tp_base */
279 0, /* tp_dict */
280 0, /* tp_descr_get */
281 0, /* tp_descr_set */
282 0, /* tp_dictoffset */
283 0, /* tp_init */
284 0, /* tp_alloc */
285 0, /* tp_new */
286 };
287
288 PyAuthority *
289 PyAuthority_NEW ()
290 {
291 return (PyAuthority *)PyObject_NEW (PyAuthority, &PyAuthorityType);
292 }
293
294 int
295 PyAuthority_Check (PyObject *x)
296 {
297 return x->ob_type == &PyAuthorityType;
298 }
299
300 PyTicket *
301 PyTicket_NEW ()
302 {
303 return (PyTicket *)PyObject_NEW (PyTicket, &PyTicketType);
304 }
305
306 int
307 PyTicket_Check (PyObject *x)
308 {
309 return x->ob_type == &PyTicketType;
310 }
311
312 PyWicket *
313 PyWicket_NEW ()
314 {
315 return (PyWicket *)PyObject_NEW (PyWicket, &PyWicketType);
316 }
317
318 int
319 PyWicket_Check (PyObject *x)
320 {
321 return x->ob_type == &PyWicketType;
322 }
323
324 PyAuthData *
325 PyAuthData_NEW ()
326 {
327 return (PyAuthData *)PyObject_NEW (PyAuthData, &PyAuthDataType);
328 }
329
330 int
331 PyAuthData_Check (PyObject *x)
332 {
333 return x->ob_type == &PyAuthDataType;
334 }
335
336 /*
337 * Authority
338 */
339
340 static PyObject *
341 api_authority_create (PyObject *self, PyObject *args)
342 {
343 int status;
344 PyAuthority *py_auth;
345 PyTicket *py_ticket;
346
347 if (!PyArg_ParseTuple (args, "O!O!",
348 &PyAuthorityType, &py_auth,
349 &PyTicketType, &py_ticket))
350 return NULL;
351
352 status = mu_authority_create (&py_auth->auth, py_ticket->ticket, NULL);
353 return _ro (PyInt_FromLong (status));
354 }
355
356 static PyObject *
357 api_authority_destroy (PyObject *self, PyObject *args)
358 {
359 PyAuthority *py_auth;
360
361 if (!PyArg_ParseTuple (args, "O!", &PyAuthorityType, &py_auth))
362 return NULL;
363
364 mu_authority_destroy (&py_auth->auth, NULL);
365 return _ro (Py_None);
366 }
367
368 static PyObject *
369 api_authority_get_ticket (PyObject *self, PyObject *args)
370 {
371 int status;
372 PyAuthority *py_auth;
373 PyTicket *py_ticket = PyTicket_NEW ();
374
375 if (!PyArg_ParseTuple (args, "O!", &PyAuthorityType, &py_auth))
376 return NULL;
377
378 Py_INCREF (py_ticket);
379
380 status = mu_authority_get_ticket (py_auth->auth, &py_ticket->ticket);
381 return status_object (status, (PyObject *)py_ticket);
382 }
383
384 static PyObject *
385 api_authority_set_ticket (PyObject *self, PyObject *args)
386 {
387 int status;
388 PyAuthority *py_auth;
389 PyTicket *py_ticket;
390
391 if (!PyArg_ParseTuple (args, "O!O!",
392 &PyAuthorityType, &py_auth,
393 &PyTicketType, &py_ticket))
394 return NULL;
395
396 status = mu_authority_set_ticket (py_auth->auth, py_ticket->ticket);
397 return _ro (PyInt_FromLong (status));
398 }
399
400 static PyObject *
401 api_authority_authenticate (PyObject *self, PyObject *args)
402 {
403 int status;
404 PyAuthority *py_auth;
405
406 if (!PyArg_ParseTuple (args, "O!", &PyAuthorityType, &py_auth))
407 return NULL;
408
409 status = mu_authority_authenticate (py_auth->auth);
410 return _ro (PyInt_FromLong (status));
411 }
412
413 /*
414 * Ticket
415 */
416
417 static PyObject *
418 api_ticket_create (PyObject *self, PyObject *args)
419 {
420 int status;
421 PyTicket *py_ticket;
422
423 if (!PyArg_ParseTuple (args, "O!", &PyTicketType, &py_ticket))
424 return NULL;
425
426 status = mu_ticket_create (&py_ticket->ticket, NULL);
427 return _ro (PyInt_FromLong (status));
428 }
429
430 static PyObject *
431 api_ticket_destroy (PyObject *self, PyObject *args)
432 {
433 PyTicket *py_ticket;
434
435 if (!PyArg_ParseTuple (args, "O!", &PyTicketType, &py_ticket))
436 return NULL;
437
438 mu_ticket_destroy (&py_ticket->ticket, NULL);
439 return _ro (Py_None);
440 }
441
442 /*
443 * Wicket
444 */
445
446 static PyObject *
447 api_wicket_create (PyObject *self, PyObject *args)
448 {
449 int status;
450 char *filename;
451 PyWicket *py_wicket;
452
453 if (!PyArg_ParseTuple (args, "O!s", &PyWicketType, &py_wicket, &filename))
454 return NULL;
455
456 status = mu_wicket_create (&py_wicket->wicket, filename);
457 return _ro (PyInt_FromLong (status));
458 }
459
460 static PyObject *
461 api_wicket_destroy (PyObject *self, PyObject *args)
462 {
463 PyWicket *py_wicket;
464
465 if (!PyArg_ParseTuple (args, "O!", &PyWicketType, &py_wicket))
466 return NULL;
467
468 mu_wicket_destroy (&py_wicket->wicket);
469 return _ro (Py_None);
470 }
471
472 static PyObject *
473 api_wicket_get_filename (PyObject *self, PyObject *args)
474 {
475 int status;
476 size_t n;
477 char filename[512];
478 PyWicket *py_wicket;
479
480 memset (filename, 0, sizeof (filename));
481
482 if (!PyArg_ParseTuple (args, "O!", &PyWicketType, &py_wicket))
483 return NULL;
484
485 status = mu_wicket_get_filename (py_wicket->wicket, filename,
486 sizeof (filename), &n);
487 return status_object (status, PyString_FromString (filename));
488 }
489
490 static PyObject *
491 api_wicket_set_filename (PyObject *self, PyObject *args)
492 {
493 int status;
494 char *filename;
495 PyWicket *py_wicket;
496
497 if (!PyArg_ParseTuple (args, "O!s", &PyWicketType, &py_wicket, &filename))
498 return NULL;
499
500 status = mu_wicket_set_filename (py_wicket->wicket, filename);
501 return _ro (PyInt_FromLong (status));
502 }
503
504 /*
505 * mu_auth
506 */
507
508 struct module_record {
509 char *name;
510 struct mu_auth_module *module;
511 };
512
513 static struct module_record module_table[] = {
514 { "system", &mu_auth_system_module },
515 { "generic", &mu_auth_generic_module },
516 { "pam", &mu_auth_pam_module },
517 { "sql", &mu_auth_sql_module },
518 { "virtual", &mu_auth_virtual_module },
519 { "radius", &mu_auth_radius_module },
520 { "ldap", &mu_auth_ldap_module },
521 { NULL, NULL },
522 };
523
524 static struct mu_auth_module *
525 find_module (const struct module_record *table, const char *name)
526 {
527 for (; table->name; table++)
528 if (strcmp (table->name, name) == 0)
529 break;
530 return table->module;
531 }
532
533 static int
534 register_module (const char *name)
535 {
536 int status = 0;
537
538 if (!name)
539 {
540 struct module_record *table;
541 for (table = module_table; table->name; table++)
542 mu_auth_register_module (table->module);
543 }
544 else
545 {
546 struct mu_auth_module *module = find_module (module_table, name);
547 if (module)
548 mu_auth_register_module (module);
549 else
550 status = EINVAL;
551 }
552 return status;
553 }
554
555 static PyObject *
556 api_register_module (PyObject *self, PyObject *args)
557 {
558 int status;
559 char *name = NULL;
560
561 if (!PyArg_ParseTuple (args, "|s", &name))
562 return NULL;
563
564 status = register_module (name);
565 return _ro (PyInt_FromLong (status));
566 }
567
568 static PyObject *
569 api_get_auth_by_name (PyObject *self, PyObject *args)
570 {
571 int status;
572 char *username;
573 PyAuthData *py_ad = PyAuthData_NEW ();
574
575 if (!PyArg_ParseTuple (args, "s", &username))
576 return NULL;
577
578 Py_INCREF (py_ad);
579
580 py_ad->auth_data = mu_get_auth_by_name (username);
581 if (!py_ad->auth_data)
582 return _ro (Py_None);
583
584 return _ro ((PyObject *)py_ad);
585 }
586
587 static PyObject *
588 api_get_auth_by_uid (PyObject *self, PyObject *args)
589 {
590 int status;
591 uid_t uid;
592 PyAuthData *py_ad = PyAuthData_NEW ();
593
594 if (!PyArg_ParseTuple (args, "i", &uid))
595 return NULL;
596
597 Py_INCREF (py_ad);
598
599 py_ad->auth_data = mu_get_auth_by_uid (uid);
600 if (!py_ad->auth_data)
601 return _ro (Py_None);
602
603 return _ro ((PyObject *)py_ad);
604 }
605
606 static PyObject *
607 api_authenticate (PyObject *self, PyObject *args)
608 {
609 int status;
610 char *pass;
611 PyAuthData *py_ad;
612
613 if (!PyArg_ParseTuple (args, "O!s", &PyAuthDataType, &py_ad, &pass))
614 return NULL;
615
616 status = mu_authenticate (py_ad->auth_data, pass);
617 return _ro (PyInt_FromLong (status));
618 }
619
620
621 static PyMethodDef methods[] = {
622 { "authority_create", (PyCFunction) api_authority_create, METH_VARARGS,
623 "" },
624
625 { "authority_destroy", (PyCFunction) api_authority_destroy, METH_VARARGS,
626 "" },
627
628 { "authority_get_ticket", (PyCFunction) api_authority_get_ticket,
629 METH_VARARGS, "" },
630
631 { "authority_set_ticket", (PyCFunction) api_authority_set_ticket,
632 METH_VARARGS, "" },
633
634 { "authority_authenticate", (PyCFunction) api_authority_authenticate,
635 METH_VARARGS, "" },
636
637 { "ticket_create", (PyCFunction) api_ticket_create, METH_VARARGS,
638 "" },
639
640 { "ticket_destroy", (PyCFunction) api_ticket_destroy, METH_VARARGS,
641 "" },
642
643 { "wicket_create", (PyCFunction) api_wicket_create, METH_VARARGS,
644 "" },
645
646 { "wicket_destroy", (PyCFunction) api_wicket_destroy, METH_VARARGS,
647 "" },
648
649 { "wicket_get_filename", (PyCFunction) api_wicket_get_filename, METH_VARARGS,
650 "" },
651
652 { "wicket_set_filename", (PyCFunction) api_wicket_set_filename, METH_VARARGS,
653 "" },
654
655 { "register_module", (PyCFunction) api_register_module, METH_VARARGS,
656 "" },
657
658 { "get_auth_by_name", (PyCFunction) api_get_auth_by_name, METH_VARARGS,
659 "" },
660
661 { "get_auth_by_uid", (PyCFunction) api_get_auth_by_uid, METH_VARARGS,
662 "" },
663
664 { "authenticate", (PyCFunction) api_authenticate, METH_VARARGS,
665 "" },
666
667 { NULL, NULL, 0, NULL }
668 };
669
670 void
671 init_auth ()
672 {
673 PyObject *m;
674
675 PyAuthorityType.tp_new = PyType_GenericNew;
676 PyTicketType.tp_new = PyType_GenericNew;
677 PyWicketType.tp_new = PyType_GenericNew;
678 PyAuthDataType.tp_new = PyType_GenericNew;
679
680 if (PyType_Ready (&PyAuthorityType) < 0)
681 return;
682 if (PyType_Ready (&PyTicketType) < 0)
683 return;
684 if (PyType_Ready (&PyWicketType) < 0)
685 return;
686 if (PyType_Ready (&PyAuthDataType) < 0)
687 return;
688
689 if ((m = attach_module (PY_MODULE, methods)))
690 {
691 Py_INCREF (&PyAuthorityType);
692 Py_INCREF (&PyTicketType);
693 Py_INCREF (&PyWicketType);
694 Py_INCREF (&PyAuthDataType);
695
696 PyModule_AddObject (m, PY_CSNAME1, (PyObject *)&PyAuthorityType);
697 PyModule_AddObject (m, PY_CSNAME2, (PyObject *)&PyTicketType);
698 PyModule_AddObject (m, PY_CSNAME3, (PyObject *)&PyWicketType);
699 PyModule_AddObject (m, PY_CSNAME4, (PyObject *)&PyAuthDataType);
700 }
701 }
1 /*
2 GNU Mailutils -- a suite of utilities for electronic mail
3 Copyright (C) 2009 Free Software Foundation, Inc.
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 3 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General
16 Public License along with this library; if not, write to the
17 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301 USA
19 */
20
21 #ifndef _MUCAPI_BODY_H
22 #define _MUCAPI_BODY_H
23
24 #include <mailutils/body.h>
25
26 typedef struct {
27 PyObject_HEAD;
28 mu_body_t body;
29 } PyBody;
30
31 extern PyBody * PyBody_NEW ();
32
33 #endif /* not _MUCAPI_BODY_H */
1 /*
2 GNU Mailutils -- a suite of utilities for electronic mail
3 Copyright (C) 2009 Free Software Foundation, Inc.
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 3 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General
16 Public License along with this library; if not, write to the
17 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301 USA
19 */
20
21 #include "c_api.h"
22 #include "body-private.h"
23 #include "stream-private.h"
24
25 #define PY_MODULE "body"
26 #define PY_CSNAME "BodyType"
27
28 static PyObject *
29 _repr (PyObject *self)
30 {
31 char buf[80];
32 sprintf (buf, "<" PY_MODULE "." PY_CSNAME " instance at %p>", self);
33 return PyString_FromString (buf);
34 }
35
36 static PyTypeObject PyBodyType = {
37 PyObject_HEAD_INIT(NULL)
38 0, /* ob_size */
39 PY_MODULE "." PY_CSNAME, /* tp_name */
40 sizeof (PyBody), /* tp_basicsize */
41 0, /* tp_itemsize */
42 (destructor)py_dealloc, /* tp_dealloc */
43 0, /* tp_print */
44 0, /* tp_getattr; __getattr__ */
45 0, /* tp_setattr; __setattr__ */
46 0, /* tp_compare; __cmp__ */
47 _repr, /* tp_repr; __repr__ */
48 0, /* tp_as_number */
49 0, /* tp_as_sequence */
50 0, /* tp_as_mapping */
51 0, /* tp_hash; __hash__ */
52 0, /* tp_call; __call__ */
53 _repr, /* tp_str; __str__ */
54 0, /* tp_getattro */
55 0, /* tp_setattro */
56 0, /* tp_as_buffer */
57 Py_TPFLAGS_DEFAULT, /* tp_flags */
58 "", /* tp_doc */
59 0, /* tp_traverse */
60 0, /* tp_clear */
61 0, /* tp_richcompare */
62 0, /* tp_weaklistoffset */
63 0, /* tp_iter */
64 0, /* tp_iternext */
65 0, /* tp_methods */
66 0, /* tp_members */
67 0, /* tp_getset */
68 0, /* tp_base */
69 0, /* tp_dict */
70 0, /* tp_descr_get */
71 0, /* tp_descr_set */
72 0, /* tp_dictoffset */
73 0, /* tp_init */
74 0, /* tp_alloc */
75 0, /* tp_new */
76 };
77
78 PyBody *
79 PyBody_NEW ()
80 {
81 return (PyBody *)PyObject_NEW (PyBody, &PyBodyType);
82 }
83
84 static PyObject *
85 api_body_size (PyObject *self, PyObject *args)
86 {
87 int status;
88 size_t size;
89 PyBody *py_body;
90
91 if (!PyArg_ParseTuple (args, "O!", &PyBodyType, &py_body))
92 return NULL;
93
94 status = mu_body_size (py_body->body, &size);
95 return status_object (status, PyInt_FromLong (size));
96 }
97
98 static PyObject *
99 api_body_lines (PyObject *self, PyObject *args)
100 {
101 int status;
102 size_t lines;
103 PyBody *py_body;
104
105 if (!PyArg_ParseTuple (args, "O!", &PyBodyType, &py_body))
106 return NULL;
107
108 status = mu_body_lines (py_body->body, &lines);
109 return status_object (status, PyInt_FromLong (lines));
110 }
111
112 static PyObject *
113 api_body_get_stream (PyObject *self, PyObject *args)
114 {
115 int status;
116 size_t lines;
117 PyBody *py_body;
118 PyStream *py_stm = PyStream_NEW ();
119
120 if (!PyArg_ParseTuple (args, "O!", &PyBodyType, &py_body))
121 return NULL;
122
123 Py_INCREF (py_stm);
124
125 status = mu_body_get_stream (py_body->body, &py_stm->stm);
126 return status_object (status, (PyObject *)py_stm);
127 }
128
129 static PyMethodDef methods[] = {
130 { "size", (PyCFunction) api_body_size, METH_VARARGS,
131 "Retrieve BODY size." },
132
133 { "lines", (PyCFunction) api_body_lines, METH_VARARGS,
134 "Retrieve BODY number of lines." },
135
136 { "get_stream", (PyCFunction) api_body_get_stream, METH_VARARGS,
137 "" },
138
139 { NULL, NULL, 0, NULL }
140 };
141
142 void
143 init_body ()
144 {
145 PyObject *m;
146
147 PyBodyType.tp_new = PyType_GenericNew;
148 if (PyType_Ready (&PyBodyType) < 0)
149 return;
150
151 if ((m = attach_module (PY_MODULE, methods)))
152 {
153 Py_INCREF (&PyBodyType);
154 PyModule_AddObject (m, PY_CSNAME, (PyObject *)&PyBodyType);
155 }
156 }
1 /*
2 GNU Mailutils -- a suite of utilities for electronic mail
3 Copyright (C) 2009 Free Software Foundation, Inc.
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 3 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General
16 Public License along with this library; if not, write to the
17 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301 USA
19 */
20
21 #include "c_api.h"
22
23 inline PyObject *
24 _ro (PyObject *obj)
25 {
26 Py_INCREF (obj);
27 return obj;
28 }
29
30 void
31 py_dealloc (PyObject *self)
32 {
33 self->ob_type->tp_free (self);
34 }
35
36 PyObject *
37 status_object (int status, PyObject *py_obj)
38 {
39 PyObject *py_ret = PyTuple_New (2);
40 PyTuple_SetItem (py_ret, 0, PyInt_FromLong (status));
41 PyTuple_SetItem (py_ret, 1, py_obj);
42 return _ro (py_ret);
43 }
44
45 static PyMethodDef nomethods[] = {
46 { NULL, NULL }
47 };
48
49 static PyObject *package;
50 static PyObject *all;
51
52 PyObject *
53 attach_module (const char *name, PyMethodDef *methods)
54 {
55 PyObject *module, *m;
56
57 char ns[64] = PY_PACKAGE_NAME "." PY_ROOT_NAME ".";
58 strcat (ns, name);
59
60 if (!(module = PyImport_AddModule (ns)))
61 return NULL;
62
63 if (PyModule_AddObject (package, name, module))
64 return NULL;
65
66 Py_INCREF (module);
67
68 if (!(m = Py_InitModule (ns, methods)))
69 return NULL;
70
71 PyList_Append (all, PyString_FromString (name));
72 return m;
73 }
74
75 PyMODINIT_FUNC
76 initc_api (void)
77 {
78 package = Py_InitModule (PY_ROOT_NAME, nomethods);
79 if (!package)
80 return;
81
82 PyModule_AddStringConstant (package, "__version__", PY_PACKAGE_VERSION);
83 if (!PyModule_AddObject (package, "__all__", _ro (PyList_New (0))))
84 {
85 all = PyObject_GetAttrString (package, "__all__");
86 if (!all || !PyList_Check (all))
87 return;
88 }
89
90 init_error ();
91 init_address ();
92 init_attribute ();
93 init_auth ();
94 init_body ();
95 init_debug ();
96 init_envelope ();
97 init_header ();
98 init_filter ();
99 init_folder ();
100 init_mailer ();
101 init_mailbox ();
102 init_mailcap ();
103 init_message ();
104 init_mime ();
105 init_registrar ();
106 init_stream ();
107 init_url ();
108 init_util ();
109 }
1 /*
2 GNU Mailutils -- a suite of utilities for electronic mail
3 Copyright (C) 2009 Free Software Foundation, Inc.
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 3 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General
16 Public License along with this library; if not, write to the
17 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301 USA
19 */
20
21 #ifdef HAVE_CONFIG_H
22 # include <config.h>
23 #endif
24
25 #include <Python.h>
26
27 #define PY_PACKAGE_NAME "mailutils"
28 #define PY_ROOT_NAME "c_api"
29 #define PY_PACKAGE_VERSION PACKAGE_VERSION
30
31 extern inline PyObject * _ro (PyObject *obj);
32 extern void py_dealloc (PyObject *self);
33 extern PyObject * status_object (int status, PyObject *py_obj);
34 extern PyObject * attach_module (const char *name, PyMethodDef *methods);
35
36 extern void init_error ();
37 extern void init_address ();
38 extern void init_attribute ();
39 extern void init_auth ();
40 extern void init_body ();
41 extern void init_debug ();
42 extern void init_envelope ();
43 extern void init_header ();
44 extern void init_filter ();
45 extern void init_folder ();
46 extern void init_mailer ();
47 extern void init_mailbox ();
48 extern void init_mailcap ();
49 extern void init_message ();
50 extern void init_mime ();
51 extern void init_registrar ();
52 extern void init_stream ();
53 extern void init_url ();
54 extern void init_util ();
1 /*
2 GNU Mailutils -- a suite of utilities for electronic mail
3 Copyright (C) 2009 Free Software Foundation, Inc.
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 3 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General
16 Public License along with this library; if not, write to the
17 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301 USA
19 */
20
21 #ifndef _MUCAPI_DEBUG_H
22 #define _MUCAPI_DEBUG_H
23
24 #include <mailutils/debug.h>
25
26 typedef struct {
27 PyObject_HEAD;
28 mu_debug_t dbg;
29 } PyDebug;
30
31 extern PyDebug * PyDebug_NEW ();
32
33 #endif /* not _MUCAPI_DEBUG_H */
1 /*
2 GNU Mailutils -- a suite of utilities for electronic mail
3 Copyright (C) 2009 Free Software Foundation, Inc.
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 3 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General
16 Public License along with this library; if not, write to the
17 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301 USA
19 */
20
21 #include "c_api.h"
22 #include "debug-private.h"
23
24 #define PY_MODULE "debug"
25 #define PY_CSNAME "DebugType"
26
27 static PyObject *
28 _repr (PyObject *self)
29 {
30 char buf[80];
31 sprintf (buf, "<" PY_MODULE "." PY_CSNAME " instance at %p>", self);
32 return PyString_FromString (buf);
33 }
34
35 static PyTypeObject PyDebugType = {
36 PyObject_HEAD_INIT(NULL)
37 0, /* ob_size */
38 PY_MODULE "." PY_CSNAME, /* tp_name */
39 sizeof (PyDebug), /* tp_basicsize */
40 0, /* tp_itemsize */
41 (destructor)py_dealloc, /* tp_dealloc */
42 0, /* tp_print */
43 0, /* tp_getattr; __getattr__ */
44 0, /* tp_setattr; __setattr__ */
45 0, /* tp_compare; __cmp__ */
46 _repr, /* tp_repr; __repr__ */
47 0, /* tp_as_number */
48 0, /* tp_as_sequence */
49 0, /* tp_as_mapping */
50 0, /* tp_hash; __hash__ */
51 0, /* tp_call; __call__ */
52 _repr, /* tp_str; __str__ */
53 0, /* tp_getattro */
54 0, /* tp_setattro */
55 0, /* tp_as_buffer */
56 Py_TPFLAGS_DEFAULT, /* tp_flags */
57 "", /* tp_doc */
58 0, /* tp_traverse */
59 0, /* tp_clear */
60 0, /* tp_richcompare */
61 0, /* tp_weaklistoffset */
62 0, /* tp_iter */
63 0, /* tp_iternext */
64 0, /* tp_methods */
65 0, /* tp_members */
66 0, /* tp_getset */
67 0, /* tp_base */
68 0, /* tp_dict */
69 0, /* tp_descr_get */
70 0, /* tp_descr_set */
71 0, /* tp_dictoffset */
72 0, /* tp_init */
73 0, /* tp_alloc */
74 0, /* tp_new */
75 };
76
77 PyDebug *
78 PyDebug_NEW ()
79 {
80 return (PyDebug *)PyObject_NEW (PyDebug, &PyDebugType);
81 }
82
83 static PyObject *
84 api_debug_set_level (PyObject *self, PyObject *args)
85 {
86 int status, level;
87 PyDebug *py_dbg;
88
89 if (!PyArg_ParseTuple (args, "O!i", &PyDebugType, &py_dbg, &level))
90 return NULL;
91
92 status = mu_debug_set_level (py_dbg->dbg,
93 MU_DEBUG_LEVEL_UPTO (level));
94 return _ro (PyInt_FromLong (status));
95 }
96
97 static PyMethodDef methods[] = {
98 { "set_level", (PyCFunction) api_debug_set_level, METH_VARARGS,
99 "" },
100
101 { NULL, NULL, 0, NULL }
102 };
103
104 void
105 init_debug ()
106 {
107 PyObject *m;
108
109 PyDebugType.tp_new = PyType_GenericNew;
110 if (PyType_Ready (&PyDebugType) < 0)
111 return;
112
113 if ((m = attach_module (PY_MODULE, methods)))
114 {
115 Py_INCREF (&PyDebugType);
116 PyModule_AddObject (m, PY_CSNAME, (PyObject *)&PyDebugType);
117 }
118 }
1 /*
2 GNU Mailutils -- a suite of utilities for electronic mail
3 Copyright (C) 2009 Free Software Foundation, Inc.
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 3 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General
16 Public License along with this library; if not, write to the
17 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301 USA
19 */
20
21 #ifndef _MUCAPI_ENVELOPE_H
22 #define _MUCAPI_ENVELOPE_H
23
24 #include <mailutils/envelope.h>
25
26 typedef struct {
27 PyObject_HEAD;
28 mu_envelope_t env;
29 } PyEnvelope;
30
31 extern PyEnvelope * PyEnvelope_NEW ();
32
33 #endif /* not _MUCAPI_ENVELOPE_H */
1 /*
2 GNU Mailutils -- a suite of utilities for electronic mail
3 Copyright (C) 2009 Free Software Foundation, Inc.
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 3 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General
16 Public License along with this library; if not, write to the
17 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301 USA
19 */
20
21 #include "c_api.h"
22 #include "envelope-private.h"
23
24 #define PY_MODULE "envelope"
25 #define PY_CSNAME "EnvelopeType"
26
27 static PyObject *
28 _repr (PyObject *self)
29 {
30 char buf[80];
31 sprintf (buf, "<" PY_MODULE "." PY_CSNAME " instance at %p>", self);
32 return PyString_FromString (buf);
33 }
34
35 static PyTypeObject PyEnvelopeType = {
36 PyObject_HEAD_INIT(NULL)
37 0, /* ob_size */
38 PY_MODULE "." PY_CSNAME, /* tp_name */
39 sizeof (PyEnvelope), /* tp_basicsize */
40 0, /* tp_itemsize */
41 (destructor)py_dealloc, /* tp_dealloc */
42 0, /* tp_print */
43 0, /* tp_getattr; __getattr__ */
44 0, /* tp_setattr; __setattr__ */
45 0, /* tp_compare; __cmp__ */
46 _repr, /* tp_repr; __repr__ */
47 0, /* tp_as_number */
48 0, /* tp_as_sequence */
49 0, /* tp_as_mapping */
50 0, /* tp_hash; __hash__ */
51 0, /* tp_call; __call__ */
52 _repr, /* tp_str; __str__ */
53 0, /* tp_getattro */
54 0, /* tp_setattro */
55 0, /* tp_as_buffer */
56 Py_TPFLAGS_DEFAULT, /* tp_flags */
57 "", /* tp_doc */
58 0, /* tp_traverse */
59 0, /* tp_clear */
60 0, /* tp_richcompare */
61 0, /* tp_weaklistoffset */
62 0, /* tp_iter */
63 0, /* tp_iternext */
64 0, /* tp_methods */
65 0, /* tp_members */
66 0, /* tp_getset */
67 0, /* tp_base */
68 0, /* tp_dict */
69 0, /* tp_descr_get */
70 0, /* tp_descr_set */
71 0, /* tp_dictoffset */
72 0, /* tp_init */
73 0, /* tp_alloc */
74 0, /* tp_new */
75 };
76
77 PyEnvelope *
78 PyEnvelope_NEW ()
79 {
80 return (PyEnvelope *)PyObject_NEW (PyEnvelope, &PyEnvelopeType);
81 }
82
83 static PyObject *
84 api_envelope_create (PyObject *self, PyObject *args)
85 {
86 int status;
87 PyEnvelope *py_env;
88
89 if (!PyArg_ParseTuple (args, "O!", &PyEnvelopeType, &py_env))
90 return NULL;
91
92 status = mu_envelope_create (&py_env->env, NULL);
93 return _ro (PyInt_FromLong (status));
94 }
95
96 static PyObject *
97 api_envelope_destroy (PyObject *self, PyObject *args)
98 {
99 PyEnvelope *py_env;
100
101 if (!PyArg_ParseTuple (args, "O!", &PyEnvelopeType, &py_env))
102 return NULL;
103
104 mu_envelope_destroy (&py_env->env, NULL);
105 return _ro (Py_None);
106 }
107
108 static PyObject *
109 api_envelope_get_sender (PyObject *self, PyObject *args)
110 {
111 int status;
112 const char *sender = NULL;
113 PyEnvelope *py_env;
114
115 if (!PyArg_ParseTuple (args, "O!", &PyEnvelopeType, &py_env))
116 return NULL;
117
118 status = mu_envelope_sget_sender (py_env->env, &sender);
119 return status_object (status, PyString_FromString (sender ? sender : ""));
120 }
121
122 static PyObject *
123 api_envelope_get_date (PyObject *self, PyObject *args)
124 {
125 int status;
126 const char *date = NULL;
127 PyEnvelope *py_env;
128
129 if (!PyArg_ParseTuple (args, "O!", &PyEnvelopeType, &py_env))
130 return NULL;
131
132 status = mu_envelope_sget_date (py_env->env, &date);
133 return status_object (status, PyString_FromString (date ? date : ""));
134 }
135
136 static PyMethodDef methods[] = {
137 { "create", (PyCFunction) api_envelope_create, METH_VARARGS,
138 "" },
139
140 { "destroy", (PyCFunction) api_envelope_destroy, METH_VARARGS,
141 "" },
142
143 { "get_sender", (PyCFunction) api_envelope_get_sender, METH_VARARGS,
144 "Get the address that this message was reportedly received from." },
145
146 { "get_date", (PyCFunction) api_envelope_get_date, METH_VARARGS,
147 "Get the date that the message was delivered to the mailbox." },
148
149 { NULL, NULL, 0, NULL }
150 };
151
152 void
153 init_envelope ()
154 {
155 PyObject *m;
156
157 PyEnvelopeType.tp_new = PyType_GenericNew;
158 if (PyType_Ready (&PyEnvelopeType) < 0)
159 return;
160
161 if ((m = attach_module (PY_MODULE, methods)))
162 {
163 Py_INCREF (&PyEnvelopeType);
164 PyModule_AddObject (m, PY_CSNAME, (PyObject *)&PyEnvelopeType);
165 }
166 }
1 /*
2 GNU Mailutils -- a suite of utilities for electronic mail
3 Copyright (C) 2009 Free Software Foundation, Inc.
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 3 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General
16 Public License along with this library; if not, write to the
17 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301 USA
19 */
20
21 #include "c_api.h"
22
23 #define PY_MODULE "error"
24
25 static PyObject *
26 api_strerror (PyObject *self, PyObject *args)
27 {
28 int status;
29 char *str = NULL;
30
31 if (!PyArg_ParseTuple (args, "i", &status))
32 return NULL;
33
34 str = (char *)mu_strerror (status);
35 return _ro (PyString_FromString (str));
36 }
37
38 static PyMethodDef methods[] = {
39 { "strerror", (PyCFunction) api_strerror, METH_VARARGS,
40 "Return the error message corresponding to ERR, "
41 "which must be an integer value." },
42
43 { NULL, NULL, 0, NULL }
44 };
45
46 void
47 init_error ()
48 {
49 attach_module (PY_MODULE, methods);
50 }
1 /*
2 GNU Mailutils -- a suite of utilities for electronic mail
3 Copyright (C) 2009 Free Software Foundation, Inc.
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 3 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General
16 Public License along with this library; if not, write to the
17 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301 USA
19 */
20
21 #include "c_api.h"
22 #include "stream-private.h"
23 #include <mailutils/filter.h>
24
25 #define PY_MODULE "filter"
26
27 static PyObject *
28 api_filter_create (PyObject *self, PyObject *args)
29 {
30 int status, mode, flags;
31 char *code = NULL;
32 PyStream *py_stm, *py_transport;
33
34 if (!PyArg_ParseTuple (args, "OOsii",
35 &py_stm, &py_transport,
36 &code, &mode, &flags))
37 return NULL;
38
39 if (!PyStream_Check ((PyObject *)py_stm) &&
40 !PyStream_Check ((PyObject *)py_transport))
41 {
42 PyErr_SetString (PyExc_TypeError, "");
43 return NULL;
44 }
45
46 status = mu_filter_create (&py_stm->stm, py_transport->stm,
47 code, mode, flags);
48 return _ro (PyInt_FromLong (status));
49 }
50
51 static PyObject *
52 api_filter_iconv_create (PyObject *self, PyObject *args)
53 {
54 int status, flags;
55 char *fromcode = NULL;
56 char *tocode = NULL;
57 PyStream *py_stm, *py_transport;
58
59 if (!PyArg_ParseTuple (args, "OOssi",
60 &py_stm, &py_transport,
61 &fromcode, &tocode, &flags))
62 return NULL;
63
64 if (!PyStream_Check ((PyObject *)py_stm) &&
65 !PyStream_Check ((PyObject *)py_transport))
66 {
67 PyErr_SetString (PyExc_TypeError, "");
68 return NULL;
69 }
70
71 status = mu_filter_iconv_create (&py_stm->stm, py_transport->stm,
72 fromcode, tocode, flags,
73 mu_fallback_none);
74 return _ro (PyInt_FromLong (status));
75 }
76
77 static PyMethodDef methods[] = {
78 { "create", (PyCFunction) api_filter_create, METH_VARARGS,
79 "" },
80
81 { "iconv_create", (PyCFunction) api_filter_iconv_create, METH_VARARGS,
82 "" },
83
84 { NULL, NULL, 0, NULL }
85 };
86
87 void
88 init_filter ()
89 {
90 attach_module (PY_MODULE, methods);
91 }
1 /*
2 GNU Mailutils -- a suite of utilities for electronic mail
3 Copyright (C) 2009 Free Software Foundation, Inc.
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 3 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General
16 Public License along with this library; if not, write to the
17 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301 USA
19 */
20
21 #ifndef _MUCAPI_FOLDER_H
22 #define _MUCAPI_FOLDER_H
23
24 #include <mailutils/folder.h>
25
26 typedef struct {
27 PyObject_HEAD;
28 mu_folder_t folder;
29 } PyFolder;
30
31 extern PyFolder * PyFolder_NEW ();
32
33 #endif /* not _MUCAPI_FOLDER_H */
1 /*
2 GNU Mailutils -- a suite of utilities for electronic mail
3 Copyright (C) 2009 Free Software Foundation, Inc.
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 3 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General
16 Public License along with this library; if not, write to the
17 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301 USA
19 */
20
21 #include "c_api.h"
22 #include "folder-private.h"
23 #include "stream-private.h"
24 #include "auth-private.h"
25 #include "url-private.h"
26
27 #define PY_MODULE "folder"
28 #define PY_CSNAME "FolderType"
29
30 static PyObject *
31 _repr (PyObject *self)
32 {
33 char buf[80];
34 sprintf (buf, "<" PY_MODULE "." PY_CSNAME " instance at %p>", self);
35 return PyString_FromString (buf);
36 }
37
38 static PyTypeObject PyFolderType = {
39 PyObject_HEAD_INIT(NULL)
40 0, /* ob_size */
41 PY_MODULE "." PY_CSNAME, /* tp_name */
42 sizeof (PyFolder), /* tp_basicsize */
43 0, /* tp_itemsize */
44 (destructor)py_dealloc, /* tp_dealloc */
45 0, /* tp_print */
46 0, /* tp_getattr; __getattr__ */
47 0, /* tp_setattr; __setattr__ */
48 0, /* tp_compare; __cmp__ */
49 _repr, /* tp_repr; __repr__ */
50 0, /* tp_as_number */
51 0, /* tp_as_sequence */
52 0, /* tp_as_mapping */
53 0, /* tp_hash; __hash__ */
54 0, /* tp_call; __call__ */
55 _repr, /* tp_str; __str__ */
56 0, /* tp_getattro */
57 0, /* tp_setattro */
58 0, /* tp_as_buffer */
59 Py_TPFLAGS_DEFAULT, /* tp_flags */
60 "", /* tp_doc */
61 0, /* tp_traverse */
62 0, /* tp_clear */
63 0, /* tp_richcompare */
64 0, /* tp_weaklistoffset */
65 0, /* tp_iter */
66 0, /* tp_iternext */
67 0, /* tp_methods */
68 0, /* tp_members */
69 0, /* tp_getset */
70 0, /* tp_base */
71 0, /* tp_dict */
72 0, /* tp_descr_get */
73 0, /* tp_descr_set */
74 0, /* tp_dictoffset */
75 0, /* tp_init */
76 0, /* tp_alloc */
77 0, /* tp_new */
78 };
79
80 PyFolder *
81 PyFolder_NEW ()
82 {
83 return (PyFolder *)PyObject_NEW (PyFolder, &PyFolderType);
84 }
85
86 static PyObject *
87 api_folder_create (PyObject *self, PyObject *args)
88 {
89 int status;
90 char *name;
91 PyFolder *py_folder;
92
93 if (!PyArg_ParseTuple (args, "O!s", &PyFolderType, &py_folder, &name))
94 return NULL;
95
96 status = mu_folder_create (&py_folder->folder, name);
97 return _ro (PyInt_FromLong (status));
98 }
99
100 static PyObject *
101 api_folder_destroy (PyObject *self, PyObject *args)
102 {
103 PyFolder *py_folder;
104
105 if (!PyArg_ParseTuple (args, "O!", &PyFolderType, &py_folder))
106 return NULL;
107
108 mu_folder_destroy (&py_folder->folder);
109 return _ro (Py_None);
110 }
111
112 static PyObject *
113 api_folder_open (PyObject *self, PyObject *args)
114 {
115 int status;
116 PyFolder *py_folder;
117
118 if (!PyArg_ParseTuple (args, "O!", &PyFolderType, &py_folder))
119 return NULL;
120
121 status = mu_folder_open (py_folder->folder, MU_STREAM_READ);
122 return _ro (PyInt_FromLong (status));
123 }
124
125 static PyObject *
126 api_folder_close (PyObject *self, PyObject *args)
127 {
128 int status;
129 PyFolder *py_folder;
130
131 if (!PyArg_ParseTuple (args, "O!", &PyFolderType, &py_folder))
132 return NULL;
133
134 status = mu_folder_close (py_folder->folder);
135 return _ro (PyInt_FromLong (status));
136 }
137
138 static PyObject *
139 api_folder_get_stream (PyObject *self, PyObject *args)
140 {
141 int status;
142 PyFolder *py_folder;
143 PyStream *py_stm = PyStream_NEW ();
144
145 if (!PyArg_ParseTuple (args, "O!", &PyFolderType, &py_folder))
146 return NULL;
147
148 Py_INCREF (py_stm);
149
150 status = mu_folder_get_stream (py_folder->folder, &py_stm->stm);
151 return status_object (status, (PyObject *)py_stm);
152 }
153
154 static PyObject *
155 api_folder_set_stream (PyObject *self, PyObject *args)
156 {
157 int status;
158 PyFolder *py_folder;
159 PyStream *py_stm;
160
161 if (!PyArg_ParseTuple (args, "O!O", &PyFolderType, &py_folder, &py_stm))
162 return NULL;
163
164 if (!PyStream_Check ((PyObject *)py_stm))
165 {
166 PyErr_SetString (PyExc_TypeError, "");
167 return NULL;
168 }
169
170 status = mu_folder_set_stream (py_folder->folder, py_stm->stm);
171 return _ro (PyInt_FromLong (status));
172 }
173
174 static PyObject *
175 api_folder_get_authority (PyObject *self, PyObject *args)
176 {
177 int status;
178 PyFolder *py_folder;
179 PyAuthority *py_auth = PyAuthority_NEW ();
180
181 if (!PyArg_ParseTuple (args, "O!", &PyFolderType, &py_folder))
182 return NULL;
183
184 Py_INCREF (py_auth);
185
186 status = mu_folder_get_authority (py_folder->folder, &py_auth->auth);
187 return status_object (status, (PyObject *)py_auth);
188 }
189
190 static PyObject *
191 api_folder_set_authority (PyObject *self, PyObject *args)
192 {
193 int status;
194 PyFolder *py_folder;
195 PyAuthority *py_auth;
196
197 if (!PyArg_ParseTuple (args, "O!O", &PyFolderType, &py_folder, &py_auth))
198 return NULL;
199
200 if (!PyAuthority_Check ((PyObject *)py_auth))
201 {
202 PyErr_SetString (PyExc_TypeError, "");
203 return NULL;
204 }
205
206 status = mu_folder_set_authority (py_folder->folder, py_auth->auth);
207 return _ro (PyInt_FromLong (status));
208 }
209
210 static PyObject *
211 api_folder_get_url (PyObject *self, PyObject *args)
212 {
213 int status;
214 PyFolder *py_folder;
215 PyUrl *py_url = PyUrl_NEW ();
216
217 if (!PyArg_ParseTuple (args, "O!", &PyFolderType, &py_folder))
218 return NULL;
219
220 Py_INCREF (py_url);
221
222 status = mu_folder_get_url (py_folder->folder, &py_url->url);
223 return status_object (status, (PyObject *)py_url);
224 }
225
226 static int
227 folderdata_extractor (void *data, PyObject **dst)
228 {
229 struct mu_list_response *resp = (struct mu_list_response *)data;
230 char separator[4];
231
232 char *attr = (resp->type & MU_FOLDER_ATTRIBUTE_DIRECTORY) ? "d" :
233 (resp->type & MU_FOLDER_ATTRIBUTE_FILE) ? "f" : "-";
234
235 snprintf (separator, sizeof (separator), "%c", resp->separator);
236
237 *dst = PyTuple_New (4);
238 PyTuple_SetItem (*dst, 0, PyString_FromString (attr));
239 PyTuple_SetItem (*dst, 1, PyInt_FromLong (resp->level));
240 PyTuple_SetItem (*dst, 2, PyString_FromString (separator));
241 PyTuple_SetItem (*dst, 3, PyString_FromString (resp->name));
242 return 0;
243 }
244
245 static PyObject *
246 api_folder_list (PyObject *self, PyObject *args)
247 {
248 int status = 0;
249 size_t max_level = 0;
250 char *dirname, *pattern;
251 PyFolder *py_folder;
252 PyObject *py_list;
253 mu_list_t c_list = NULL;
254
255 if (!PyArg_ParseTuple (args, "O!zs|i", &PyFolderType, &py_folder,
256 &dirname, &pattern, &max_level))
257 return NULL;
258
259 status = mu_folder_list (py_folder->folder, dirname, pattern, max_level,
260 &c_list);
261
262 if (c_list)
263 py_list = mulist_to_pylist (c_list, folderdata_extractor);
264 else
265 py_list = PyTuple_New (0);
266
267 return status_object (status, py_list);
268 }
269
270 static PyMethodDef methods[] = {
271 { "create", (PyCFunction) api_folder_create, METH_VARARGS,
272 "" },
273
274 { "destroy", (PyCFunction) api_folder_destroy, METH_VARARGS,
275 "" },
276
277 { "open", (PyCFunction) api_folder_open, METH_VARARGS,
278 "" },
279
280 { "close", (PyCFunction) api_folder_close, METH_VARARGS,
281 "" },
282
283 { "get_stream", (PyCFunction) api_folder_get_stream, METH_VARARGS,
284 "" },
285
286 { "set_stream", (PyCFunction) api_folder_set_stream, METH_VARARGS,
287 "" },
288
289 { "get_authority", (PyCFunction) api_folder_get_authority, METH_VARARGS,
290 "" },
291
292 { "set_authority", (PyCFunction) api_folder_set_authority, METH_VARARGS,
293 "" },
294
295 { "get_url", (PyCFunction) api_folder_get_url, METH_VARARGS,
296 "" },
297
298 { "list", (PyCFunction) api_folder_list, METH_VARARGS,
299 "" },
300
301 { NULL, NULL, 0, NULL }
302 };
303
304 void
305 init_folder ()
306 {
307 PyObject *m;
308
309 PyFolderType.tp_new = PyType_GenericNew;
310 if (PyType_Ready (&PyFolderType) < 0)
311 return;
312
313 if ((m = attach_module (PY_MODULE, methods)))
314 {
315 Py_INCREF (&PyFolderType);
316 PyModule_AddObject (m, PY_CSNAME, (PyObject *)&PyFolderType);
317 }
318 }
1 /*
2 GNU Mailutils -- a suite of utilities for electronic mail
3 Copyright (C) 2009 Free Software Foundation, Inc.
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 3 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General
16 Public License along with this library; if not, write to the
17 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301 USA
19 */
20
21 #ifndef _MUCAPI_HEADER_H
22 #define _MUCAPI_HEADER_H
23
24 #include <mailutils/header.h>
25
26 typedef struct {
27 PyObject_HEAD;
28 mu_header_t hdr;
29 } PyHeader;
30
31 extern PyHeader * PyHeader_NEW ();
32
33 #endif /* not _MUCAPI_HEADER_H */
1 /*
2 GNU Mailutils -- a suite of utilities for electronic mail
3 Copyright (C) 2009 Free Software Foundation, Inc.
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 3 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General
16 Public License along with this library; if not, write to the
17 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301 USA
19 */
20
21 #include "c_api.h"
22 #include "header-private.h"
23
24 #define PY_MODULE "header"
25 #define PY_CSNAME "HeaderType"
26
27 static PyObject *
28 _repr (PyObject *self)
29 {
30 char buf[80];
31 sprintf (buf, "<" PY_MODULE "." PY_CSNAME " instance at %p>", self);
32 return PyString_FromString (buf);
33 }
34
35 static PyTypeObject PyHeaderType = {
36 PyObject_HEAD_INIT(NULL)
37 0, /* ob_size */
38 PY_MODULE "." PY_CSNAME, /* tp_name */
39 sizeof (PyHeader), /* tp_basicsize */
40 0, /* tp_itemsize */
41 (destructor)py_dealloc, /* tp_dealloc */
42 0, /* tp_print */
43 0, /* tp_getattr; __getattr__ */
44 0, /* tp_setattr; __setattr__ */
45 0, /* tp_compare; __cmp__ */
46 _repr, /* tp_repr; __repr__ */
47 0, /* tp_as_number */
48 0, /* tp_as_sequence */
49 0, /* tp_as_mapping */
50 0, /* tp_hash; __hash__ */
51 0, /* tp_call; __call__ */
52 _repr, /* tp_str; __str__ */
53 0, /* tp_getattro */
54 0, /* tp_setattro */
55 0, /* tp_as_buffer */
56 Py_TPFLAGS_DEFAULT, /* tp_flags */
57 "", /* tp_doc */
58 0, /* tp_traverse */
59 0, /* tp_clear */
60 0, /* tp_richcompare */
61 0, /* tp_weaklistoffset */
62 0, /* tp_iter */
63 0, /* tp_iternext */
64 0, /* tp_methods */
65 0, /* tp_members */
66 0, /* tp_getset */
67 0, /* tp_base */
68 0, /* tp_dict */
69 0, /* tp_descr_get */
70 0, /* tp_descr_set */
71 0, /* tp_dictoffset */
72 0, /* tp_init */
73 0, /* tp_alloc */
74 0, /* tp_new */
75 };
76
77 PyHeader *
78 PyHeader_NEW ()
79 {
80 return (PyHeader *)PyObject_NEW (PyHeader, &PyHeaderType);
81 }
82
83 static PyObject *
84 api_header_size (PyObject *self, PyObject *args)
85 {
86 int status;
87 size_t size;
88 PyHeader *py_hdr;
89
90 if (!PyArg_ParseTuple (args, "O!", &PyHeaderType, &py_hdr))
91 return NULL;
92
93 status = mu_header_size (py_hdr->hdr, &size);
94 return status_object (status, PyInt_FromLong (size));
95 }
96
97 static PyObject *
98 api_header_lines (PyObject *self, PyObject *args)
99 {
100 int status;
101 size_t lines;
102 PyHeader *py_hdr;
103
104 if (!PyArg_ParseTuple (args, "O!", &PyHeaderType, &py_hdr))
105 return NULL;
106
107 status = mu_header_lines (py_hdr->hdr, &lines);
108 return status_object (status, PyInt_FromLong (lines));
109 }
110
111 static PyObject *
112 api_header_get_value (PyObject *self, PyObject *args)
113 {
114 int status;
115 char *name;
116 const char *value = NULL;
117 PyHeader *py_hdr;
118
119 if (!PyArg_ParseTuple (args, "O!s", &PyHeaderType, &py_hdr, &name))
120 return NULL;
121
122 status = mu_header_sget_value (py_hdr->hdr, name, &value);
123 return status_object (status, PyString_FromString (value ? value : ""));
124 }
125
126 static PyObject *
127 api_header_set_value (PyObject *self, PyObject *args)
128 {
129 int status, replace = 1;
130 char *name, *value;
131 PyHeader *py_hdr;
132
133 if (!PyArg_ParseTuple (args, "O!ss|i", &PyHeaderType, &py_hdr, &name,
134 &value, &replace))
135 return NULL;
136
137 status = mu_header_set_value (py_hdr->hdr, name, value, replace);
138 return _ro (PyInt_FromLong (status));
139 }
140
141 static PyObject *
142 api_header_get_field_count (PyObject *self, PyObject *args)
143 {
144 int status;
145 size_t count = 0;
146 PyHeader *py_hdr;
147
148 if (!PyArg_ParseTuple (args, "O!", &PyHeaderType, &py_hdr))
149 return NULL;
150
151 status = mu_header_get_field_count (py_hdr->hdr, &count);
152 return status_object (status, PyInt_FromLong (count));
153 }
154
155 static PyObject *
156 api_header_get_field_name (PyObject *self, PyObject *args)
157 {
158 int status;
159 size_t idx;
160 const char *name = NULL;
161 PyHeader *py_hdr;
162
163 if (!PyArg_ParseTuple (args, "O!i", &PyHeaderType, &py_hdr, &idx))
164 return NULL;
165
166 status = mu_header_sget_field_name (py_hdr->hdr, idx, &name);
167 return status_object (status, PyString_FromString (name ? name : ""));
168 }
169
170 static PyObject *
171 api_header_get_field_value (PyObject *self, PyObject *args)
172 {
173 int status;
174 size_t idx;
175 const char *value = NULL;
176 PyHeader *py_hdr;
177
178 if (!PyArg_ParseTuple (args, "O!i", &PyHeaderType, &py_hdr, &idx))
179 return NULL;
180
181 status = mu_header_sget_field_value (py_hdr->hdr, idx, &value);
182 return status_object (status, PyString_FromString (value ? value : ""));
183 }
184
185 static PyMethodDef methods[] = {
186 { "size", (PyCFunction) api_header_size, METH_VARARGS,
187 "Retrieve HEADER size." },
188
189 { "lines", (PyCFunction) api_header_lines, METH_VARARGS,
190 "Retrieve HEADER number of lines." },
191
192 { "get_value", (PyCFunction) api_header_get_value, METH_VARARGS,
193 "Retrieve header field value." },
194
195 { "set_value", (PyCFunction) api_header_set_value, METH_VARARGS,
196 "Set header field value." },
197
198 { "get_field_count", (PyCFunction) api_header_get_field_count, METH_VARARGS,
199 "Retrieve the number of header fields." },
200
201 { "get_field_name", (PyCFunction) api_header_get_field_name, METH_VARARGS,
202 "Retrieve header field name by field index IDX." },
203
204 { "get_field_value", (PyCFunction) api_header_get_field_value, METH_VARARGS,
205 "Retrieve header field value by field index IDX." },
206
207 { NULL, NULL, 0, NULL }
208 };
209
210 void
211 init_header ()
212 {
213 PyObject *m;
214
215 PyHeaderType.tp_new = PyType_GenericNew;
216 if (PyType_Ready (&PyHeaderType) < 0)
217 return;
218
219 if ((m = attach_module (PY_MODULE, methods)))
220 {
221 Py_INCREF (&PyHeaderType);
222 PyModule_AddObject (m, PY_CSNAME, (PyObject *)&PyHeaderType);
223 }
224 }
1 /*
2 GNU Mailutils -- a suite of utilities for electronic mail
3 Copyright (C) 2009 Free Software Foundation, Inc.
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 3 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General
16 Public License along with this library; if not, write to the
17 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301 USA
19 */
20
21 #ifndef _MUCAPI_LIST_H
22 #define _MUCAPI_LIST_H
23
24 #include <mailutils/list.h>
25
26 typedef int (*mulist_extractor_fp) (void *data, PyObject **dst);
27
28 extern PyObject * mulist_to_pylist (mu_list_t list, mulist_extractor_fp fnc);
29
30 #endif /* not _MUCAPI_LIST_H */
1 /*
2 GNU Mailutils -- a suite of utilities for electronic mail
3 Copyright (C) 2009 Free Software Foundation, Inc.
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 3 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General
16 Public License along with this library; if not, write to the
17 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301 USA
19 */
20
21 #include "c_api.h"
22 #include "list-private.h"
23
24 PyObject *
25 mulist_to_pylist (mu_list_t list, mulist_extractor_fp extractor)
26 {
27 int status, i;
28 size_t list_count;
29 PyObject *py_list;
30
31 if (!list)
32 return NULL;
33
34 status = mu_list_count (list, &list_count);
35 if (status)
36 return NULL;
37
38 py_list = PyList_New (list_count);
39 if (!py_list)
40 return NULL;
41
42 for (i = 0; i < list_count; i++)
43 {
44 void *item;
45 PyObject *py_item = NULL;
46
47 status = mu_list_get (list, i, &item);
48 if (!status)
49 {
50 status = (*extractor)(item, &py_item);
51 if (!status && py_item)
52 PyList_SetItem (py_list, i, py_item);
53 }
54 }
55 return py_list;
56 }
1 /*
2 GNU Mailutils -- a suite of utilities for electronic mail
3 Copyright (C) 2009 Free Software Foundation, Inc.
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 3 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General
16 Public License along with this library; if not, write to the
17 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301 USA
19 */
20
21 #ifndef _MUCAPI_MAILBOX_H
22 #define _MUCAPI_MAILBOX_H
23
24 #include <mailutils/mailbox.h>
25
26 typedef struct {
27 PyObject_HEAD;
28 mu_mailbox_t mbox;
29 } PyMailbox;
30
31 #endif /* not _MUCAPI_MAILBOX_H */
1 /*
2 GNU Mailutils -- a suite of utilities for electronic mail
3 Copyright (C) 2009 Free Software Foundation, Inc.
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 3 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General
16 Public License along with this library; if not, write to the
17 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301 USA
19 */
20
21 #include "c_api.h"
22 #include "mailbox-private.h"
23 #include "message-private.h"
24 #include "folder-private.h"
25 #include "url-private.h"
26 #include "debug-private.h"
27
28 #define PY_MODULE "mailbox"
29 #define PY_CSNAME "MailboxType"
30
31 static PyObject *
32 _repr (PyObject *self)
33 {
34 char buf[80];
35 sprintf (buf, "<" PY_MODULE "." PY_CSNAME " instance at %p>", self);
36 return PyString_FromString (buf);
37 }
38
39 static PyTypeObject PyMailboxType = {
40 PyObject_HEAD_INIT(NULL)
41 0, /* ob_size */
42 PY_MODULE "." PY_CSNAME, /* tp_name */
43 sizeof (PyMailbox), /* tp_basicsize */
44 0, /* tp_itemsize */
45 (destructor)py_dealloc, /* tp_dealloc */
46 0, /* tp_print */
47 0, /* tp_getattr; __getattr__ */
48 0, /* tp_setattr; __setattr__ */
49 0, /* tp_compare; __cmp__ */
50 _repr, /* tp_repr; __repr__ */
51 0, /* tp_as_number */
52 0, /* tp_as_sequence */
53 0, /* tp_as_mapping */
54 0, /* tp_hash; __hash__ */
55 0, /* tp_call; __call__ */
56 _repr, /* tp_str; __str__ */
57 0, /* tp_getattro */
58 0, /* tp_setattro */
59 0, /* tp_as_buffer */
60 Py_TPFLAGS_DEFAULT, /* tp_flags */
61 "", /* tp_doc */
62 0, /* tp_traverse */
63 0, /* tp_clear */
64 0, /* tp_richcompare */
65 0, /* tp_weaklistoffset */
66 0, /* tp_iter */
67 0, /* tp_iternext */
68 0, /* tp_methods */
69 0, /* tp_members */
70 0, /* tp_getset */
71 0, /* tp_base */
72 0, /* tp_dict */
73 0, /* tp_descr_get */
74 0, /* tp_descr_set */
75 0, /* tp_dictoffset */
76 0, /* tp_init */
77 0, /* tp_alloc */
78 0, /* tp_new */
79 };
80
81 static PyObject *
82 api_mailbox_create (PyObject *self, PyObject *args)
83 {
84 int status;
85 char *name;
86 PyMailbox *py_mbox;
87
88 if (!PyArg_ParseTuple (args, "O!s", &PyMailboxType, &py_mbox, &name))
89 return NULL;
90
91 status = mu_mailbox_create (&py_mbox->mbox, name);
92 return _ro (PyInt_FromLong (status));
93 }
94
95 static PyObject *
96 api_mailbox_create_default (PyObject *self, PyObject *args)
97 {
98 int status;
99 char *name;
100 PyMailbox *py_mbox;
101
102 if (!PyArg_ParseTuple (args, "O!s", &PyMailboxType, &py_mbox, &name))
103 return NULL;
104
105 status = mu_mailbox_create_default (&py_mbox->mbox, name);
106 return _ro (PyInt_FromLong (status));
107 }
108
109 static PyObject *
110 api_mailbox_destroy (PyObject *self, PyObject *args)
111 {
112 PyMailbox *py_mbox;
113
114 if (!PyArg_ParseTuple (args, "O!", &PyMailboxType, &py_mbox))
115 return NULL;
116
117 mu_mailbox_destroy (&py_mbox->mbox);
118 return _ro (Py_None);
119 }
120
121 static PyObject *
122 api_mailbox_open (PyObject *self, PyObject *args)
123 {
124 int status;
125 int flag;
126 PyMailbox *py_mbox;
127
128 if (!PyArg_ParseTuple (args, "O!i", &PyMailboxType, &py_mbox, &flag))
129 return NULL;
130
131 status = mu_mailbox_open (py_mbox->mbox, flag);
132 return _ro (PyInt_FromLong (status));
133 }
134
135 static PyObject *
136 api_mailbox_close (PyObject *self, PyObject *args)
137 {
138 int status;
139 PyMailbox *py_mbox;
140
141 if (!PyArg_ParseTuple (args, "O!", &PyMailboxType, &py_mbox))
142 return NULL;
143
144 status = mu_mailbox_close (py_mbox->mbox);
145 return _ro (PyInt_FromLong (status));
146 }
147
148 static PyObject *
149 api_mailbox_flush (PyObject *self, PyObject *args)
150 {
151 int status, expunge = 0;
152 PyMailbox *py_mbox;
153
154 if (!PyArg_ParseTuple (args, "O!i", &PyMailboxType, &py_mbox, &expunge))
155 return NULL;
156
157 status = mu_mailbox_flush (py_mbox->mbox, expunge);
158 return _ro (PyInt_FromLong (status));
159 }
160
161 static PyObject *
162 api_mailbox_messages_count (PyObject *self, PyObject *args)
163 {
164 int status;
165 size_t total = 0;
166 PyMailbox *py_mbox;
167
168 if (!PyArg_ParseTuple (args, "O!", &PyMailboxType, &py_mbox))
169 return NULL;
170
171 status = mu_mailbox_messages_count (py_mbox->mbox, &total);
172 return status_object (status, PyInt_FromLong (total));
173 }
174
175 static PyObject *
176 api_mailbox_messages_recent (PyObject *self, PyObject *args)
177 {
178 int status;
179 size_t recent = 0;
180 PyMailbox *py_mbox;
181
182 if (!PyArg_ParseTuple (args, "O!", &PyMailboxType, &py_mbox))
183 return NULL;
184
185 status = mu_mailbox_messages_recent (py_mbox->mbox, &recent);
186 return status_object (status, PyInt_FromLong (recent));
187 }
188
189 static PyObject *
190 api_mailbox_message_unseen (PyObject *self, PyObject *args)
191 {
192 int status;
193 size_t unseen = 0;
194 PyMailbox *py_mbox;
195
196 if (!PyArg_ParseTuple (args, "O!", &PyMailboxType, &py_mbox))
197 return NULL;
198
199 status = mu_mailbox_message_unseen (py_mbox->mbox, &unseen);
200 return status_object (status, PyInt_FromLong (unseen));
201 }
202
203 static PyObject *
204 api_mailbox_get_message (PyObject *self, PyObject *args)
205 {
206 int status;
207 size_t msgno;
208 PyMailbox *py_mbox;
209 PyMessage *py_msg = PyMessage_NEW ();
210
211 if (!PyArg_ParseTuple (args, "O!i", &PyMailboxType, &py_mbox, &msgno))
212 return NULL;
213
214 status = mu_mailbox_get_message (py_mbox->mbox, msgno, &py_msg->msg);
215
216 Py_INCREF (py_msg);
217 return status_object (status, (PyObject *)py_msg);
218 }
219
220 static PyObject *
221 api_mailbox_append_message (PyObject *self, PyObject *args)
222 {
223 int status;
224 PyMailbox *py_mbox;
225 PyMessage *py_msg;
226
227 if (!PyArg_ParseTuple (args, "O!O", &PyMailboxType, &py_mbox, &py_msg))
228 return NULL;
229
230 if (!PyMessage_Check ((PyObject *)py_msg))
231 {
232 PyErr_SetString (PyExc_TypeError, "");
233 return NULL;
234 }
235
236 status = mu_mailbox_append_message (py_mbox->mbox, py_msg->msg);
237 return status_object (status, PyInt_FromLong (status));
238 }
239
240 static PyObject *
241 api_mailbox_expunge (PyObject *self, PyObject *args)
242 {
243 int status;
244 PyMailbox *py_mbox;
245
246 if (!PyArg_ParseTuple (args, "O!", &PyMailboxType, &py_mbox))
247 return NULL;
248
249 status = mu_mailbox_expunge (py_mbox->mbox);
250 return _ro (PyInt_FromLong (status));
251 }
252
253 static PyObject *
254 api_mailbox_sync (PyObject *self, PyObject *args)
255 {
256 int status;
257 PyMailbox *py_mbox;
258
259 if (!PyArg_ParseTuple (args, "O!", &PyMailboxType, &py_mbox))
260 return NULL;
261
262 status = mu_mailbox_sync (py_mbox->mbox);
263 return _ro (PyInt_FromLong (status));
264 }
265
266 static PyObject *
267 api_mailbox_lock (PyObject *self, PyObject *args)
268 {
269 int status;
270 PyMailbox *py_mbox;
271
272 if (!PyArg_ParseTuple (args, "O!", &PyMailboxType, &py_mbox))
273 return NULL;
274
275 status = mu_mailbox_lock (py_mbox->mbox);
276 return _ro (PyInt_FromLong (status));
277 }
278
279 static PyObject *
280 api_mailbox_unlock (PyObject *self, PyObject *args)
281 {
282 int status;
283 PyMailbox *py_mbox;
284
285 if (!PyArg_ParseTuple (args, "O!", &PyMailboxType, &py_mbox))
286 return NULL;
287
288 status = mu_mailbox_unlock (py_mbox->mbox);
289 return _ro (PyInt_FromLong (status));
290 }
291
292 static PyObject *
293 api_mailbox_get_size (PyObject *self, PyObject *args)
294 {
295 int status;
296 mu_off_t size = 0;
297 PyMailbox *py_mbox;
298
299 if (!PyArg_ParseTuple (args, "O!", &PyMailboxType, &py_mbox))
300 return NULL;
301
302 status = mu_mailbox_get_size (py_mbox->mbox, &size);
303 return status_object (status, PyInt_FromLong (size));
304 }
305
306 static PyObject *
307 api_mailbox_get_debug (PyObject *self, PyObject *args)
308 {
309 int status;
310 PyMailbox *py_mbox;
311 PyDebug *py_dbg = PyDebug_NEW ();
312
313 if (!PyArg_ParseTuple (args, "O!", &PyMailboxType, &py_mbox))
314 return NULL;
315
316 status = mu_mailbox_get_debug (py_mbox->mbox, &py_dbg->dbg);
317
318 Py_INCREF (py_dbg);
319 return status_object (status, (PyObject *)py_dbg);
320 }
321
322 static PyObject *
323 api_mailbox_get_folder (PyObject *self, PyObject *args)
324 {
325 int status;
326 PyMailbox *py_mbox;
327 PyFolder *py_folder = PyFolder_NEW ();
328
329 if (!PyArg_ParseTuple (args, "O!", &PyMailboxType, &py_mbox))
330 return NULL;
331
332 py_folder->folder = NULL;
333 status = mu_mailbox_get_folder (py_mbox->mbox, &py_folder->folder);
334
335 Py_INCREF (py_folder);
336 return status_object (status, (PyObject *)py_folder);
337 }
338
339 static PyObject *
340 api_mailbox_get_url (PyObject *self, PyObject *args)
341 {
342 int status;
343 PyMailbox *py_mbox;
344 PyUrl *py_url = PyUrl_NEW ();
345
346 if (!PyArg_ParseTuple (args, "O!", &PyMailboxType, &py_mbox))
347 return NULL;
348
349 Py_INCREF (py_url);
350
351 status = mu_mailbox_get_url (py_mbox->mbox, &py_url->url);
352 return status_object (status, (PyObject *)py_url);
353 }
354
355 static PyMethodDef methods[] = {
356 { "create", (PyCFunction) api_mailbox_create, METH_VARARGS,
357 "Allocate and initialize MBOX. The concrete mailbox type "
358 "instantiate is based on the scheme of the url NAME." },
359
360 { "create_default", (PyCFunction) api_mailbox_create_default, METH_VARARGS,
361 "Create a mailbox with mu_mailbox_create() based on the "
362 "environment variable MAIL or the string formed by "
363 "__PATH_MAILDIR_/USER or LOGNAME if USER is null." },
364
365 { "destroy", (PyCFunction) api_mailbox_destroy, METH_VARARGS,
366 "Destroy and release resources held by MBOX." },
367
368 { "open", (PyCFunction) api_mailbox_open, METH_VARARGS,
369 "A connection is open, if no stream was provided, a stream is "
370 "created based on the MBOX type. The FLAG can be OR'ed." },
371
372 { "close", (PyCFunction) api_mailbox_close, METH_VARARGS,
373 "The stream attached to MBOX is closed." },
374
375 { "flush", (PyCFunction) api_mailbox_flush, METH_VARARGS,
376 "" },
377
378 { "messages_count", (PyCFunction) api_mailbox_messages_count, METH_VARARGS,
379 "Give the number of messages in MBOX." },
380
381 { "messages_recent", (PyCFunction) api_mailbox_messages_recent, METH_VARARGS,
382 "Give the number of recent messages in MBOX." },
383
384 { "message_unseen", (PyCFunction) api_mailbox_message_unseen, METH_VARARGS,
385 "Give the number of first unseen message in MBOX." },
386
387 { "get_message", (PyCFunction) api_mailbox_get_message, METH_VARARGS,
388 "Retrieve message number MSGNO, MESSAGE is allocated and initialized." },
389
390 { "append_message", (PyCFunction) api_mailbox_append_message, METH_VARARGS,
391 "Append MESSAGE to the mailbox MBOX." },
392
393 { "expunge", (PyCFunction) api_mailbox_expunge, METH_VARARGS,
394 "Expunge deleted messages from the mailbox MBOX." },
395
396 { "sync", (PyCFunction) api_mailbox_sync, METH_VARARGS,
397 "" },
398
399 { "lock", (PyCFunction) api_mailbox_lock, METH_VARARGS,
400 "" },
401
402 { "unlock", (PyCFunction) api_mailbox_unlock, METH_VARARGS,
403 "" },
404
405 { "get_size", (PyCFunction) api_mailbox_get_size, METH_VARARGS,
406 "" },
407
408 { "get_debug", (PyCFunction) api_mailbox_get_debug, METH_VARARGS,
409 "" },
410
411 { "get_folder", (PyCFunction) api_mailbox_get_folder, METH_VARARGS,
412 "" },
413
414 { "get_url", (PyCFunction) api_mailbox_get_url, METH_VARARGS,
415 "" },
416
417 { NULL, NULL, 0, NULL }
418 };
419
420 void
421 init_mailbox ()
422 {
423 PyObject *m;
424
425 PyMailboxType.tp_new = PyType_GenericNew;
426 if (PyType_Ready (&PyMailboxType) < 0)
427 return;
428
429 if ((m = attach_module (PY_MODULE, methods)))
430 {
431 Py_INCREF (&PyMailboxType);
432 PyModule_AddObject (m, PY_CSNAME, (PyObject *)&PyMailboxType);
433 }
434 }
1 /*
2 GNU Mailutils -- a suite of utilities for electronic mail
3 Copyright (C) 2009 Free Software Foundation, Inc.
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 3 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General
16 Public License along with this library; if not, write to the
17 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301 USA
19 */
20
21 #ifndef _MUCAPI_MAILCAP_H
22 #define _MUCAPI_MAILCAP_H
23
24 #include <mailutils/mailcap.h>
25
26 typedef struct {
27 PyObject_HEAD;
28 mu_mailcap_t mc;
29 } PyMailcap;
30
31 typedef struct {
32 PyObject_HEAD;
33 mu_mailcap_entry_t entry;
34 } PyMailcapEntry;
35
36 extern PyMailcap * PyMailcap_NEW ();
37 extern PyMailcapEntry * PyMailcapEntry_NEW ();
38
39 #endif /* not _MUCAPI_MAILCAP_H */
1 /*
2 GNU Mailutils -- a suite of utilities for electronic mail
3 Copyright (C) 2009 Free Software Foundation, Inc.
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 3 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General
16 Public License along with this library; if not, write to the
17 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301 USA
19 */
20
21 #include "c_api.h"
22 #include "mailcap-private.h"
23 #include "stream-private.h"
24
25 #define PY_MODULE "mailcap"
26 #define PY_CSNAME1 "MailcapType"
27 #define PY_CSNAME2 "MailcapEntryType"
28
29 static PyObject *
30 _repr1 (PyObject *self)
31 {
32 char buf[80];
33 sprintf (buf, "<" PY_MODULE "." PY_CSNAME1 " instance at %p>", self);
34 return PyString_FromString (buf);
35 }
36
37 static PyTypeObject PyMailcapType = {
38 PyObject_HEAD_INIT(NULL)
39 0, /* ob_size */
40 PY_MODULE "." PY_CSNAME1, /* tp_name */
41 sizeof (PyMailcap), /* tp_basicsize */
42 0, /* tp_itemsize */
43 (destructor)py_dealloc, /* tp_dealloc */
44 0, /* tp_print */
45 0, /* tp_getattr; __getattr__ */
46 0, /* tp_setattr; __setattr__ */
47 0, /* tp_compare; __cmp__ */
48 _repr1, /* tp_repr; __repr__ */
49 0, /* tp_as_number */
50 0, /* tp_as_sequence */
51 0, /* tp_as_mapping */
52 0, /* tp_hash; __hash__ */
53 0, /* tp_call; __call__ */
54 _repr1, /* tp_str; __str__ */
55 0, /* tp_getattro */
56 0, /* tp_setattro */
57 0, /* tp_as_buffer */
58 Py_TPFLAGS_DEFAULT, /* tp_flags */
59 "", /* tp_doc */
60 0, /* tp_traverse */
61 0, /* tp_clear */
62 0, /* tp_richcompare */
63 0, /* tp_weaklistoffset */
64 0, /* tp_iter */
65 0, /* tp_iternext */
66 0, /* tp_methods */
67 0, /* tp_members */
68 0, /* tp_getset */
69 0, /* tp_base */
70 0, /* tp_dict */
71 0, /* tp_descr_get */
72 0, /* tp_descr_set */
73 0, /* tp_dictoffset */
74 0, /* tp_init */
75 0, /* tp_alloc */
76 0, /* tp_new */
77 };
78
79 PyMailcap *
80 PyMailcap_NEW ()
81 {
82 return (PyMailcap *)PyObject_NEW (PyMailcap, &PyMailcapType);
83 }
84
85 static PyObject *
86 _repr2 (PyObject *self)
87 {
88 char buf[80];
89 sprintf (buf, "<" PY_MODULE "." PY_CSNAME2 " instance at %p>", self);
90 return PyString_FromString (buf);
91 }
92
93 static PyTypeObject PyMailcapEntryType = {
94 PyObject_HEAD_INIT(NULL)
95 0, /* ob_size */
96 PY_MODULE "." PY_CSNAME2, /* tp_name */
97 sizeof (PyMailcapEntry), /* tp_basicsize */
98 0, /* tp_itemsize */
99 (destructor)py_dealloc, /* tp_dealloc */
100 0, /* tp_print */
101 0, /* tp_getattr; __getattr__ */
102 0, /* tp_setattr; __setattr__ */
103 0, /* tp_compare; __cmp__ */
104 _repr2, /* tp_repr; __repr__ */
105 0, /* tp_as_number */
106 0, /* tp_as_sequence */
107 0, /* tp_as_mapping */
108 0, /* tp_hash; __hash__ */
109 0, /* tp_call; __call__ */
110 _repr2, /* tp_str; __str__ */
111 0, /* tp_getattro */
112 0, /* tp_setattro */
113 0, /* tp_as_buffer */
114 Py_TPFLAGS_DEFAULT, /* tp_flags */
115 "", /* tp_doc */
116 0, /* tp_traverse */
117 0, /* tp_clear */
118 0, /* tp_richcompare */
119 0, /* tp_weaklistoffset */
120 0, /* tp_iter */
121 0, /* tp_iternext */
122 0, /* tp_methods */
123 0, /* tp_members */
124 0, /* tp_getset */
125 0, /* tp_base */
126 0, /* tp_dict */
127 0, /* tp_descr_get */
128 0, /* tp_descr_set */
129 0, /* tp_dictoffset */
130 0, /* tp_init */
131 0, /* tp_alloc */
132 0, /* tp_new */
133 };
134
135 PyMailcapEntry *
136 PyMailcapEntry_NEW ()
137 {
138 return (PyMailcapEntry *)PyObject_NEW (PyMailcapEntry,
139 &PyMailcapEntryType);
140 }
141
142
143 static PyObject *
144 api_mailcap_create (PyObject *self, PyObject *args)
145 {
146 int status;
147 PyMailcap *py_mc;
148 PyStream *py_stm;
149
150 if (!PyArg_ParseTuple (args, "O!O", &PyMailcapType, &py_mc, &py_stm))
151 return NULL;
152
153 if (!PyStream_Check ((PyObject *)py_stm))
154 {
155 PyErr_SetString (PyExc_TypeError, py_stm->ob_type->tp_name);
156 return NULL;
157 }
158
159 status = mu_mailcap_create (&py_mc->mc, py_stm->stm);
160 return _ro (PyInt_FromLong (status));
161 }
162
163 static PyObject *
164 api_mailcap_destroy (PyObject *self, PyObject *args)
165 {
166 PyMailcap *py_mc;
167
168 if (!PyArg_ParseTuple (args, "O!", &PyMailcapType, &py_mc))
169 return NULL;
170
171 mu_mailcap_destroy (&py_mc->mc);
172 return _ro (Py_None);
173 }
174
175 static PyObject *
176 api_mailcap_entries_count (PyObject *self, PyObject *args)
177 {
178 int status;
179 size_t count = 0;
180 PyMailcap *py_mc;
181
182 if (!PyArg_ParseTuple (args, "O!", &PyMailcapType, &py_mc))
183 return NULL;
184
185 status = mu_mailcap_entries_count (py_mc->mc, &count);
186 return status_object (status, PyInt_FromLong (count));
187 }
188
189 static PyObject *
190 api_mailcap_get_entry (PyObject *self, PyObject *args)
191 {
192 int status, i;
193 PyMailcap *py_mc;
194 PyMailcapEntry *py_entry = PyMailcapEntry_NEW ();
195
196 if (!PyArg_ParseTuple (args, "O!i", &PyMailcapType, &py_mc, &i))
197 return NULL;
198
199 status = mu_mailcap_get_entry (py_mc->mc, i, &py_entry->entry);
200
201 Py_INCREF (py_entry);
202 return status_object (status, (PyObject *)py_entry);
203 }
204
205 static PyObject *
206 api_mailcap_entry_fields_count (PyObject *self, PyObject *args)
207 {
208 int status;
209 size_t count;
210 PyMailcapEntry *py_entry;
211
212 if (!PyArg_ParseTuple (args, "O!", &PyMailcapEntryType, &py_entry))
213 return NULL;
214
215 status = mu_mailcap_entry_fields_count (py_entry->entry, &count);
216 return status_object (status, PyInt_FromLong (count));
217 }
218
219 static PyObject *
220 api_mailcap_entry_get_field (PyObject *self, PyObject *args)
221 {
222 int status, i;
223 char buf[256];
224 PyMailcapEntry *py_entry;
225
226 if (!PyArg_ParseTuple (args, "O!i", &PyMailcapEntryType, &py_entry,
227 &i))
228 return NULL;
229
230 status = mu_mailcap_entry_get_field (py_entry->entry, i, buf,
231 sizeof (buf), NULL);
232 return status_object (status, PyString_FromString (buf));
233 }
234
235 static PyObject *
236 api_mailcap_entry_get_typefield (PyObject *self, PyObject *args)
237 {
238 int status;
239 char buf[256];
240 PyMailcapEntry *py_entry;
241
242 if (!PyArg_ParseTuple (args, "O!", &PyMailcapEntryType, &py_entry))
243 return NULL;
244
245 status = mu_mailcap_entry_get_typefield (py_entry->entry, buf,
246 sizeof (buf), NULL);
247 return status_object (status, PyString_FromString (buf));
248 }
249
250 static PyObject *
251 api_mailcap_entry_get_viewcommand (PyObject *self, PyObject *args)
252 {
253 int status;
254 char buf[256];
255 PyMailcapEntry *py_entry;
256
257 if (!PyArg_ParseTuple (args, "O!", &PyMailcapEntryType, &py_entry))
258 return NULL;
259
260 status = mu_mailcap_entry_get_viewcommand (py_entry->entry, buf,
261 sizeof (buf), NULL);
262 return status_object (status, PyString_FromString (buf));
263 }
264
265 static PyMethodDef methods[] = {
266 { "create", (PyCFunction) api_mailcap_create, METH_VARARGS,
267 "Allocate, parse the buffer from the STREAM and initializes MAILCAP." },
268
269 { "destroy", (PyCFunction) api_mailcap_destroy, METH_VARARGS,
270 "Release any resources from the mailcap object." },
271
272 { "entries_count", (PyCFunction) api_mailcap_entries_count, METH_VARARGS,
273 "Return the number of entries found in the mailcap." },
274
275 { "get_entry", (PyCFunction) api_mailcap_get_entry, METH_VARARGS,
276 "Return in ENTRY the mailcap entry of NO." },
277
278 { "entry_fields_count", (PyCFunction) api_mailcap_entry_fields_count,
279 METH_VARARGS,
280 "Return the number of fields found in the entry." },
281
282 { "entry_get_field", (PyCFunction) api_mailcap_entry_get_field,
283 METH_VARARGS,
284 "" },
285
286 { "entry_get_typefield", (PyCFunction) api_mailcap_entry_get_typefield,
287 METH_VARARGS,
288 "" },
289
290 { "entry_get_viewcommand",
291 (PyCFunction) api_mailcap_entry_get_viewcommand, METH_VARARGS,
292 "" },
293
294 { NULL, NULL, 0, NULL }
295 };
296
297 void
298 init_mailcap ()
299 {
300 PyObject *m;
301
302 PyMailcapType.tp_new = PyType_GenericNew;
303 PyMailcapEntryType.tp_new = PyType_GenericNew;
304 if (PyType_Ready (&PyMailcapType) < 0 ||
305 PyType_Ready (&PyMailcapEntryType) < 0)
306 return;
307
308 if ((m = attach_module (PY_MODULE, methods)))
309 {
310 Py_INCREF (&PyMailcapType);
311 Py_INCREF (&PyMailcapEntryType);
312 PyModule_AddObject (m, PY_CSNAME1, (PyObject *)&PyMailcapType);
313 PyModule_AddObject (m, PY_CSNAME2, (PyObject *)&PyMailcapEntryType);
314 }
315 }
1 /*
2 GNU Mailutils -- a suite of utilities for electronic mail
3 Copyright (C) 2009 Free Software Foundation, Inc.
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 3 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General
16 Public License along with this library; if not, write to the
17 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301 USA
19 */
20
21 #ifndef _MUCAPI_MAILER_H
22 #define _MUCAPI_MAILER_H
23
24 #include <mailutils/mailer.h>
25
26 typedef struct {
27 PyObject_HEAD;
28 mu_mailer_t mlr;
29 } PyMailer;
30
31 extern PyMailer * PyMailer_NEW ();
32
33 #endif /* not _MUCAPI_MAILER_H */
1 /*
2 GNU Mailutils -- a suite of utilities for electronic mail
3 Copyright (C) 2009 Free Software Foundation, Inc.
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 3 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General
16 Public License along with this library; if not, write to the
17 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301 USA
19 */
20
21 #include "c_api.h"
22 #include "mailer-private.h"
23 #include "address-private.h"
24 #include "message-private.h"
25 #include "debug-private.h"
26
27 #define PY_MODULE "mailer"
28 #define PY_CSNAME "MailerType"
29
30 static PyObject *
31 _repr (PyObject *self)
32 {
33 char buf[80];
34 sprintf (buf, "<" PY_MODULE "." PY_CSNAME " instance at %p>", self);
35 return PyString_FromString (buf);
36 }
37
38 static PyTypeObject PyMailerType = {
39 PyObject_HEAD_INIT(NULL)
40 0, /* ob_size */
41 PY_MODULE "." PY_CSNAME, /* tp_name */
42 sizeof (PyMailer), /* tp_basicsize */
43 0, /* tp_itemsize */
44 (destructor)py_dealloc, /* tp_dealloc */
45 0, /* tp_print */
46 0, /* tp_getattr; __getattr__ */
47 0, /* tp_setattr; __setattr__ */
48 0, /* tp_compare; __cmp__ */
49 _repr, /* tp_repr; __repr__ */
50 0, /* tp_as_number */
51 0, /* tp_as_sequence */
52 0, /* tp_as_mapping */
53 0, /* tp_hash; __hash__ */
54 0, /* tp_call; __call__ */
55 _repr, /* tp_str; __str__ */
56 0, /* tp_getattro */
57 0, /* tp_setattro */
58 0, /* tp_as_buffer */
59 Py_TPFLAGS_DEFAULT, /* tp_flags */
60 "", /* tp_doc */
61 0, /* tp_traverse */
62 0, /* tp_clear */
63 0, /* tp_richcompare */
64 0, /* tp_weaklistoffset */
65 0, /* tp_iter */
66 0, /* tp_iternext */
67 0, /* tp_methods */
68 0, /* tp_members */
69 0, /* tp_getset */
70 0, /* tp_base */
71 0, /* tp_dict */
72 0, /* tp_descr_get */
73 0, /* tp_descr_set */
74 0, /* tp_dictoffset */
75 0, /* tp_init */
76 0, /* tp_alloc */
77 0, /* tp_new */
78 };
79
80 PyMailer *
81 PyMailer_NEW ()
82 {
83 return (PyMailer *)PyObject_NEW (PyMailer, &PyMailerType);
84 }
85
86 static PyObject *
87 api_mailer_create (PyObject *self, PyObject *args)
88 {
89 int status;
90 char *url;
91 PyMailer *py_mlr;
92
93 if (!PyArg_ParseTuple (args, "O!s", &PyMailerType, &py_mlr, &url))
94 return NULL;
95
96 status = mu_mailer_create (&py_mlr->mlr, url);
97 return _ro (PyInt_FromLong (status));
98 }
99
100 static PyObject *
101 api_mailer_destroy (PyObject *self, PyObject *args)
102 {
103 PyMailer *py_mlr;
104
105 if (!PyArg_ParseTuple (args, "O!", &PyMailerType, &py_mlr))
106 return NULL;
107
108 mu_mailer_destroy (&py_mlr->mlr);
109 return _ro (Py_None);
110 }
111
112 static PyObject *
113 api_mailer_open (PyObject *self, PyObject *args)
114 {
115 int status, flags;
116 PyMailer *py_mlr;
117
118 if (!PyArg_ParseTuple (args, "O!i", &PyMailerType, &py_mlr, &flags))
119 return NULL;
120
121 status = mu_mailer_open (py_mlr->mlr, flags);
122 return _ro (PyInt_FromLong (status));
123 }
124
125 static PyObject *
126 api_mailer_close (PyObject *self, PyObject *args)
127 {
128 int status;
129 PyMailer *py_mlr;
130
131 if (!PyArg_ParseTuple (args, "O!", &PyMailerType, &py_mlr))
132 return NULL;
133
134 status = mu_mailer_close (py_mlr->mlr);
135 return _ro (PyInt_FromLong (status));
136 }
137
138 static PyObject *
139 api_mailer_send_message (PyObject *self, PyObject *args)
140 {
141 int status;
142 PyMailer *py_mlr;
143 PyMessage *py_msg;
144 PyAddress *py_from, *py_to;
145 mu_address_t c_from = NULL, c_to = NULL;
146
147 if (!PyArg_ParseTuple (args, "O!OOO", &PyMailerType, &py_mlr,
148 &py_msg, &py_from, &py_to))
149 return NULL;
150
151 if (!PyMessage_Check ((PyObject *)py_msg))
152 {
153 PyErr_SetString (PyExc_TypeError, "");
154 return NULL;
155 }
156 if (!PyAddress_Check ((PyObject *)py_from) &&
157 (PyObject *)py_from != Py_None)
158 {
159 PyErr_SetString (PyExc_TypeError, "");
160 return NULL;
161 }
162 if (!PyAddress_Check ((PyObject *)py_to) &&
163 (PyObject *)py_to != Py_None)
164 {
165 PyErr_SetString (PyExc_TypeError, "");
166 return NULL;
167 }
168 if ((PyObject *)py_from != Py_None)
169 c_from = py_from->addr;
170 if ((PyObject *)py_to != Py_None)
171 c_to = py_to->addr;
172
173 status = mu_mailer_send_message (py_mlr->mlr, py_msg->msg,
174 c_from, c_to);
175 return _ro (PyInt_FromLong (status));
176 }
177
178 static PyObject *
179 api_mailer_get_debug (PyObject *self, PyObject *args)
180 {
181 int status;
182 PyMailer *py_mlr;
183 PyDebug *py_dbg = PyDebug_NEW ();
184
185 if (!PyArg_ParseTuple (args, "O!", &PyMailerType, &py_mlr))
186 return NULL;
187
188 status = mu_mailer_get_debug (py_mlr->mlr, &py_dbg->dbg);
189
190 Py_INCREF (py_dbg);
191 return status_object (status, (PyObject *)py_dbg);
192 }
193
194 static PyMethodDef methods[] = {
195 { "create", (PyCFunction) api_mailer_create, METH_VARARGS,
196 "Create mailer." },
197
198 { "destroy", (PyCFunction) api_mailer_destroy, METH_VARARGS,
199 "The resources allocate for MSG are freed." },
200
201 { "open", (PyCFunction) api_mailer_open, METH_VARARGS,
202 "" },
203
204 { "close", (PyCFunction) api_mailer_close, METH_VARARGS,
205 "" },
206
207 { "send_message", (PyCFunction) api_mailer_send_message, METH_VARARGS,
208 "" },
209
210 { "get_debug", (PyCFunction) api_mailer_get_debug, METH_VARARGS,
211 "" },
212
213 { NULL, NULL, 0, NULL }
214 };
215
216 void
217 init_mailer ()
218 {
219 PyObject *m;
220
221 PyMailerType.tp_new = PyType_GenericNew;
222 if (PyType_Ready (&PyMailerType) < 0)
223 return;
224
225 if ((m = attach_module (PY_MODULE, methods)))
226 {
227 Py_INCREF (&PyMailerType);
228 PyModule_AddObject (m, PY_CSNAME, (PyObject *)&PyMailerType);
229 }
230 }
1 /*
2 GNU Mailutils -- a suite of utilities for electronic mail
3 Copyright (C) 2009 Free Software Foundation, Inc.
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 3 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General
16 Public License along with this library; if not, write to the
17 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301 USA
19 */
20
21 #ifndef _MUCAPI_MESSAGE_H
22 #define _MUCAPI_MESSAGE_H
23
24 #include <mailutils/message.h>
25
26 typedef struct {
27 PyObject_HEAD;
28 mu_message_t msg;
29 } PyMessage;
30
31 extern PyMessage * PyMessage_NEW ();
32 extern int PyMessage_Check (PyObject *x);
33
34 #endif /* not _MUCAPI_MESSAGE_H */
1 /*
2 GNU Mailutils -- a suite of utilities for electronic mail
3 Copyright (C) 2009 Free Software Foundation, Inc.
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 3 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General
16 Public License along with this library; if not, write to the
17 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301 USA
19 */
20
21 #include "c_api.h"
22 #include "message-private.h"
23 #include "envelope-private.h"
24 #include "header-private.h"
25 #include "body-private.h"
26 #include "attribute-private.h"
27 #include "stream-private.h"
28
29 #define PY_MODULE "message"
30 #define PY_CSNAME "MessageType"
31
32 static PyObject *
33 _repr (PyObject *self)
34 {
35 char buf[80];
36 sprintf (buf, "<" PY_MODULE "." PY_CSNAME " instance at %p>", self);
37 return PyString_FromString (buf);
38 }
39
40 static PyTypeObject PyMessageType = {
41 PyObject_HEAD_INIT(NULL)
42 0, /* ob_size */
43 PY_MODULE "." PY_CSNAME, /* tp_name */
44 sizeof (PyMessage), /* tp_basicsize */
45 0, /* tp_itemsize */
46 (destructor)py_dealloc, /* tp_dealloc */
47 0, /* tp_print */
48 0, /* tp_getattr; __getattr__ */
49 0, /* tp_setattr; __setattr__ */
50 0, /* tp_compare; __cmp__ */
51 _repr, /* tp_repr; __repr__ */
52 0, /* tp_as_number */
53 0, /* tp_as_sequence */
54 0, /* tp_as_mapping */
55 0, /* tp_hash; __hash__ */
56 0, /* tp_call; __call__ */
57 _repr, /* tp_str; __str__ */
58 0, /* tp_getattro */
59 0, /* tp_setattro */
60 0, /* tp_as_buffer */
61 Py_TPFLAGS_DEFAULT, /* tp_flags */
62 "", /* tp_doc */
63 0, /* tp_traverse */
64 0, /* tp_clear */
65 0, /* tp_richcompare */
66 0, /* tp_weaklistoffset */
67 0, /* tp_iter */
68 0, /* tp_iternext */
69 0, /* tp_methods */
70 0, /* tp_members */
71 0, /* tp_getset */
72 0, /* tp_base */
73 0, /* tp_dict */
74 0, /* tp_descr_get */
75 0, /* tp_descr_set */
76 0, /* tp_dictoffset */
77 0, /* tp_init */
78 0, /* tp_alloc */
79 0, /* tp_new */
80 };
81
82 PyMessage *
83 PyMessage_NEW ()
84 {
85 return (PyMessage *)PyObject_NEW (PyMessage, &PyMessageType);
86 }
87
88 int
89 PyMessage_Check (PyObject *x)
90 {
91 return x->ob_type == &PyMessageType;
92 }
93
94 static PyObject *
95 api_message_create (PyObject *self, PyObject *args)
96 {
97 int status;
98 PyMessage *py_msg;
99
100 if (!PyArg_ParseTuple (args, "O!", &PyMessageType, &py_msg))
101 return NULL;
102
103 status = mu_message_create (&py_msg->msg, NULL);
104 return _ro (PyInt_FromLong (status));
105 }
106
107 static PyObject *
108 api_message_destroy (PyObject *self, PyObject *args)
109 {
110 PyMessage *py_msg;
111
112 if (!PyArg_ParseTuple (args, "O!", &PyMessageType, &py_msg))
113 return NULL;
114
115 mu_message_destroy (&py_msg->msg, NULL);
116 return _ro (Py_None);
117 }
118
119 static PyObject *
120 api_message_is_multipart (PyObject *self, PyObject *args)
121 {
122 int status, ismulti;
123 PyMessage *py_msg;
124
125 if (!PyArg_ParseTuple (args, "O!", &PyMessageType, &py_msg))
126 return NULL;
127
128 status = mu_message_is_multipart (py_msg->msg, &ismulti);
129 return status_object (status, PyBool_FromLong (ismulti));
130 }
131
132 static PyObject *
133 api_message_size (PyObject *self, PyObject *args)
134 {
135 int status;
136 size_t size;
137 PyMessage *py_msg;
138
139 if (!PyArg_ParseTuple (args, "O!", &PyMessageType, &py_msg))
140 return NULL;
141
142 status = mu_message_size (py_msg->msg, &size);
143 return status_object (status, PyInt_FromLong (size));
144 }
145
146 static PyObject *
147 api_message_lines (PyObject *self, PyObject *args)
148 {
149 int status;
150 size_t lines;
151 PyMessage *py_msg;
152
153 if (!PyArg_ParseTuple (args, "O!", &PyMessageType, &py_msg))
154 return NULL;
155
156 status = mu_message_lines (py_msg->msg, &lines);
157 return status_object (status, PyInt_FromLong (lines));
158 }
159
160 static PyObject *
161 api_message_get_envelope (PyObject *self, PyObject *args)
162 {
163 int status;
164 PyMessage *py_msg;
165 PyEnvelope *py_env = PyEnvelope_NEW ();
166
167 if (!PyArg_ParseTuple (args, "O!", &PyMessageType, &py_msg))
168 return NULL;
169
170 status = mu_message_get_envelope (py_msg->msg, &py_env->env);
171
172 Py_INCREF (py_env);
173 return status_object (status, (PyObject *)py_env);
174 }
175
176 static PyObject *
177 api_message_get_header (PyObject *self, PyObject *args)
178 {
179 int status;
180 PyMessage *py_msg;
181 PyHeader *py_hdr = PyHeader_NEW ();
182
183 if (!PyArg_ParseTuple (args, "O!", &PyMessageType, &py_msg))
184 return NULL;
185
186 status = mu_message_get_header (py_msg->msg, &py_hdr->hdr);
187
188 Py_INCREF (py_hdr);
189 return status_object (status, (PyObject *)py_hdr);
190 }
191
192 static PyObject *
193 api_message_get_body (PyObject *self, PyObject *args)
194 {
195 int status;
196 PyMessage *py_msg;
197 PyBody *py_body = PyBody_NEW ();
198
199 if (!PyArg_ParseTuple (args, "O!", &PyMessageType, &py_msg))
200 return NULL;
201
202 status = mu_message_get_body (py_msg->msg, &py_body->body);
203
204 Py_INCREF (py_body);
205 return status_object (status, (PyObject *)py_body);
206 }
207
208 static PyObject *
209 api_message_get_attribute (PyObject *self, PyObject *args)
210 {
211 int status;
212 PyMessage *py_msg;
213 PyAttribute *py_attr = PyAttribute_NEW ();
214
215 if (!PyArg_ParseTuple (args, "O!", &PyMessageType, &py_msg))
216 return NULL;
217
218 status = mu_message_get_attribute (py_msg->msg, &py_attr->attr);
219
220 Py_INCREF (py_attr);
221 return status_object (status, (PyObject *)py_attr);
222 }
223
224 static PyObject *
225 api_message_get_num_parts (PyObject *self, PyObject *args)
226 {
227 int status;
228 size_t parts;
229 PyMessage *py_msg;
230
231 if (!PyArg_ParseTuple (args, "O!", &PyMessageType, &py_msg))
232 return NULL;
233
234 status = mu_message_get_num_parts (py_msg->msg, &parts);
235 return status_object (status, PyInt_FromLong (parts));
236 }
237
238 static PyObject *
239 api_message_get_part (PyObject *self, PyObject *args)
240 {
241 int status;
242 size_t npart;
243 PyMessage *py_msg;
244 PyMessage *py_part = PyMessage_NEW ();
245
246 if (!PyArg_ParseTuple (args, "O!i", &PyMessageType, &py_msg, &npart))
247 return NULL;
248
249 status = mu_message_get_part (py_msg->msg, npart, &py_part->msg);
250
251 Py_INCREF (py_part);
252 return status_object (status, (PyObject *)py_part);
253 }
254
255 static PyObject *
256 api_message_get_uid (PyObject *self, PyObject *args)
257 {
258 int status;
259 size_t uid;
260 PyMessage *py_msg;
261
262 if (!PyArg_ParseTuple (args, "O!", &PyMessageType, &py_msg))
263 return NULL;
264
265 status = mu_message_get_uid (py_msg->msg, &uid);
266 return status_object (status, PyInt_FromLong (uid));
267 }
268
269 static PyObject *
270 api_message_get_uidl (PyObject *self, PyObject *args)
271 {
272 int status;
273 char buf[512];
274 size_t writen;
275 PyMessage *py_msg;
276
277 memset (buf, 0, sizeof (buf));
278
279 if (!PyArg_ParseTuple (args, "O!", &PyMessageType, &py_msg))
280 return NULL;
281
282 status = mu_message_get_uidl (py_msg->msg, buf, sizeof (buf), &writen);
283 return status_object (status, PyString_FromString (buf));
284 }
285
286 static PyObject *
287 api_message_get_attachment_name (PyObject *self, PyObject *args)
288 {
289 int status;
290 char *name = NULL;
291 PyMessage *py_msg;
292
293 if (!PyArg_ParseTuple (args, "O!", &PyMessageType, &py_msg))
294 return NULL;
295
296 status = mu_message_aget_attachment_name (py_msg->msg, &name);
297 return status_object (status, PyString_FromString (name ? name : ""));
298 }
299
300 static PyObject *
301 api_message_save_attachment (PyObject *self, PyObject *args)
302 {
303 int status;
304 char *filename = NULL;
305 PyMessage *py_msg;
306
307 if (!PyArg_ParseTuple (args, "O!|s", &PyMessageType, &py_msg,
308 &filename))
309 return NULL;
310
311 if (!strlen (filename))
312 filename = NULL;
313
314 status = mu_message_save_attachment (py_msg->msg, filename, NULL);
315 return _ro (PyInt_FromLong (status));
316 }
317
318 static PyObject *
319 api_message_unencapsulate (PyObject *self, PyObject *args)
320 {
321 int status;
322 char *filename = NULL;
323 PyMessage *py_msg;
324 PyMessage *py_unen = PyMessage_NEW ();
325
326 if (!PyArg_ParseTuple (args, "O!|s", &PyMessageType, &py_msg,
327 &filename))
328 return NULL;
329
330 Py_INCREF (py_unen);
331
332 status = mu_message_unencapsulate (py_msg->msg, &py_unen->msg, NULL);
333 return status_object (status, (PyObject *)py_unen);
334 }
335
336 static PyObject *
337 api_message_set_stream (PyObject *self, PyObject *args)
338 {
339 int status;
340 PyMessage *py_msg;
341 PyStream *py_stm;
342
343 if (!PyArg_ParseTuple (args, "O!O", &PyMessageType, &py_msg, &py_stm))
344 return NULL;
345
346 if (!PyStream_Check ((PyObject *)py_stm))
347 {
348 PyErr_SetString (PyExc_TypeError, "");
349 return NULL;
350 }
351
352 status = mu_message_set_stream (py_msg->msg, py_stm->stm, NULL);
353 py_stm->stm = NULL;
354
355 return _ro (PyInt_FromLong (status));
356 }
357
358 static PyMethodDef methods[] = {
359 { "create", (PyCFunction) api_message_create, METH_VARARGS,
360 "Create message." },
361
362 { "destroy", (PyCFunction) api_message_destroy, METH_VARARGS,
363 "The resources allocate for MSG are freed." },
364
365 { "is_multipart", (PyCFunction) api_message_is_multipart, METH_VARARGS,
366 "" },
367
368 { "size", (PyCFunction) api_message_size, METH_VARARGS,
369 "Retrieve MSG size." },
370
371 { "lines", (PyCFunction) api_message_lines, METH_VARARGS,
372 "Retrieve MSG number of lines." },
373
374 { "get_envelope", (PyCFunction) api_message_get_envelope, METH_VARARGS,
375 "Retrieve MSG envelope." },
376
377 { "get_header", (PyCFunction) api_message_get_header, METH_VARARGS,
378 "Retrieve MSG header." },
379
380 { "get_body", (PyCFunction) api_message_get_body, METH_VARARGS,
381 "Retrieve MSG body." },
382
383 { "get_attribute", (PyCFunction) api_message_get_attribute, METH_VARARGS,
384 "Retrieve MSG attribute." },
385
386 { "get_num_parts", (PyCFunction) api_message_get_num_parts, METH_VARARGS,
387 "" },
388
389 { "get_part", (PyCFunction) api_message_get_part, METH_VARARGS,
390 "" },
391
392 { "get_uid", (PyCFunction) api_message_get_uid, METH_VARARGS,
393 "" },
394
395 { "get_uidl", (PyCFunction) api_message_get_uidl, METH_VARARGS,
396 "" },
397
398 { "get_attachment_name", (PyCFunction) api_message_get_attachment_name,
399 METH_VARARGS, "" },
400
401 { "save_attachment", (PyCFunction) api_message_save_attachment,
402 METH_VARARGS, "" },
403
404 { "unencapsulate", (PyCFunction) api_message_unencapsulate,
405 METH_VARARGS, "" },
406
407 { "set_stream", (PyCFunction) api_message_set_stream, METH_VARARGS,
408 "" },
409
410 { NULL, NULL, 0, NULL }
411 };
412
413 void
414 init_message ()
415 {
416 PyObject *m;
417
418 PyMessageType.tp_new = PyType_GenericNew;
419 if (PyType_Ready (&PyMessageType) < 0)
420 return;
421
422 if ((m = attach_module (PY_MODULE, methods)))
423 {
424 Py_INCREF (&PyMessageType);
425 PyModule_AddObject (m, PY_CSNAME, (PyObject *)&PyMessageType);
426 }
427 }
1 /*
2 GNU Mailutils -- a suite of utilities for electronic mail
3 Copyright (C) 2009 Free Software Foundation, Inc.
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 3 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General
16 Public License along with this library; if not, write to the
17 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301 USA
19 */
20
21 #ifndef _MUCAPI_MIME_H
22 #define _MUCAPI_MIME_H
23
24 #include <mailutils/mime.h>
25
26 typedef struct {
27 PyObject_HEAD;
28 mu_mime_t mime;
29 } PyMime;
30
31 extern PyMime * PyMime_NEW ();
32
33 #endif /* not _MUCAPI_MIME_H */
1 /*
2 GNU Mailutils -- a suite of utilities for electronic mail
3 Copyright (C) 2009 Free Software Foundation, Inc.
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 3 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General
16 Public License along with this library; if not, write to the
17 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301 USA
19 */
20
21 #include "c_api.h"
22 #include "mime-private.h"
23 #include "message-private.h"
24
25 #define PY_MODULE "mime"
26 #define PY_CSNAME "MimeType"
27
28 static PyObject *
29 _repr (PyObject *self)
30 {
31 char buf[80];
32 sprintf (buf, "<" PY_MODULE "." PY_CSNAME " instance at %p>", self);
33 return PyString_FromString (buf);
34 }
35
36 static PyTypeObject PyMimeType = {
37 PyObject_HEAD_INIT(NULL)
38 0, /* ob_size */
39 PY_MODULE "." PY_CSNAME, /* tp_name */
40 sizeof (PyMime), /* tp_basicsize */
41 0, /* tp_itemsize */
42 (destructor)py_dealloc, /* tp_dealloc */
43 0, /* tp_print */
44 0, /* tp_getattr; __getattr__ */
45 0, /* tp_setattr; __setattr__ */
46 0, /* tp_compare; __cmp__ */
47 _repr, /* tp_repr; __repr__ */
48 0, /* tp_as_number */
49 0, /* tp_as_sequence */
50 0, /* tp_as_mapping */
51 0, /* tp_hash; __hash__ */
52 0, /* tp_call; __call__ */
53 _repr, /* tp_str; __str__ */
54 0, /* tp_getattro */
55 0, /* tp_setattro */
56 0, /* tp_as_buffer */
57 Py_TPFLAGS_DEFAULT, /* tp_flags */
58 "", /* tp_doc */
59 0, /* tp_traverse */
60 0, /* tp_clear */
61 0, /* tp_richcompare */
62 0, /* tp_weaklistoffset */
63 0, /* tp_iter */
64 0, /* tp_iternext */
65 0, /* tp_methods */
66 0, /* tp_members */
67 0, /* tp_getset */
68 0, /* tp_base */
69 0, /* tp_dict */
70 0, /* tp_descr_get */
71 0, /* tp_descr_set */
72 0, /* tp_dictoffset */
73 0, /* tp_init */
74 0, /* tp_alloc */
75 0, /* tp_new */
76 };
77
78 PyMime *
79 PyMime_NEW ()
80 {
81 return (PyMime *)PyObject_NEW (PyMime, &PyMimeType);
82 }
83
84 static PyObject *
85 api_mime_create (PyObject *self, PyObject *args)
86 {
87 int status, flags;
88 PyMime *py_mime;
89 PyMessage *py_msg;
90
91 if (!PyArg_ParseTuple (args, "O!Oi", &PyMimeType, &py_mime,
92 &py_msg, &flags))
93 return NULL;
94
95 if (!PyMessage_Check ((PyObject *)py_msg))
96 {
97 PyErr_SetString (PyExc_TypeError, "");
98 return NULL;
99 }
100
101 status = mu_mime_create (&py_mime->mime, py_msg->msg, flags);
102 return _ro (PyInt_FromLong (status));
103 }
104
105 static PyObject *
106 api_mime_destroy (PyObject *self, PyObject *args)
107 {
108 PyMime *py_mime;
109
110 if (!PyArg_ParseTuple (args, "O!", &PyMimeType, &py_mime))
111 return NULL;
112
113 mu_mime_destroy (&py_mime->mime);
114 return _ro (Py_None);
115 }
116
117 static PyObject *
118 api_mime_is_multipart (PyObject *self, PyObject *args)
119 {
120 int ismulti;
121 PyMime *py_mime;
122
123 if (!PyArg_ParseTuple (args, "O!", &PyMimeType, &py_mime))
124 return NULL;
125
126 ismulti = mu_mime_is_multipart (py_mime->mime);
127 return _ro (PyBool_FromLong (ismulti));
128 }
129
130 static PyObject *
131 api_mime_get_num_parts (PyObject *self, PyObject *args)
132 {
133 int status;
134 size_t nparts;
135 PyMime *py_mime;
136
137 if (!PyArg_ParseTuple (args, "O!", &PyMimeType, &py_mime))
138 return NULL;
139
140 status = mu_mime_get_num_parts (py_mime->mime, &nparts);
141 return status_object (status, PyInt_FromLong (nparts));
142 }
143
144 static PyObject *
145 api_mime_get_part (PyObject *self, PyObject *args)
146 {
147 int status;
148 size_t npart;
149 PyMime *py_mime;
150 PyMessage *py_part = PyMessage_NEW ();
151
152 if (!PyArg_ParseTuple (args, "O!i", &PyMimeType, &py_mime, &npart))
153 return NULL;
154
155 status = mu_mime_get_part (py_mime->mime, npart, &py_part->msg);
156
157 Py_INCREF (py_part);
158 return status_object (status, (PyObject *)py_part);
159 }
160
161 static PyObject *
162 api_mime_add_part (PyObject *self, PyObject *args)
163 {
164 int status;
165 PyMime *py_mime;
166 PyMessage *py_msg;
167
168 if (!PyArg_ParseTuple (args, "O!O", &PyMimeType, &py_mime, &py_msg))
169 return NULL;
170
171 if (!PyMessage_Check ((PyObject *)py_msg))
172 {
173 PyErr_SetString (PyExc_TypeError, "");
174 return NULL;
175 }
176
177 status = mu_mime_add_part (py_mime->mime, py_msg->msg);
178 return _ro (PyInt_FromLong (status));
179 }
180
181 static PyObject *
182 api_mime_get_message (PyObject *self, PyObject *args)
183 {
184 int status;
185 PyMime *py_mime;
186 PyMessage *py_msg = PyMessage_NEW ();
187
188 if (!PyArg_ParseTuple (args, "O!", &PyMimeType, &py_mime))
189 return NULL;
190
191 status = mu_mime_get_message (py_mime->mime, &py_msg->msg);
192
193 Py_INCREF (py_msg);
194 return status_object (status, (PyObject *)py_msg);
195 }
196
197 static PyObject *
198 api_rfc2047_decode (PyObject *self, PyObject *args)
199 {
200 int status;
201 char *tocode, *text;
202 char *buf = NULL;
203
204 if (!PyArg_ParseTuple (args, "ss", &tocode, &text))
205 return NULL;
206
207 status = mu_rfc2047_decode (tocode, text, &buf);
208 return status_object (status, PyString_FromString (buf ? buf : ""));
209 }
210
211 static PyObject *
212 api_rfc2047_encode (PyObject *self, PyObject *args)
213 {
214 int status;
215 char *charset, *encoding, *text;
216 char *buf = NULL;
217
218 if (!PyArg_ParseTuple (args, "sss", &charset, &encoding, &text))
219 return NULL;
220
221 status = mu_rfc2047_encode (charset, encoding, text, &buf);
222 return status_object (status, PyString_FromString (buf ? buf : ""));
223 }
224
225 static PyMethodDef methods[] = {
226 { "create", (PyCFunction) api_mime_create, METH_VARARGS,
227 "" },
228
229 { "destroy", (PyCFunction) api_mime_destroy, METH_VARARGS,
230 "" },
231
232 { "is_multipart", (PyCFunction) api_mime_is_multipart, METH_VARARGS,
233 "" },
234
235 { "get_num_parts", (PyCFunction) api_mime_get_num_parts, METH_VARARGS,
236 "" },
237
238 { "get_part", (PyCFunction) api_mime_get_part, METH_VARARGS,
239 "" },
240
241 { "add_part", (PyCFunction) api_mime_add_part, METH_VARARGS,
242 "" },
243
244 { "get_message", (PyCFunction) api_mime_get_message, METH_VARARGS,
245 "" },
246
247 { "rfc2047_decode", (PyCFunction) api_rfc2047_decode, METH_VARARGS,
248 "" },
249
250 { "rfc2047_encode", (PyCFunction) api_rfc2047_encode, METH_VARARGS,
251 "" },
252
253 { NULL, NULL, 0, NULL }
254 };
255
256 void
257 init_mime ()
258 {
259 PyObject *m;
260
261 PyMimeType.tp_new = PyType_GenericNew;
262 if (PyType_Ready (&PyMimeType) < 0)
263 return;
264
265 if ((m = attach_module (PY_MODULE, methods)))
266 {
267 Py_INCREF (&PyMimeType);
268 PyModule_AddObject (m, PY_CSNAME, (PyObject *)&PyMimeType);
269 }
270 }
1 /*
2 GNU Mailutils -- a suite of utilities for electronic mail
3 Copyright (C) 2009 Free Software Foundation, Inc.
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 3 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General
16 Public License along with this library; if not, write to the
17 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301 USA
19 */
20
21 #include "c_api.h"
22 #include <mailutils/registrar.h>
23 #include <mailutils/tls.h>
24
25 #define PY_MODULE "registrar"
26
27 struct format_record {
28 char *name;
29 mu_record_t *record;
30 };
31
32 static struct format_record format_table[] = {
33 { "mbox", &mu_mbox_record },
34 { "mh", &mu_mh_record },
35 { "maildir", &mu_maildir_record },
36 { "pop", &mu_pop_record },
37 { "imap", &mu_imap_record },
38 #ifdef WITH_TLS
39 { "pops", &mu_pops_record },
40 { "imaps", &mu_imaps_record },
41 #endif /* WITH_TLS */
42 { "sendmail", &mu_sendmail_record },
43 { "smtp", &mu_smtp_record },
44 { NULL, NULL },
45 };
46
47 static mu_record_t *
48 find_format (const struct format_record *table, const char *name)
49 {
50 for (; table->name; table++)
51 if (strcmp (table->name, name) == 0)
52 break;
53 return table->record;
54 }
55
56 static int
57 register_format (const char *name)
58 {
59 int status = 0;
60
61 if (!name)
62 {
63 struct format_record *table;
64 for (table = format_table; table->name; table++)
65 mu_registrar_record (*table->record);
66 }
67 else
68 {
69 mu_record_t *record = find_format (format_table, name);
70 if (record)
71 status = mu_registrar_record (*record);
72 else
73 status = EINVAL;
74 }
75 return status;
76 }
77
78 static int
79 set_default_format (const char *name)
80 {
81 int status = 0;
82
83 if (name)
84 {
85 mu_record_t *record = find_format (format_table, name);
86 if (record)
87 mu_registrar_set_default_record (*record);
88 else
89 status = EINVAL;
90 }
91 return status;
92 }
93
94 static PyObject *
95 api_registrar_register_format (PyObject *self, PyObject *args)
96 {
97 int status;
98 char *name = NULL;
99
100 if (!PyArg_ParseTuple (args, "|s", &name))
101 return NULL;
102
103 status = register_format (name);
104 return _ro (PyInt_FromLong (status));
105 }
106
107 static PyObject *
108 api_registrar_set_default_format (PyObject *self, PyObject *args)
109 {
110 int status;
111 char *name = NULL;
112
113 if (!PyArg_ParseTuple (args, "s", &name))
114 return NULL;
115
116 status = set_default_format (name);
117 return _ro (PyInt_FromLong (status));
118 }
119
120 static PyMethodDef methods[] = {
121 { "register_format", (PyCFunction) api_registrar_register_format,
122 METH_VARARGS,
123 "Register desired mailutils formats. Any number of arguments "
124 "can be given." },
125
126 { "set_default_format", (PyCFunction) api_registrar_set_default_format,
127 METH_VARARGS, "" },
128
129 { NULL, NULL, 0, NULL }
130 };
131
132 void
133 init_registrar ()
134 {
135 attach_module (PY_MODULE, methods);
136
137 mu_registrar_record (MU_DEFAULT_RECORD);
138 mu_registrar_set_default_record (MU_DEFAULT_RECORD);
139
140 #ifdef WITH_TLS
141 mu_init_tls_libs ();
142 #endif /* WITH_TLS */
143
144 }
1 /*
2 GNU Mailutils -- a suite of utilities for electronic mail
3 Copyright (C) 2009 Free Software Foundation, Inc.
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 3 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General
16 Public License along with this library; if not, write to the
17 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301 USA
19 */
20
21 #ifndef _MUCAPI_STREAM_H
22 #define _MUCAPI_STREAM_H
23
24 #include <mailutils/stream.h>
25
26 typedef struct {
27 PyObject_HEAD;
28 mu_stream_t stm;
29 } PyStream;
30
31 extern PyStream * PyStream_NEW ();
32 extern int PyStream_Check (PyObject *x);
33
34 #endif /* not _MUCAPI_STREAM_H */
1 /*
2 GNU Mailutils -- a suite of utilities for electronic mail
3 Copyright (C) 2009 Free Software Foundation, Inc.
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 3 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General
16 Public License along with this library; if not, write to the
17 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301 USA
19 */
20
21 #include "c_api.h"
22 #include "stream-private.h"
23
24 #define PY_MODULE "stream"
25 #define PY_CSNAME "StreamType"
26
27 static PyObject *
28 _repr (PyObject *self)
29 {
30 char buf[80];
31 sprintf (buf, "<" PY_MODULE "." PY_CSNAME " instance at %p>", self);
32 return PyString_FromString (buf);
33 }
34
35 static PyTypeObject PyStreamType = {
36 PyObject_HEAD_INIT(NULL)
37 0, /* ob_size */
38 PY_MODULE "." PY_CSNAME, /* tp_name */
39 sizeof (PyStream), /* tp_basicsize */
40 0, /* tp_itemsize */
41 (destructor)py_dealloc, /* tp_dealloc */
42 0, /* tp_print */
43 0, /* tp_getattr; __getattr__ */
44 0, /* tp_setattr; __setattr__ */
45 0, /* tp_compare; __cmp__ */
46 _repr, /* tp_repr; __repr__ */
47 0, /* tp_as_number */
48 0, /* tp_as_sequence */
49 0, /* tp_as_mapping */
50 0, /* tp_hash; __hash__ */
51 0, /* tp_call; __call__ */
52 _repr, /* tp_str; __str__ */
53 0, /* tp_getattro */
54 0, /* tp_setattro */
55 0, /* tp_as_buffer */
56 Py_TPFLAGS_DEFAULT, /* tp_flags */
57 "", /* tp_doc */
58 0, /* tp_traverse */
59 0, /* tp_clear */
60 0, /* tp_richcompare */
61 0, /* tp_weaklistoffset */
62 0, /* tp_iter */
63 0, /* tp_iternext */
64 0, /* tp_methods */
65 0, /* tp_members */
66 0, /* tp_getset */
67 0, /* tp_base */
68 0, /* tp_dict */
69 0, /* tp_descr_get */
70 0, /* tp_descr_set */
71 0, /* tp_dictoffset */
72 0, /* tp_init */
73 0, /* tp_alloc */
74 0, /* tp_new */
75 };
76
77 PyStream *
78 PyStream_NEW ()
79 {
80 return (PyStream *)PyObject_NEW (PyStream, &PyStreamType);
81 }
82
83 int
84 PyStream_Check (PyObject *x)
85 {
86 return x->ob_type == &PyStreamType;
87 }
88
89 static PyObject *
90 api_tcp_stream_create (PyObject *self, PyObject *args)
91 {
92 int status, flags, port;
93 char *host;
94 PyStream *py_stm;
95
96 if (!PyArg_ParseTuple (args, "O!sii", &PyStreamType, &py_stm,
97 &host, &port, &flags))
98 return NULL;
99
100 status = mu_tcp_stream_create (&py_stm->stm, host, port, flags);
101 return _ro (PyInt_FromLong (status));
102 }
103
104 static PyObject *
105 api_file_stream_create (PyObject *self, PyObject *args)
106 {
107 int status, flags;
108 char *filename;
109 PyStream *py_stm;
110
111 if (!PyArg_ParseTuple (args, "O!si", &PyStreamType, &py_stm,
112 &filename, &flags))
113 return NULL;
114
115 status = mu_file_stream_create (&py_stm->stm, filename, flags);
116 return _ro (PyInt_FromLong (status));
117 }
118
119 static PyObject *
120 api_stdio_stream_create (PyObject *self, PyObject *args)
121 {
122 int status, flags;
123 char *filename;
124 FILE *fp;
125 PyStream *py_stm;
126 PyFileObject *py_file;
127
128 if (!PyArg_ParseTuple (args, "O!O!i",
129 &PyStreamType, &py_stm,
130 &PyFile_Type, &py_file,
131 &flags))
132 return NULL;
133
134 fp = PyFile_AsFile ((PyObject *)py_file);
135
136 status = mu_stdio_stream_create (&py_stm->stm, fp, flags);
137 return _ro (PyInt_FromLong (status));
138 }
139
140 static PyObject *
141 api_prog_stream_create (PyObject *self, PyObject *args)
142 {
143 int status, flags;
144 char *progname;
145 PyStream *py_stm;
146
147 if (!PyArg_ParseTuple (args, "O!si", &PyStreamType, &py_stm,
148 &progname, &flags))
149 return NULL;
150
151 status = mu_prog_stream_create (&py_stm->stm, progname, flags);
152 return _ro (PyInt_FromLong (status));
153 }
154
155 static PyObject *
156 api_filter_prog_stream_create (PyObject *self, PyObject *args)
157 {
158 int status;
159 char *progname;
160 PyStream *py_stm, *py_input;
161
162 if (!PyArg_ParseTuple (args, "O!sO!",
163 &PyStreamType, &py_stm,
164 &progname,
165 &PyStreamType, &py_input))
166 return NULL;
167
168 status = mu_filter_prog_stream_create (&py_stm->stm, progname,
169 py_input->stm);
170 return _ro (PyInt_FromLong (status));
171 }
172
173 static PyObject *
174 api_stream_destroy (PyObject *self, PyObject *args)
175 {
176 PyStream *py_stm;
177
178 if (!PyArg_ParseTuple (args, "O!", &PyStreamType, &py_stm))
179 return NULL;
180
181 mu_stream_destroy (&py_stm->stm, NULL);
182 return _ro (Py_None);
183 }
184
185 static PyObject *
186 api_stream_open (PyObject *self, PyObject *args)
187 {
188 int status;
189 PyStream *py_stm;
190
191 if (!PyArg_ParseTuple (args, "O!", &PyStreamType, &py_stm))
192 return NULL;
193
194 status = mu_stream_open (py_stm->stm);
195 return _ro (PyInt_FromLong (status));
196 }
197
198 static PyObject *
199 api_stream_close (PyObject *self, PyObject *args)
200 {
201 int status;
202 PyStream *py_stm;
203
204 if (!PyArg_ParseTuple (args, "O!", &PyStreamType, &py_stm))
205 return NULL;
206
207 status = mu_stream_close (py_stm->stm);
208 return _ro (PyInt_FromLong (status));
209 }
210
211 static PyObject *
212 api_stream_flush (PyObject *self, PyObject *args)
213 {
214 int status;
215 PyStream *py_stm;
216
217 if (!PyArg_ParseTuple (args, "O!", &PyStreamType, &py_stm))
218 return NULL;
219
220 status = mu_stream_flush (py_stm->stm);
221 return _ro (PyInt_FromLong (status));
222 }
223
224 static PyObject *
225 api_stream_wait (PyObject *self, PyObject *args)
226 {
227 int status, wflags;
228 PyStream *py_stm;
229
230 if (!PyArg_ParseTuple (args, "O!i", &PyStreamType, &py_stm, &wflags))
231 return NULL;
232
233 status = mu_stream_wait (py_stm->stm, &wflags, NULL);
234 return _ro (PyInt_FromLong (status));
235 }
236
237 static PyObject *
238 api_stream_read (PyObject *self, PyObject *args)
239 {
240 int status;
241 size_t offset;
242 size_t read_count;
243 char rbuf[1024];
244 PyObject *py_ret;
245 PyStream *py_stm;
246
247 memset (rbuf, 0, sizeof (rbuf));
248
249 if (!PyArg_ParseTuple (args, "O!i", &PyStreamType, &py_stm, &offset))
250 return NULL;
251
252 status = mu_stream_read (py_stm->stm, rbuf, sizeof (rbuf), offset,
253 &read_count);
254
255 py_ret = PyTuple_New (3);
256 PyTuple_SetItem (py_ret, 0, PyInt_FromLong (status));
257 PyTuple_SetItem (py_ret, 1, PyString_FromString (rbuf));
258 PyTuple_SetItem (py_ret, 2, PyInt_FromLong (read_count));
259 return _ro (py_ret);
260 }
261
262 static PyObject *
263 api_stream_write (PyObject *self, PyObject *args)
264 {
265 int status;
266 size_t offset;
267 size_t write_count;
268 char *wbuf;
269 PyStream *py_stm;
270
271 if (!PyArg_ParseTuple (args, "O!si", &PyStreamType, &py_stm,
272 &wbuf, &offset))
273 return NULL;
274
275 status = mu_stream_write (py_stm->stm, wbuf, strlen (wbuf), offset,
276 &write_count);
277 return status_object (status, PyInt_FromLong (write_count));
278 }
279
280 static PyObject *
281 api_stream_readline (PyObject *self, PyObject *args)
282 {
283 int status;
284 size_t offset;
285 size_t read_count;
286 char rbuf[1024];
287 PyObject *py_ret;
288 PyStream *py_stm;
289
290 memset (rbuf, 0, sizeof (rbuf));
291
292 if (!PyArg_ParseTuple (args, "O!i", &PyStreamType, &py_stm, &offset))
293 return NULL;
294
295 status = mu_stream_readline (py_stm->stm, rbuf, sizeof (rbuf), offset,
296 &read_count);
297
298 py_ret = PyTuple_New (3);
299 PyTuple_SetItem (py_ret, 0, PyInt_FromLong (status));
300 PyTuple_SetItem (py_ret, 1, PyString_FromString (rbuf));
301 PyTuple_SetItem (py_ret, 2, PyInt_FromLong (read_count));
302 return _ro (py_ret);
303 }
304
305 static PyObject *
306 api_stream_sequential_readline (PyObject *self, PyObject *args)
307 {
308 int status;
309 size_t read_count;
310 char rbuf[1024];
311 PyObject *py_ret;
312 PyStream *py_stm;
313
314 memset (rbuf, 0, sizeof (rbuf));
315
316 if (!PyArg_ParseTuple (args, "O!", &PyStreamType, &py_stm))
317 return NULL;
318
319 status = mu_stream_sequential_readline (py_stm->stm, rbuf, sizeof (rbuf),
320 &read_count);
321
322 py_ret = PyTuple_New (3);
323 PyTuple_SetItem (py_ret, 0, PyInt_FromLong (status));
324 PyTuple_SetItem (py_ret, 1, PyString_FromString (rbuf));
325 PyTuple_SetItem (py_ret, 2, PyInt_FromLong (read_count));
326 return _ro (py_ret);
327 }
328
329 static PyObject *
330 api_stream_sequential_write (PyObject *self, PyObject *args)
331 {
332 int status;
333 char *wbuf;
334 size_t size;
335 PyStream *py_stm;
336
337 if (!PyArg_ParseTuple (args, "O!si", &PyStreamType, &py_stm, &wbuf,
338 &size))
339 return NULL;
340
341 status = mu_stream_sequential_write (py_stm->stm, wbuf, size);
342 return _ro (PyInt_FromLong (status));
343 }
344
345 static PyMethodDef methods[] = {
346 { "tcp_stream_create", (PyCFunction) api_tcp_stream_create, METH_VARARGS,
347 "" },
348
349 { "file_stream_create", (PyCFunction) api_file_stream_create, METH_VARARGS,
350 "" },
351
352 { "stdio_stream_create", (PyCFunction) api_stdio_stream_create, METH_VARARGS,
353 "" },
354
355 { "prog_stream_create", (PyCFunction) api_prog_stream_create, METH_VARARGS,
356 "" },
357
358 { "filter_prog_stream_create",
359 (PyCFunction) api_filter_prog_stream_create, METH_VARARGS,
360 "" },
361
362 { "destroy", (PyCFunction) api_stream_destroy, METH_VARARGS,
363 "" },
364
365 { "open", (PyCFunction) api_stream_open, METH_VARARGS,
366 "" },
367
368 { "close", (PyCFunction) api_stream_close, METH_VARARGS,
369 "" },
370
371 { "flush", (PyCFunction) api_stream_flush, METH_VARARGS,
372 "" },
373
374 { "wait", (PyCFunction) api_stream_wait, METH_VARARGS,
375 "" },
376
377 { "read", (PyCFunction) api_stream_read, METH_VARARGS,
378 "" },
379
380 { "write", (PyCFunction) api_stream_write, METH_VARARGS,
381 "" },
382
383 { "readline", (PyCFunction) api_stream_readline, METH_VARARGS,
384 "" },
385
386 { "sequential_readline", (PyCFunction) api_stream_sequential_readline,
387 METH_VARARGS, "" },
388
389 { "sequential_write", (PyCFunction) api_stream_sequential_write,
390 METH_VARARGS, "" },
391
392 { NULL, NULL, 0, NULL }
393 };
394
395 void
396 init_stream ()
397 {
398 PyObject *m;
399
400 PyStreamType.tp_new = PyType_GenericNew;
401 if (PyType_Ready (&PyStreamType) < 0)
402 return;
403
404 if ((m = attach_module (PY_MODULE, methods)))
405 {
406 Py_INCREF (&PyStreamType);
407 PyModule_AddObject (m, PY_CSNAME, (PyObject *)&PyStreamType);
408 }
409 }
1 /*
2 GNU Mailutils -- a suite of utilities for electronic mail
3 Copyright (C) 2009 Free Software Foundation, Inc.
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 3 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General
16 Public License along with this library; if not, write to the
17 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301 USA
19 */
20
21 #ifndef _MUCAPI_URL_H
22 #define _MUCAPI_URL_H
23
24 #include <mailutils/url.h>
25
26 typedef struct {
27 PyObject_HEAD;
28 mu_url_t url;
29 } PyUrl;
30
31 extern PyUrl * PyUrl_NEW ();
32
33 #endif /* not _MUCAPI_URL_H */
1 /*
2 GNU Mailutils -- a suite of utilities for electronic mail
3 Copyright (C) 2009 Free Software Foundation, Inc.
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 3 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General
16 Public License along with this library; if not, write to the
17 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301 USA
19 */
20
21 #include "c_api.h"
22 #include "url-private.h"
23
24 #define PY_MODULE "url"
25 #define PY_CSNAME "UrlType"
26
27 static PyObject *
28 _repr (PyObject *self)
29 {
30 char buf[80];
31 sprintf (buf, "<" PY_MODULE "." PY_CSNAME " instance at %p>", self);
32 return PyString_FromString (buf);
33 }
34
35 static PyTypeObject PyUrlType = {
36 PyObject_HEAD_INIT(NULL)
37 0, /* ob_size */
38 PY_MODULE "." PY_CSNAME, /* tp_name */
39 sizeof (PyUrl), /* tp_basicsize */
40 0, /* tp_itemsize */
41 (destructor)py_dealloc, /* tp_dealloc */
42 0, /* tp_print */
43 0, /* tp_getattr; __getattr__ */
44 0, /* tp_setattr; __setattr__ */
45 0, /* tp_compare; __cmp__ */
46 _repr, /* tp_repr; __repr__ */
47 0, /* tp_as_number */
48 0, /* tp_as_sequence */
49 0, /* tp_as_mapping */
50 0, /* tp_hash; __hash__ */
51 0, /* tp_call; __call__ */
52 _repr, /* tp_str; __str__ */
53 0, /* tp_getattro */
54 0, /* tp_setattro */
55 0, /* tp_as_buffer */
56 Py_TPFLAGS_DEFAULT, /* tp_flags */
57 "", /* tp_doc */
58 0, /* tp_traverse */
59 0, /* tp_clear */
60 0, /* tp_richcompare */
61 0, /* tp_weaklistoffset */
62 0, /* tp_iter */
63 0, /* tp_iternext */
64 0, /* tp_methods */
65 0, /* tp_members */
66 0, /* tp_getset */
67 0, /* tp_base */
68 0, /* tp_dict */
69 0, /* tp_descr_get */
70 0, /* tp_descr_set */
71 0, /* tp_dictoffset */
72 0, /* tp_init */
73 0, /* tp_alloc */
74 0, /* tp_new */
75 };
76
77 PyUrl *
78 PyUrl_NEW ()
79 {
80 return (PyUrl *)PyObject_NEW (PyUrl, &PyUrlType);
81 }
82
83 static PyObject *
84 api_url_create (PyObject *self, PyObject *args)
85 {
86 int status;
87 char *str;
88 PyUrl *py_url;
89
90 if (!PyArg_ParseTuple (args, "O!s", &PyUrlType, &py_url, &str))
91 return NULL;
92
93 status = mu_url_create (&py_url->url, str);
94 return _ro (PyInt_FromLong (status));
95 }
96
97 static PyObject *
98 api_url_destroy (PyObject *self, PyObject *args)
99 {
100 PyUrl *py_url;
101
102 if (!PyArg_ParseTuple (args, "O!", &PyUrlType, &py_url))
103 return NULL;
104
105 mu_url_destroy (&py_url->url);
106 return _ro (Py_None);
107 }
108
109 static PyObject *
110 api_url_parse (PyObject *self, PyObject *args)
111 {
112 int status;
113 PyUrl *py_url;
114
115 if (!PyArg_ParseTuple (args, "O!", &PyUrlType, &py_url))
116 return NULL;
117
118 status = mu_url_parse (py_url->url);
119 return _ro (PyInt_FromLong (status));
120 }
121
122 static PyObject *
123 api_url_get_port (PyObject *self, PyObject *args)
124 {
125 int status;
126 long port;
127 PyUrl *py_url;
128
129 if (!PyArg_ParseTuple (args, "O!", &PyUrlType, &py_url))
130 return NULL;
131
132 status = mu_url_get_port (py_url->url, &port);
133 return status_object (status, PyInt_FromLong (port));
134 }
135
136 static PyObject *
137 api_url_get_scheme (PyObject *self, PyObject *args)
138 {
139 int status;
140 const char *buf = NULL;
141 PyUrl *py_url;
142
143 if (!PyArg_ParseTuple (args, "O!", &PyUrlType, &py_url))
144 return NULL;
145
146 status = mu_url_sget_scheme (py_url->url, &buf);
147 return status_object (status, PyString_FromString (buf ? buf : ""));
148 }
149
150 static PyObject *
151 api_url_get_user (PyObject *self, PyObject *args)
152 {
153 int status;
154 const char *buf = NULL;
155 PyUrl *py_url;
156
157 if (!PyArg_ParseTuple (args, "O!", &PyUrlType, &py_url))
158 return NULL;
159
160 status = mu_url_sget_user (py_url->url, &buf);
161 return status_object (status, PyString_FromString (buf ? buf : ""));
162 }
163
164 static PyObject *
165 api_url_get_passwd (PyObject *self, PyObject *args)
166 {
167 int status;
168 const char *buf = NULL;
169 PyUrl *py_url;
170
171 if (!PyArg_ParseTuple (args, "O!", &PyUrlType, &py_url))
172 return NULL;
173
174 status = mu_url_sget_passwd (py_url->url, &buf);
175 return status_object (status, PyString_FromString (buf ? buf : ""));
176 }
177
178 static PyObject *
179 api_url_get_auth (PyObject *self, PyObject *args)
180 {
181 int status;
182 const char *buf = NULL;
183 PyUrl *py_url;
184
185 if (!PyArg_ParseTuple (args, "O!", &PyUrlType, &py_url))
186 return NULL;
187
188 status = mu_url_sget_auth (py_url->url, &buf);
189 return status_object (status, PyString_FromString (buf ? buf : ""));
190 }
191
192 static PyObject *
193 api_url_get_host (PyObject *self, PyObject *args)
194 {
195 int status;
196 const char *buf = NULL;
197 PyUrl *py_url;
198
199 if (!PyArg_ParseTuple (args, "O!", &PyUrlType, &py_url))
200 return NULL;
201
202 status = mu_url_sget_host (py_url->url, &buf);
203 return status_object (status, PyString_FromString (buf ? buf : ""));
204 }
205
206 static PyObject *
207 api_url_get_path (PyObject *self, PyObject *args)
208 {
209 int status;
210 const char *buf = NULL;
211 PyUrl *py_url;
212
213 if (!PyArg_ParseTuple (args, "O!", &PyUrlType, &py_url))
214 return NULL;
215
216 status = mu_url_sget_path (py_url->url, &buf);
217 return status_object (status, PyString_FromString (buf ? buf : ""));
218 }
219
220 static PyObject *
221 api_url_get_query (PyObject *self, PyObject *args)
222 {
223 int status, i;
224 size_t argc;
225 char **argv;
226 PyObject *py_list;
227 PyUrl *py_url;
228
229 if (!PyArg_ParseTuple (args, "O!", &PyUrlType, &py_url))
230 return NULL;
231
232 status = mu_url_sget_query (py_url->url, &argc, &argv);
233
234 py_list = PyList_New (0);
235 for (i = 0; i < argc; i++)
236 PyList_Append (py_list, PyString_FromString (argv[i]));
237
238 return status_object (status, py_list);
239 }
240
241 static PyObject *
242 api_url_to_string (PyObject *self, PyObject *args)
243 {
244 int status;
245 const char *str;
246 PyUrl *py_url;
247
248 if (!PyArg_ParseTuple (args, "O!", &PyUrlType, &py_url))
249 return NULL;
250
251 str = mu_url_to_string (py_url->url);
252 return _ro (PyString_FromString (str ? str : ""));
253 }
254
255 static PyMethodDef methods[] = {
256 { "create", (PyCFunction) api_url_create, METH_VARARGS,
257 "Create the url data structure, but do not parse it." },
258
259 { "destroy", (PyCFunction) api_url_destroy, METH_VARARGS,
260 "Destroy the url and free its resources." },
261
262 { "parse", (PyCFunction) api_url_parse, METH_VARARGS,
263 "Parse the url, after calling this the get functions can be called." },
264
265 { "to_string", (PyCFunction) api_url_to_string, METH_VARARGS,
266 "" },
267
268 { "get_port", (PyCFunction) api_url_get_port, METH_VARARGS, "" },
269 { "get_scheme", (PyCFunction) api_url_get_scheme, METH_VARARGS, "" },
270 { "get_user", (PyCFunction) api_url_get_user, METH_VARARGS, "" },
271 { "get_passwd", (PyCFunction) api_url_get_passwd, METH_VARARGS, "" },
272 { "get_auth", (PyCFunction) api_url_get_auth, METH_VARARGS, "" },
273 { "get_host", (PyCFunction) api_url_get_host, METH_VARARGS, "" },
274 { "get_path", (PyCFunction) api_url_get_path, METH_VARARGS, "" },
275 { "get_query", (PyCFunction) api_url_get_query, METH_VARARGS, "" },
276
277 { NULL, NULL, 0, NULL }
278 };
279
280 void
281 init_url ()
282 {
283 PyObject *m;
284
285 PyUrlType.tp_new = PyType_GenericNew;
286 if (PyType_Ready (&PyUrlType) < 0)
287 return;
288
289 if ((m = attach_module (PY_MODULE, methods)))
290 {
291 Py_INCREF (&PyUrlType);
292 PyModule_AddObject (m, PY_CSNAME, (PyObject *)&PyUrlType);
293 }
294 }
1 /*
2 GNU Mailutils -- a suite of utilities for electronic mail
3 Copyright (C) 2009 Free Software Foundation, Inc.
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 3 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General
16 Public License along with this library; if not, write to the
17 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301 USA
19 */
20
21 #include "c_api.h"
22 #include <mailutils/mutil.h>
23
24 #define PY_MODULE "util"
25
26 static PyObject *
27 api_util_get_user_email (PyObject *self, PyObject *args)
28 {
29 int status;
30 char *name = NULL;
31 char *email = NULL;
32
33 if (!PyArg_ParseTuple (args, "|s", &name))
34 return NULL;
35
36 email = mu_get_user_email (name);
37 return _ro (PyString_FromString (email ? email : ""));
38 }
39
40 static PyObject *
41 api_util_set_user_email (PyObject *self, PyObject *args)
42 {
43 int status;
44 char *email;
45
46 if (!PyArg_ParseTuple (args, "s", &email))
47 return NULL;
48
49 status = mu_set_user_email (email);
50 return _ro (PyInt_FromLong (status));
51 }
52
53 static PyObject *
54 api_util_get_user_email_domain (PyObject *self, PyObject *args)
55 {
56 int status;
57 const char *domain = NULL;
58
59 status = mu_get_user_email_domain (&domain);
60 return status_object (status, PyString_FromString (domain ? domain : ""));
61 }
62
63 static PyObject *
64 api_util_set_user_email_domain (PyObject *self, PyObject *args)
65 {
66 int status;
67 char *domain;
68
69 if (!PyArg_ParseTuple (args, "s", &domain))
70 return NULL;
71
72 status = mu_set_user_email_domain (domain);
73 return _ro (PyInt_FromLong (status));
74 }
75
76 static PyObject *
77 api_util_tempname (PyObject *self, PyObject *args)
78 {
79 char *tmpdir = NULL, *tmpname = NULL;
80
81 if (!PyArg_ParseTuple (args, "|z", &tmpdir))
82 return NULL;
83
84 tmpname = mu_tempname (tmpdir);
85 return _ro (PyString_FromString (tmpname ? tmpname : ""));
86 }
87
88 static PyMethodDef methods[] = {
89 { "get_user_email", (PyCFunction) api_util_get_user_email, METH_VARARGS,
90 "Get the default user email address." },
91
92 { "set_user_email", (PyCFunction) api_util_set_user_email, METH_VARARGS,
93 "Set the default user email address." },
94
95 { "get_user_email_domain", (PyCFunction) api_util_get_user_email_domain,
96 METH_VARARGS,
97 "Get the default user email address domain." },
98
99 { "set_user_email_domain", (PyCFunction) api_util_set_user_email_domain,
100 METH_VARARGS,
101 "Set the default user email address domain." },
102
103 { "tempname", (PyCFunction) api_util_tempname,
104 METH_VARARGS, "" },
105
106 { NULL, NULL, 0, NULL }
107 };
108
109 void
110 init_util ()
111 {
112 attach_module (PY_MODULE, methods);
113 }
1 ## Process this file with GNU Automake to create Makefile.in
2
3 ## Copyright (C) 2009 Free Software Foundation, Inc.
4 ##
5 ## GNU Mailutils is free software; you can redistribute it and/or
6 ## modify it under the terms of the GNU General Public License as
7 ## published by the Free Software Foundation; either version 3, or (at
8 ## your option) any later version.
9 ##
10 ## This program is distributed in the hope that it will be useful, but
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 ## General Public License for more details.
14 ##
15 ## You should have received a copy of the GNU General Public License
16 ## along with this program; if not, write to the Free Software
17 ## Foundation, Inc. 51 Franklin Street, Fifth Floor, Boston, MA
18 ## 02110-1301 USA
19
20 pkgpython_PYTHON = \
21 __init__.py \
22 error.py \
23 address.py \
24 attribute.py \
25 auth.py \
26 body.py \
27 debug.py \
28 envelope.py \
29 filter.py \
30 folder.py \
31 header.py \
32 mailer.py \
33 mailbox.py \
34 mailcap.py \
35 message.py \
36 mime.py \
37 registrar.py \
38 stream.py \
39 url.py \
40 util.py
41
1 # GNU Mailutils -- a suite of utilities for electronic mail
2 # Copyright (C) 2009 Free Software Foundation, Inc.
3 #
4 # GNU Mailutils is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 3, or (at your option)
7 # any later version.
8 #
9 # GNU Mailutils is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with GNU Mailutils; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
17 # MA 02110-1301 USA
18
19 __all__ = [
20 "error",
21 "address",
22 "attribute",
23 "auth",
24 "body",
25 "debug",
26 "envelope",
27 "filter",
28 "folder",
29 "header",
30 "mailer",
31 "mailbox",
32 "mailcap",
33 "message",
34 "mime",
35 "registrar",
36 "stream",
37 "url",
38 "util",
39 ]
1 #
2 # GNU Mailutils -- a suite of utilities for electronic mail
3 # Copyright (C) 2009 Free Software Foundation, Inc.
4 #
5 # This library is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU Lesser General Public
7 # License as published by the Free Software Foundation; either
8 # version 3 of the License, or (at your option) any later version.
9 #
10 # This library is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 # Lesser General Public License for more details.
14 #
15 # You should have received a copy of the GNU Lesser General
16 # Public License along with this library; if not, write to the
17 # Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 # Boston, MA 02110-1301 USA
19 #
20
21 import types
22 from mailutils.c_api import address
23 from mailutils.error import AddressError
24
25 class Address:
26 def __init__ (self, addr):
27 self.addr = address.AddressType ()
28 if isinstance (addr, types.ListType):
29 status = address.createv (self.addr, addr)
30 else:
31 status = address.create (self.addr, addr)
32 if status:
33 raise AddressError (status)
34
35 def __del__ (self):
36 address.destroy (self.addr)
37 del self.addr
38
39 def __len__ (self):
40 return self.get_count ()
41
42 def __str__ (self):
43 status, str = address.to_string (self.addr)
44 if status:
45 raise AddressError (status)
46 return str
47
48 def __iter__ (self):
49 self.__count = 0
50 self.__len = self.get_count ()
51 return self
52
53 def next (self):
54 if self.__count >= self.__len:
55 self.__count = 0
56 raise StopIteration
57 else:
58 self.__count += 1
59 return self.get_email (self.__count)
60
61 def is_group (self, n):
62 """Return True if this address is just the name of a group,
63 False otherwise."""
64 status, isgroup = address.is_group (self.addr, n)
65 if status:
66 raise AddressError (status)
67 return isgroup
68
69 def get_count (self):
70 """Return a count of the addresses in the address list."""
71 return address.get_count (self.addr)
72
73 def get_email (self, n):
74 """Return email part of the Nth email address."""
75 status, email = address.get_email (self.addr, n)
76 if status:
77 raise AddressError (status)
78 return email
79
80 def get_local_part (self, n):
81 """Return local part of the Nth email address."""
82 status, local_part = address.get_local_part (self.addr, n)
83 if status:
84 raise AddressError (status)
85 return local_part
86
87 def get_domain (self, n):
88 """Return domain part of the Nth email address."""
89 status, domain = address.get_domain (self.addr, n)
90 if status:
91 raise AddressError (status)
92 return domain
93
94 def get_personal (self, n):
95 """Return personal part of the Nth email address."""
96 status, personal = address.get_personal (self.addr, n)
97 if status:
98 raise AddressError (status)
99 return personal
100
101 def get_comments (self, n):
102 """Return comment part of the Nth email address."""
103 status, comments = address.get_comments (self.addr, n)
104 if status:
105 raise AddressError (status)
106 return comments
107
108 def get_route (self, n):
109 """Return the route part of the Nth email address."""
110 status, route = address.get_route (self.addr, n)
111 if status:
112 raise AddressError (status)
113 return route
1 #
2 # GNU Mailutils -- a suite of utilities for electronic mail
3 # Copyright (C) 2009 Free Software Foundation, Inc.
4 #
5 # This library is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU Lesser General Public
7 # License as published by the Free Software Foundation; either
8 # version 3 of the License, or (at your option) any later version.
9 #
10 # This library is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 # Lesser General Public License for more details.
14 #
15 # You should have received a copy of the GNU Lesser General
16 # Public License along with this library; if not, write to the
17 # Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 # Boston, MA 02110-1301 USA
19 #
20
21 import types
22 from mailutils.c_api import attribute
23 from mailutils.error import *
24
25 MU_ATTRIBUTE_ANSWERED = 0x01
26 MU_ATTRIBUTE_FLAGGED = 0x02
27 MU_ATTRIBUTE_DELETED = 0x04
28 MU_ATTRIBUTE_DRAFT = 0x08
29 MU_ATTRIBUTE_SEEN = 0x10
30 MU_ATTRIBUTE_READ = 0x20
31 MU_ATTRIBUTE_MODIFIED = 0x40
32
33 class Attribute:
34 def __init__ (self, attr):
35 self.attr = attr
36
37 def __del__ (self):
38 del self.attr
39
40 def __str__ (self):
41 return attribute.to_string (self.attr)
42
43 def __getitem__ (self, flag):
44 return self.is_flag (flag)
45
46 def __setitem__ (self, flag, value):
47 if value == True:
48 self.set_flags (flag)
49 elif value == False:
50 self.unset_flags (flag)
51 else:
52 raise TypeError, value
53
54 def is_modified (self):
55 return attribute.is_modified (self.attr)
56
57 def clear_modified (self):
58 attribute.clear_modified (self.attr)
59
60 def set_modified (self):
61 attribute.set_modified (self.attr)
62
63 def get_flags (self):
64 status, flags = attribute.get_flags (self.attr)
65 if status:
66 raise Error (status)
67 return flags
68
69 def set_flags (self, flags):
70 status = attribute.set_flags (self.attr, flags)
71 if status:
72 raise Error (status)
73
74 def unset_flags (self, flags):
75 status = attribute.unset_flags (self.attr, flags)
76 if status:
77 raise Error (status)
78
79 def is_flag (self, flag):
80 flags = self.get_flags ()
81 if flags & flag:
82 return True
83 return False
1 #
2 # GNU Mailutils -- a suite of utilities for electronic mail
3 # Copyright (C) 2009 Free Software Foundation, Inc.
4 #
5 # This library is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU Lesser General Public
7 # License as published by the Free Software Foundation; either
8 # version 3 of the License, or (at your option) any later version.
9 #
10 # This library is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 # Lesser General Public License for more details.
14 #
15 # You should have received a copy of the GNU Lesser General
16 # Public License along with this library; if not, write to the
17 # Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 # Boston, MA 02110-1301 USA
19 #
20
21 import types
22 from mailutils.c_api import auth
23 from mailutils.error import AuthError
24
25 MU_AF_QUOTA = 0x1
26
27 def register_module (name = None):
28 if name == None:
29 status = auth.register_module ()
30 elif isinstance (name, types.TupleType) \
31 or isinstance (name, types.ListType):
32 for n in name:
33 status = auth.register_module (n)
34 else:
35 status = auth.register_module (name)
36 if status:
37 raise AuthError (status)
38
39 def get_auth_by_name (username):
40 return auth.get_auth_by_name (username)
41
42 def get_auth_by_uid (uid):
43 return auth.get_auth_by_uid (uid)
44
45 def authenticate (auth_data, password):
46 status = auth.authenticate (auth_data, password)
47 if status:
48 raise AuthError (status)
49
50
51 class Authority:
52 __owner = False
53
54 def __init__ (self, authority = None):
55 if isinstance (authority, auth.AuthorityType):
56 self.authority = authority
57 else:
58 self.authority = auth.AuthorityType ()
59 self.__owner = True
60 status = auth.authority_create (self.authority)
61 if status:
62 raise AuthError (status)
63
64 def __del__ (self):
65 if self.__owner:
66 auth.authority_destroy (self.authority)
67 del self.authority
68
69 def get_ticket (self):
70 status, ticket = auth.authority_get_ticket (self.authority)
71 if status:
72 raise AuthError (status)
73 return Ticket (ticket)
74
75 def set_ticket (self, ticket):
76 status = auth.authority_set_ticket (self.authority, ticket.ticket)
77 if status:
78 raise AuthError (status)
79
80 def authenticate (self):
81 status = auth.authority_authenticate (self.authority)
82 if status:
83 raise AuthError (status)
84
85 class Ticket:
86 __owner = False
87
88 def __init__ (self, ticket = None):
89 if isinstance (ticket, auth.TicketType):
90 self.ticket = ticket
91 else:
92 self.ticket = auth.TicketType ()
93 self.__owner = True
94 status = auth.ticket_create (self.ticket)
95 if status:
96 raise AuthError (status)
97
98 def __del__ (self):
99 if self.__owner:
100 auth.ticket_destroy (self.ticket)
101 del self.ticket
102
103 class Wicket:
104 __owner = False
105
106 def __init__ (self, wicket = None):
107 if isinstance (wicket, auth.WicketType):
108 self.wicket = wicket
109 else:
110 self.wicket = auth.WicketType ()
111 self.__owner = True
112 status = auth.wicket_create (self.wicket)
113 if status:
114 raise AuthError (status)
115
116 def __del__ (self):
117 if self.__owner:
118 auth.wicket_destroy (self.wicket)
119 del self.wicket
120
121 def __str__ (self):
122 return self.get_filename ()
123
124 def get_filename (self):
125 status, filename = auth.wicket_get_filename (self.wicket)
126 if status:
127 raise AuthError (status)
128 return filename
129
130 def set_filename (self, filename):
131 status = auth.wicket_set_filename (self.wicket, filename)
132 if status:
133 raise AuthError (status)
1 #
2 # GNU Mailutils -- a suite of utilities for electronic mail
3 # Copyright (C) 2009 Free Software Foundation, Inc.
4 #
5 # This library is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU Lesser General Public
7 # License as published by the Free Software Foundation; either
8 # version 3 of the License, or (at your option) any later version.
9 #
10 # This library is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 # Lesser General Public License for more details.
14 #
15 # You should have received a copy of the GNU Lesser General
16 # Public License along with this library; if not, write to the
17 # Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 # Boston, MA 02110-1301 USA
19 #
20
21 from mailutils.c_api import body
22 from mailutils import stream
23 from mailutils.error import BodyError
24
25 class Body:
26 def __init__ (self, bd):
27 self.bd = bd
28
29 def __del__ (self):
30 del self.bd
31
32 def __getattr__ (self, name):
33 if name == 'size':
34 return self.get_size ()
35 elif name == 'lines':
36 return self.get_lines ()
37 else:
38 raise AttributeError, name
39
40 def __len__ (self):
41 return self.get_size ()
42
43 def get_size (self):
44 status, size = body.size (self.bd)
45 if status:
46 raise BodyError (status)
47 return size
48
49 def get_lines (self):
50 status, lines = body.lines (self.bd)
51 if status:
52 raise BodyError (status)
53 return lines
54
55 def get_stream (self):
56 status, stm = body.get_stream (self.bd)
57 if status:
58 raise BodyError (status)
59 return stream.Stream (stm)
1 #
2 # GNU Mailutils -- a suite of utilities for electronic mail
3 # Copyright (C) 2009 Free Software Foundation, Inc.
4 #
5 # This library is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU Lesser General Public
7 # License as published by the Free Software Foundation; either
8 # version 3 of the License, or (at your option) any later version.
9 #
10 # This library is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 # Lesser General Public License for more details.
14 #
15 # You should have received a copy of the GNU Lesser General
16 # Public License along with this library; if not, write to the
17 # Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 # Boston, MA 02110-1301 USA
19 #
20
21 from mailutils.c_api import debug
22 from mailutils.error import DebugError
23
24 MU_DEBUG_ERROR = 0
25 MU_DEBUG_TRACE0 = 1
26 MU_DEBUG_TRACE = MU_DEBUG_TRACE0
27 MU_DEBUG_TRACE1 = 2
28 MU_DEBUG_TRACE2 = 3
29 MU_DEBUG_TRACE3 = 4
30 MU_DEBUG_TRACE4 = 5
31 MU_DEBUG_TRACE5 = 6
32 MU_DEBUG_TRACE6 = 7
33 MU_DEBUG_TRACE7 = 8
34 MU_DEBUG_PROT = 9
35
36 class Debug:
37 def __init__ (self, dbg):
38 self.dbg = dbg
39
40 def __del__ (self):
41 del self.dbg
42
43 def set_level (self, level = MU_DEBUG_PROT):
44 status = debug.set_level (self.dbg, level)
45 if status:
46 raise DebugError (status)
1 #
2 # GNU Mailutils -- a suite of utilities for electronic mail
3 # Copyright (C) 2009 Free Software Foundation, Inc.
4 #
5 # This library is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU Lesser General Public
7 # License as published by the Free Software Foundation; either
8 # version 3 of the License, or (at your option) any later version.
9 #
10 # This library is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 # Lesser General Public License for more details.
14 #
15 # You should have received a copy of the GNU Lesser General
16 # Public License along with this library; if not, write to the
17 # Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 # Boston, MA 02110-1301 USA
19 #
20
21 from mailutils.c_api import envelope
22 from mailutils.error import EnvelopeError
23
24 MU_ENVELOPE_DATE_FORMAT = "%a %b %d %H:%M:%S %Y"
25 MU_ENVELOPE_DATE_LENGTH = 24
26
27 class Envelope:
28 def __init__ (self, env):
29 self.env = env
30
31 def __del__ (self):
32 del self.env
33
34 def get_sender (self):
35 """Get the address that this message was reportedly received from."""
36 status, sender = envelope.get_sender (self.env)
37 if status:
38 raise EnvelopeError (status)
39 return sender
40
41 def get_date (self):
42 """Get the date that the message was delivered to the mailbox, in
43 something close to ANSI ctime() format: Mon Jul 05 13:08:27 1999."""
44 status, date = envelope.get_date (self.env)
45 if status:
46 raise EnvelopeError (status)
47 return date
1 #
2 # GNU Mailutils -- a suite of utilities for electronic mail
3 # Copyright (C) 2009 Free Software Foundation, Inc.
4 #
5 # This library is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU Lesser General Public
7 # License as published by the Free Software Foundation; either
8 # version 3 of the License, or (at your option) any later version.
9 #
10 # This library is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 # Lesser General Public License for more details.
14 #
15 # You should have received a copy of the GNU Lesser General
16 # Public License along with this library; if not, write to the
17 # Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 # Boston, MA 02110-1301 USA
19 #
20
21 from mailutils.c_api import error
22
23 def strerror (status):
24 return error.strerror (status)
25
26 class Error (Exception):
27 def __init__ (self, status):
28 self.status = status
29 self.strerror = strerror (status)
30 def __str__ (self):
31 return "%d: %s" % (self.status, self.strerror)
32
33 class AddressError (Error): pass
34 class AuthError (Error): pass
35 class BodyError (Error): pass
36 class DebugError (Error): pass
37 class EnvelopeError (Error): pass
38 class FolderError (Error): pass
39 class HeaderError (Error): pass
40 class MailerError (Error): pass
41 class MailboxError (Error): pass
42 class MailcapError (Error): pass
43 class MessageError (Error): pass
44 class MimeError (Error): pass
45 class StreamError (Error): pass
46 class UrlError (Error): pass
47
48 MU_ERR_BASE = 0x1000
49
50 MU_ERR_FAILURE = (MU_ERR_BASE+0)
51 MU_ERR_CANCELED = (MU_ERR_BASE+1)
52 MU_ERR_NO_HANDLER = (MU_ERR_BASE+2)
53 MU_ERR_EMPTY_VFN = (MU_ERR_BASE+3)
54 MU_ERR_OUT_NULL = (MU_ERR_BASE+4)
55 MU_ERR_OUT_PTR_NULL = (MU_ERR_BASE+5)
56 MU_ERR_MBX_NULL = (MU_ERR_BASE+6)
57 MU_ERR_BAD_822_FORMAT = (MU_ERR_BASE+7)
58 MU_ERR_EMPTY_ADDRESS = (MU_ERR_BASE+8)
59 MU_ERR_LOCKER_NULL = (MU_ERR_BASE+9)
60 MU_ERR_LOCK_CONFLICT = (MU_ERR_BASE+10)
61 MU_ERR_LOCK_BAD_LOCK = (MU_ERR_BASE+11)
62 MU_ERR_LOCK_BAD_FILE = (MU_ERR_BASE+12)
63 MU_ERR_LOCK_NOT_HELD = (MU_ERR_BASE+13)
64 MU_ERR_LOCK_EXT_FAIL = (MU_ERR_BASE+14)
65 MU_ERR_LOCK_EXT_ERR = (MU_ERR_BASE+15)
66 MU_ERR_LOCK_EXT_KILLED = (MU_ERR_BASE+16)
67 MU_ERR_NO_SUCH_USER = (MU_ERR_BASE+17)
68 MU_ERR_GETHOSTBYNAME = (MU_ERR_BASE+18)
69 MU_ERR_BAD_RESUMPTION = (MU_ERR_BASE+19)
70 MU_ERR_MAILER_BAD_FROM = (MU_ERR_BASE+20)
71 MU_ERR_MAILER_BAD_TO = (MU_ERR_BASE+21)
72 MU_ERR_MAILER_NO_RCPT_TO = (MU_ERR_BASE+22)
73 MU_ERR_MAILER_BAD_URL = (MU_ERR_BASE+23)
74 MU_ERR_SMTP_RCPT_FAILED = (MU_ERR_BASE+24)
75 MU_ERR_TCP_NO_HOST = (MU_ERR_BASE+25)
76 MU_ERR_TCP_NO_PORT = (MU_ERR_BASE+26)
77 MU_ERR_BAD_2047_INPUT = (MU_ERR_BASE+27)
78 MU_ERR_BAD_2047_ENCODING = (MU_ERR_BASE+28)
79 MU_ERR_NOUSERNAME = (MU_ERR_BASE+29)
80 MU_ERR_NOPASSWORD = (MU_ERR_BASE+30)
81 MU_ERR_UNSAFE_PERMS = (MU_ERR_BASE+31)
82 MU_ERR_BAD_AUTH_SCHEME = (MU_ERR_BASE+32)
83 MU_ERR_AUTH_FAILURE = (MU_ERR_BASE+33)
84 MU_ERR_PROCESS_NOEXEC = (MU_ERR_BASE+34)
85 MU_ERR_PROCESS_EXITED = (MU_ERR_BASE+35)
86 MU_ERR_PROCESS_SIGNALED = (MU_ERR_BASE+36)
87 MU_ERR_PROCESS_UNKNOWN_FAILURE = (MU_ERR_BASE+37)
88 MU_ERR_CONN_CLOSED = (MU_ERR_BASE+38)
89 MU_ERR_PARSE = (MU_ERR_BASE+39)
90 MU_ERR_NOENT = (MU_ERR_BASE+40)
91 MU_ERR_EXISTS = (MU_ERR_BASE+41)
92 MU_ERR_BUFSPACE = (MU_ERR_BASE+42)
93 MU_ERR_SQL = (MU_ERR_BASE+43)
94 MU_ERR_DB_ALREADY_CONNECTED = (MU_ERR_BASE+44)
95 MU_ERR_DB_NOT_CONNECTED = (MU_ERR_BASE+45)
96 MU_ERR_RESULT_NOT_RELEASED = (MU_ERR_BASE+46)
97 MU_ERR_NO_QUERY = (MU_ERR_BASE+47)
98 MU_ERR_BAD_COLUMN = (MU_ERR_BASE+48)
99 MU_ERR_NO_RESULT = (MU_ERR_BASE+49)
100 MU_ERR_NO_INTERFACE = (MU_ERR_BASE+50)
101 MU_ERR_BADOP = (MU_ERR_BASE+51)
102 MU_ERR_BAD_FILENAME = (MU_ERR_BASE+52)
103 MU_ERR_READ = (MU_ERR_BASE+53)
1 #
2 # GNU Mailutils -- a suite of utilities for electronic mail
3 # Copyright (C) 2009 Free Software Foundation, Inc.
4 #
5 # This library is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU Lesser General Public
7 # License as published by the Free Software Foundation; either
8 # version 3 of the License, or (at your option) any later version.
9 #
10 # This library is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 # Lesser General Public License for more details.
14 #
15 # You should have received a copy of the GNU Lesser General
16 # Public License along with this library; if not, write to the
17 # Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 # Boston, MA 02110-1301 USA
19 #
20
21 from mailutils.c_api import filter
22 from mailutils.stream import *
23 from mailutils.error import StreamError
24
25 # Type
26 MU_FILTER_DECODE = 0
27 MU_FILTER_ENCODE = 1
28
29 # Direction
30 MU_FILTER_READ = MU_STREAM_READ
31 MU_FILTER_WRITE = MU_STREAM_WRITE
32 MU_FILTER_RDWR = MU_STREAM_RDWR
33
34 class FilterStream (Stream):
35 def __init__ (self, transport, name, type = MU_FILTER_DECODE,
36 direction = MU_FILTER_READ):
37 Stream.__init__ (self)
38 status = filter.create (self.stm, transport.stm, name,
39 type, direction)
40 if status:
41 raise StreamError (status)
42
43 class FilterIconvStream (Stream):
44 def __init__ (self, transport, fromcode, tocode, direction=MU_FILTER_READ):
45 Stream.__init__ (self)
46 status = filter.iconv_create (self.stm, transport.stm,
47 fromcode, tocode, direction)
48 if status:
49 raise StreamError (status)
1 #
2 # GNU Mailutils -- a suite of utilities for electronic mail
3 # Copyright (C) 2009 Free Software Foundation, Inc.
4 #
5 # This library is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU Lesser General Public
7 # License as published by the Free Software Foundation; either
8 # version 3 of the License, or (at your option) any later version.
9 #
10 # This library is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 # Lesser General Public License for more details.
14 #
15 # You should have received a copy of the GNU Lesser General
16 # Public License along with this library; if not, write to the
17 # Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 # Boston, MA 02110-1301 USA
19 #
20
21 from mailutils.c_api import folder
22 from mailutils import stream
23 from mailutils import auth
24 from mailutils import url
25 from mailutils.error import FolderError
26
27 class Folder:
28 __owner = False
29
30 def __init__ (self, f):
31 if isinstance (f, folder.FolderType):
32 self.folder = f
33 else:
34 self.folder = folder.FolderType ()
35 self.__owner = True
36 status = folder.create (self.folder, f)
37 if status:
38 raise FolderError (status)
39
40 def __del__ (self):
41 if self.__owner:
42 folder.destroy (self.folder)
43 del self.folder
44
45 def open (self):
46 status = folder.open (self.folder)
47 if status:
48 raise FolderError (status)
49
50 def close (self):
51 status = folder.close (self.folder)
52 if status:
53 raise FolderError (status)
54
55 def get_stream (self):
56 status, stream = folder.get_stream (self.folder)
57 if status:
58 raise FolderError (status)
59 return stream.Stream (stm)
60
61 def set_stream (self, stream):
62 status = folder.set_stream (self.folder, stream.stm)
63 if status:
64 raise FolderError (status)
65
66 def get_authority (self):
67 status, authority = folder.get_authority (self.folder)
68 if status:
69 raise FolderError (status)
70 return auth.Authority (authority)
71
72 def set_authority (self, authority):
73 status = folder.set_authority (self.folder, authority.authority)
74 if status:
75 raise FolderError (status)
76
77 def get_url (self):
78 status, u = folder.get_url (self.folder)
79 if status:
80 raise FolderError (status)
81 return url.Url (u)
82
83 def list (self, dirname, pattern, max_level = 0):
84 status, lst = folder.list (self.folder, dirname, pattern, max_level)
85 if status:
86 raise FolderError (status)
87 return lst
1 #
2 # GNU Mailutils -- a suite of utilities for electronic mail
3 # Copyright (C) 2009 Free Software Foundation, Inc.
4 #
5 # This library is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU Lesser General Public
7 # License as published by the Free Software Foundation; either
8 # version 3 of the License, or (at your option) any later version.
9 #
10 # This library is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 # Lesser General Public License for more details.
14 #
15 # You should have received a copy of the GNU Lesser General
16 # Public License along with this library; if not, write to the
17 # Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 # Boston, MA 02110-1301 USA
19 #
20
21 import types
22 from mailutils.c_api import header
23 from mailutils.error import *
24
25 class Header:
26 def __init__ (self, hdr):
27 self.hdr = hdr
28
29 def __del__ (self):
30 del self.hdr
31
32 def __getitem__ (self, item):
33 if isinstance (item, types.IntType):
34 return self.get_field_name (item), self.get_field_value (item)
35 else:
36 return self.get_value (item)
37
38 def __setitem__ (self, name, value):
39 self.set_value (name, value)
40
41 def __getattr__ (self, name):
42 if name == 'size':
43 return self.get_size ()
44 elif name == 'lines':
45 return self.get_lines ()
46 else:
47 raise AttributeError, name
48
49 def __len__ (self):
50 return self.get_field_count ()
51
52 def __iter__ (self):
53 self.__count = 0
54 self.__len = self.get_field_count ()
55 return self
56
57 def next (self):
58 if self.__count >= self.__len:
59 self.__count = 0
60 raise StopIteration
61 else:
62 self.__count += 1
63 return self.__getitem__ (self.__count)
64
65 def get_size (self):
66 status, size = header.size (self.hdr)
67 if status:
68 raise HeaderError (status)
69 return size
70
71 def get_lines (self):
72 status, lines = header.lines (self.hdr)
73 if status:
74 raise HeaderError (status)
75 return lines
76
77 def get_value (self, name, default = None):
78 status, value = header.get_value (self.hdr, name)
79 if status == MU_ERR_NOENT:
80 if default != None:
81 return default
82 else:
83 raise KeyError (name)
84 elif status:
85 raise HeaderError (status)
86 return value
87
88 def set_value (self, name, value, replace = True):
89 status = header.set_value (self.hdr, name, value, replace)
90 if status:
91 raise HeaderError (status)
92
93 def get_field_count (self):
94 status, count = header.get_field_count (self.hdr)
95 if status:
96 raise HeaderError (status)
97 return count
98
99 def get_field_name (self, idx):
100 status, name = header.get_field_name (self.hdr, idx)
101 if status == MU_ERR_NOENT:
102 raise IndexError (idx)
103 elif status:
104 raise HeaderError (status)
105 return name
106
107 def get_field_value (self, idx):
108 status, value = header.get_field_value (self.hdr, idx)
109 if status == MU_ERR_NOENT:
110 raise IndexError (idx)
111 elif status:
112 raise HeaderError (status)
113 return value
114
115 MU_HEADER_UNIX_FROM = "From "
116 MU_HEADER_RETURN_PATH = "Return-Path"
117 MU_HEADER_RECEIVED = "Received"
118 MU_HEADER_DATE = "Date"
119 MU_HEADER_DCC = "Dcc"
120 MU_HEADER_FROM = "From"
121 MU_HEADER_SENDER = "Sender"
122 MU_HEADER_RESENT_FROM = "Resent-From"
123 MU_HEADER_SUBJECT = "Subject"
124 MU_HEADER_SENDER = "Sender"
125 MU_HEADER_RESENT_SENDER = "Resent-SENDER"
126 MU_HEADER_TO = "To"
127 MU_HEADER_RESENT_TO = "Resent-To"
128 MU_HEADER_CC = "Cc"
129 MU_HEADER_RESENT_CC = "Resent-Cc"
130 MU_HEADER_BCC = "Bcc"
131 MU_HEADER_RESENT_BCC = "Resent-Bcc"
132 MU_HEADER_REPLY_TO = "Reply-To"
133 MU_HEADER_RESENT_REPLY_TO = "Resent-Reply-To"
134 MU_HEADER_MESSAGE_ID = "Message-ID"
135 MU_HEADER_RESENT_MESSAGE_ID = "Resent-Message-ID"
136 MU_HEADER_IN_REPLY_TO = "In-Reply-To"
137 MU_HEADER_REFERENCE = "Reference"
138 MU_HEADER_REFERENCES = "References"
139 MU_HEADER_ENCRYPTED = "Encrypted"
140 MU_HEADER_PRECEDENCE = "Precedence"
141 MU_HEADER_STATUS = "Status"
142 MU_HEADER_CONTENT_LENGTH = "Content-Length"
143 MU_HEADER_CONTENT_LANGUAGE = "Content-Language"
144 MU_HEADER_CONTENT_TRANSFER_ENCODING = "Content-transfer-encoding"
145 MU_HEADER_CONTENT_ID = "Content-ID"
146 MU_HEADER_CONTENT_TYPE = "Content-Type"
147 MU_HEADER_CONTENT_DESCRIPTION = "Content-Description"
148 MU_HEADER_CONTENT_DISPOSITION = "Content-Disposition"
149 MU_HEADER_CONTENT_MD5 = "Content-MD5"
150 MU_HEADER_MIME_VERSION = "MIME-Version"
151 MU_HEADER_X_MAILER = "X-Mailer"
152 MU_HEADER_X_UIDL = "X-UIDL"
153 MU_HEADER_X_UID = "X-UID"
154 MU_HEADER_X_IMAPBASE = "X-IMAPbase"
155 MU_HEADER_ENV_SENDER = "X-Envelope-Sender"
156 MU_HEADER_ENV_DATE = "X-Envelope-Date"
157 MU_HEADER_FCC = "Fcc"
158 MU_HEADER_DELIVERY_DATE = "Delivery-date"
159 MU_HEADER_ENVELOPE_TO = "Envelope-to"
160 MU_HEADER_X_EXPIRE_TIMESTAMP = "X-Expire-Timestamp"
161
162 MU_HEADER_REPLACE = 0x01
163 MU_HEADER_BEFORE = 0x02
1 #
2 # GNU Mailutils -- a suite of utilities for electronic mail
3 # Copyright (C) 2009 Free Software Foundation, Inc.
4 #
5 # This library is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU Lesser General Public
7 # License as published by the Free Software Foundation; either
8 # version 3 of the License, or (at your option) any later version.
9 #
10 # This library is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 # Lesser General Public License for more details.
14 #
15 # You should have received a copy of the GNU Lesser General
16 # Public License along with this library; if not, write to the
17 # Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 # Boston, MA 02110-1301 USA
19 #
20
21 from mailutils.c_api import mailbox
22 from mailutils import message
23 from mailutils import folder
24 from mailutils import url
25 from mailutils import debug
26 from mailutils.error import MailboxError
27
28 class MailboxBase:
29 def open (self, flags = 0):
30 """Open the connection."""
31 status = mailbox.open (self.mbox, flags)
32 if status:
33 raise MailboxError (status)
34
35 def close (self):
36 """Close the connection."""
37 status = mailbox.close (self.mbox)
38 if status:
39 raise MailboxError (status)
40
41 def flush (self, expunge = False):
42 """Flush the mailbox."""
43 status = mailbox.flush (self.mbox, expunge)
44 if status:
45 raise MailboxError (status)
46
47 def messages_count (self):
48 """Return the number of messages in mailbox."""
49 status, total = mailbox.messages_count (self.mbox)
50 if status:
51 raise MailboxError (status)
52 return total
53
54 def messages_recent (self):
55 """Return the number of recent messages in mailbox."""
56 status, recent = mailbox.messages_recent (self.mbox)
57 if status:
58 raise MailboxError (status)
59 return recent
60
61 def message_unseen (self):
62 """Return the number of first unseen message in mailbox."""
63 status, recent = mailbox.message_unseen (self.mbox)
64 if status:
65 raise MailboxError (status)
66 return unseen
67
68 def get_message (self, msgno):
69 """Retrieve message number MSGNO."""
70 status, c_msg = mailbox.get_message (self.mbox, msgno)
71 if status:
72 raise MailboxError (status)
73 return message.Message (c_msg)
74
75 def append_message (self, msg):
76 """Append MSG to the mailbox."""
77 status = mailbox.append_message (self.mbox, msg.msg)
78 if status:
79 raise MailboxError (status)
80
81 def expunge (self):
82 """Remove all messages marked for deletion."""
83 status = mailbox.expunge (self.mbox)
84 if status:
85 raise MailboxError (status)
86
87 def sync (self):
88 """Synchronize the mailbox."""
89 status = mailbox.sync (self.mbox)
90 if status:
91 raise MailboxError (status)
92
93 def lock (self):
94 """Lock the mailbox."""
95 status = mailbox.lock (self.mbox)
96 if status:
97 raise MailboxError (status)
98
99 def unlock (self):
100 """Unlock the mailbox."""
101 status = mailbox.unlock (self.mbox)
102 if status:
103 raise MailboxError (status)
104
105 def get_size (self):
106 """Return the mailbox size."""
107 status, size = mailbox.get_size (self.mbox)
108 if status:
109 raise MailboxError (status)
110 return size
111
112 def get_folder (self):
113 """Get the FOLDER."""
114 status, fld = mailbox.get_folder (self.mbox)
115 if status:
116 raise MailboxError (status)
117 return folder.Folder (fld)
118
119 def get_debug (self):
120 status, dbg = mailbox.get_debug (self.mbox)
121 if status:
122 raise MailboxError (status)
123 return debug.Debug (dbg)
124
125 def get_url (self):
126 status, u = mailbox.get_url (self.mbox)
127 if status:
128 raise MailboxError (status)
129 return url.Url (u)
130
131 def next (self):
132 if self.__count >= self.__len:
133 self.__count = 0
134 raise StopIteration
135 else:
136 self.__count += 1
137 return self.get_message (self.__count)
138
139 def __getitem__ (self, msgno):
140 return self.get_message (msgno)
141
142 def __iter__ (self):
143 self.__count = 0
144 self.__len = self.messages_count ()
145 return self
146
147 def __getattr__ (self, name):
148 if name == 'size':
149 return self.get_size ()
150 elif name == 'folder':
151 return self.get_folder ()
152 elif name == 'url':
153 return self.get_url ()
154 elif name == 'debug':
155 return self.get_debug ()
156 else:
157 raise AttributeError, name
158
159 def __len__ (self):
160 return self.messages_count ()
161
162
163 class Mailbox (MailboxBase):
164 def __init__ (self, name):
165 self.mbox = mailbox.MailboxType ()
166 status = mailbox.create (self.mbox, name)
167 if status:
168 raise MailboxError (status)
169
170 def __del__ (self):
171 mailbox.destroy (self.mbox)
172 del self.mbox
173
174 class MailboxDefault (MailboxBase):
175 def __init__ (self, name):
176 self.mbox = mailbox.MailboxType ()
177 status = mailbox.create_default (self.mbox, name)
178 if status:
179 raise MailboxError (status)
180
181 def __del__ (self):
182 mailbox.destroy (self.mbox)
183 del self.mbox
1 #
2 # GNU Mailutils -- a suite of utilities for electronic mail
3 # Copyright (C) 2009 Free Software Foundation, Inc.
4 #
5 # This library is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU Lesser General Public
7 # License as published by the Free Software Foundation; either
8 # version 3 of the License, or (at your option) any later version.
9 #
10 # This library is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 # Lesser General Public License for more details.
14 #
15 # You should have received a copy of the GNU Lesser General
16 # Public License along with this library; if not, write to the
17 # Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 # Boston, MA 02110-1301 USA
19 #
20
21 from mailutils.c_api import mailcap
22 from mailutils.error import MailcapError
23
24 class Mailcap:
25 def __init__ (self, stream):
26 self.mc = mailcap.MailcapType ()
27 status = mailcap.create (self.mc, stream.stm)
28 if status:
29 raise MailcapError (status)
30
31 def __del__ (self):
32 mailcap.destroy (self.mc)
33 del self.mc
34
35 def __len__ (self):
36 return self.entries_count ()
37
38 def __getitem__ (self, item):
39 return self.get_entry (item)
40
41 def __iter__ (self):
42 self.__count = 0
43 self.__len = self.entries_count ()
44 return self
45
46 def next (self):
47 if self.__count >= self.__len:
48 self.__count = 0
49 raise StopIteration
50 else:
51 self.__count += 1
52 return self.__getitem__ (self.__count)
53
54 def entries_count (self):
55 """Return the number of entries found in the mailcap."""
56 status, count = mailcap.entries_count (self.mc)
57 if status:
58 raise MailcapError (status)
59 return count
60
61 def get_entry (self, item):
62 """Return in MailcapEntry the mailcap entry of ITEM."""
63 status, entry = mailcap.get_entry (self.mc, item)
64 if status:
65 raise MailcapError (status)
66 return MailcapEntry (entry)
67
68
69 class MailcapEntry:
70 def __init__ (self, entry):
71 self.entry = entry
72
73 def __len__ (self):
74 return self.fields_count ()
75
76 def __getitem__ (self, item):
77 return self.get_field (item)
78
79 def __iter__ (self):
80 self.__count = 0
81 self.__len = self.fields_count ()
82 return self
83
84 def next (self):
85 if self.__count >= self.__len:
86 self.__count = 0
87 raise StopIteration
88 else:
89 self.__count += 1
90 return self.__getitem__ (self.__count)
91
92 def fields_count (self):
93 status, count = mailcap.entry_fields_count (self.entry)
94 if status:
95 raise MailcapEntry (status)
96 return count
97
98 def get_field (self, i):
99 status, field = mailcap.entry_get_field (self.entry, i)
100 if status:
101 raise MailcapEntry (status)
102 return field
103
104 def get_typefield (self):
105 status, typefield = mailcap.entry_get_typefield (self.entry)
106 if status:
107 raise MailcapEntry (status)
108 return typefield
109
110 def get_viewcommand (self):
111 status, viewcommand = mailcap.entry_get_viewcommand (self.entry)
112 if status:
113 raise MailcapEntry (status)
114 return viewcommand
1 #
2 # GNU Mailutils -- a suite of utilities for electronic mail
3 # Copyright (C) 2009 Free Software Foundation, Inc.
4 #
5 # This library is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU Lesser General Public
7 # License as published by the Free Software Foundation; either
8 # version 3 of the License, or (at your option) any later version.
9 #
10 # This library is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 # Lesser General Public License for more details.
14 #
15 # You should have received a copy of the GNU Lesser General
16 # Public License along with this library; if not, write to the
17 # Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 # Boston, MA 02110-1301 USA
19 #
20
21 from mailutils.c_api import mailer
22 from mailutils import address
23 from mailutils import debug
24 from mailutils.error import MailerError
25
26 class Mailer:
27 def __init__ (self, url):
28 self.mlr = mailer.MailerType ()
29 status = mailer.create (self.mlr, url)
30 if status:
31 raise MailerError (status)
32
33 def __del__ (self):
34 mailer.destroy (self.mlr)
35 del self.mlr
36
37 def __getattr__ (self, name):
38 if name == 'debug':
39 return self.get_debug ()
40 else:
41 raise AttributeError, name
42
43 def open (self, flags = 0):
44 status = mailer.open (self.mlr, flags)
45 if status:
46 raise MailerError (status)
47
48 def close (self):
49 status = mailer.close (self.mlr)
50 if status:
51 raise MailerError (status)
52
53 def send_message (self, msg, frm, to):
54 if isinstance (frm, address.Address):
55 frm = frm.addr
56 if isinstance (to, address.Address):
57 to = to.addr
58 status = mailer.send_message (self.mlr, msg.msg, frm, to)
59 if status:
60 raise MailerError (status)
61
62 def get_debug (self):
63 status, dbg = mailer.get_debug (self.mlr)
64 if status:
65 raise MailerError (status)
66 return debug.Debug (dbg)
1 #
2 # GNU Mailutils -- a suite of utilities for electronic mail
3 # Copyright (C) 2009 Free Software Foundation, Inc.
4 #
5 # This library is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU Lesser General Public
7 # License as published by the Free Software Foundation; either
8 # version 3 of the License, or (at your option) any later version.
9 #
10 # This library is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 # Lesser General Public License for more details.
14 #
15 # You should have received a copy of the GNU Lesser General
16 # Public License along with this library; if not, write to the
17 # Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 # Boston, MA 02110-1301 USA
19 #
20
21 from mailutils.c_api import message
22 from mailutils import envelope
23 from mailutils import header
24 from mailutils import body
25 from mailutils import attribute
26 from mailutils.error import MessageError
27
28 class Message:
29 __owner = False
30
31 def __init__ (self, msg = None):
32 if msg == None:
33 self.msg = message.MessageType ()
34 self.__owner = True
35 status = message.create (self.msg)
36 if status:
37 raise MessageError (status)
38 else:
39 self.msg = msg
40
41 def __del__ (self):
42 if self.__owner:
43 message.destroy (self.msg)
44 del self.msg
45
46 def __getattr__ (self, name):
47 if name == 'header':
48 return self.get_header ()
49 elif name == 'body':
50 return self.get_body ()
51 elif name == 'envelope':
52 return self.get_envelope ()
53 elif name == 'attribute':
54 return self.get_attribute ()
55 elif name == 'size':
56 return self.get_size ()
57 elif name == 'lines':
58 return self.get_lines ()
59 else:
60 raise AttributeError, name
61
62 def __len__ (self):
63 return self.get_size ()
64
65 def is_multipart (self):
66 status, ismulti = message.is_multipart (self.msg)
67 if status:
68 raise MessageError (status)
69 return ismulti
70
71 def get_size (self):
72 status, size = message.size (self.msg)
73 if status:
74 raise MessageError (status)
75 return size
76
77 def get_lines (self):
78 status, lines = message.lines (self.msg)
79 if status:
80 raise MessageError (status)
81 return lines
82
83 def get_envelope (self):
84 status, env = message.get_envelope (self.msg)
85 if status:
86 raise MessageError (status)
87 return envelope.Envelope (env)
88
89 def get_header (self):
90 status, hdr = message.get_header (self.msg)
91 if status:
92 raise MessageError (status)
93 return header.Header (hdr)
94
95 def get_body (self):
96 status, bd = message.get_body (self.msg)
97 if status:
98 raise MessageError (status)
99 return body.Body (bd)
100
101 def get_attribute (self):
102 status, attr = message.get_attribute (self.msg)
103 if status:
104 raise MessageError (status)
105 return attribute.Attribute (attr)
106
107 def get_num_parts (self):
108 status, num_parts = message.get_num_parts (self.msg)
109 if status:
110 raise MessageError (status)
111 return num_parts
112
113 def get_part (self, npart):
114 status, part = message.get_part (self.msg, npart)
115 if status:
116 raise MessageError (status)
117 return Message (part)
118
119 def get_uid (self):
120 status, uid = message.get_uid (self.msg)
121 if status:
122 raise MessageError (status)
123 return uid
124
125 def get_uidl (self):
126 status, uidl = message.get_uidl (self.msg)
127 if status:
128 raise MessageError (status)
129 return uidl
130
131 def get_attachment_name (self):
132 status, name = message.get_attachment_name (self.msg)
133 if status:
134 raise MessageError (status)
135 return name
136
137 def save_attachment (self, filename = ''):
138 status = message.save_attachment (self.msg, filename)
139 if status:
140 raise MessageError (status)
141
142 def unencapsulate (self):
143 status, msg = message.unencapsulate (self.msg)
144 if status:
145 raise MessageError (status)
146 return Message (msg)
147
148 def set_stream (self, stream):
149 status = message.set_stream (self.msg, stream.stm)
150 if status:
151 raise MessageError (status)
1 #
2 # GNU Mailutils -- a suite of utilities for electronic mail
3 # Copyright (C) 2009 Free Software Foundation, Inc.
4 #
5 # This library is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU Lesser General Public
7 # License as published by the Free Software Foundation; either
8 # version 3 of the License, or (at your option) any later version.
9 #
10 # This library is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 # Lesser General Public License for more details.
14 #
15 # You should have received a copy of the GNU Lesser General
16 # Public License along with this library; if not, write to the
17 # Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 # Boston, MA 02110-1301 USA
19 #
20
21 from mailutils.c_api import mime
22 from mailutils import message
23 from mailutils.error import MimeError
24
25 MU_MIME_MULTIPART_MIXED = 0x1
26 MU_MIME_MULTIPART_ALT = 0x2
27
28 class Mime:
29 def __init__ (self, msg, flags = 0):
30 self.mime = mime.MimeType ()
31 status = mime.create (self.mime, msg.msg, flags)
32 if status:
33 raise MimeError (status)
34
35 def __del__ (self):
36 mime.destroy (self.mime)
37 del self.mime
38
39 def is_multipart (self):
40 return mime.is_multipart (self.mime)
41
42 def get_num_parts (self):
43 status, nparts = mime.get_num_parts (self.mime)
44 if status:
45 raise MimeError (status)
46 return nparts
47
48 def get_part (self, npart):
49 status, msg = mime.get_part (self.mime, npart)
50 if status:
51 raise MimeError (status)
52 return message.Message (msg)
53
54 def add_part (self, name, msg):
55 status = mime.add_part (self.mime, msg.msg)
56 if status:
57 raise MimeError (status)
58
59 def get_message (self):
60 status, msg = mime.get_message (self.mime)
61 if status:
62 raise MimeError (status)
63 return message.Message (msg)
64
65 def rfc2047_decode (tocode, text):
66 return mime.rfc2047_decode (tocode, text)
67
68 def rfc2047_encode (charset, encoding, text):
69 return mime.rfc2047_encode (charset, encoding, text)
1 #
2 # GNU Mailutils -- a suite of utilities for electronic mail
3 # Copyright (C) 2009 Free Software Foundation, Inc.
4 #
5 # This library is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU Lesser General Public
7 # License as published by the Free Software Foundation; either
8 # version 3 of the License, or (at your option) any later version.
9 #
10 # This library is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 # Lesser General Public License for more details.
14 #
15 # You should have received a copy of the GNU Lesser General
16 # Public License along with this library; if not, write to the
17 # Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 # Boston, MA 02110-1301 USA
19 #
20
21 import types
22 from mailutils.c_api import registrar
23
24 def register_format (name = None):
25 if name == None:
26 registrar.register_format ()
27 elif isinstance (name, types.TupleType) \
28 or isinstance (name, types.ListType):
29 for n in name:
30 registrar.register_format (n)
31 else:
32 registrar.register_format (name)
33
34 def set_default_format (name):
35 registrar.set_default_format (name)
1 #
2 # GNU Mailutils -- a suite of utilities for electronic mail
3 # Copyright (C) 2009 Free Software Foundation, Inc.
4 #
5 # This library is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU Lesser General Public
7 # License as published by the Free Software Foundation; either
8 # version 3 of the License, or (at your option) any later version.
9 #
10 # This library is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 # Lesser General Public License for more details.
14 #
15 # You should have received a copy of the GNU Lesser General
16 # Public License along with this library; if not, write to the
17 # Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 # Boston, MA 02110-1301 USA
19 #
20
21 from mailutils.c_api import stream
22 from mailutils.error import StreamError
23
24 MU_STREAM_READ = 0x00000001
25 MU_STREAM_WRITE = 0x00000002
26 MU_STREAM_RDWR = 0x00000004
27 MU_STREAM_APPEND = 0x00000008
28 MU_STREAM_CREAT = 0x00000010
29 MU_STREAM_NONBLOCK = 0x00000020
30 MU_STREAM_NO_CHECK = 0x00000040
31 MU_STREAM_SEEKABLE = 0x00000080
32 MU_STREAM_NO_CLOSE = 0x00000100
33 MU_STREAM_ALLOW_LINKS = 0x00000200
34 MU_STREAM_NONLOCK = 0x00000400
35 MU_STREAM_QACCESS = 0x00000800
36 MU_STREAM_IRGRP = 0x00001000
37 MU_STREAM_IWGRP = 0x00002000
38 MU_STREAM_IROTH = 0x00004000
39 MU_STREAM_IWOTH = 0x00008000
40 MU_STREAM_IMASK = 0x0000F000
41
42 class Stream:
43 __refcount = 0
44
45 def __init__ (self, stm = None):
46 if isinstance (stm, stream.StreamType):
47 self.stm = stm
48 else:
49 self.stm = stream.StreamType ()
50 self.__reference ()
51 self.read_count = 0
52 self.write_count = 0
53
54 def __del__ (self):
55 if self.__dereference ():
56 stream.destroy (self.stm)
57 del self.stm
58
59 def __reference (self):
60 self.__refcount += 1
61
62 def __dereference (self):
63 self.__refcount -= 1
64 return self.__refcount == 0
65
66 def open (self):
67 status = stream.open (self.stm)
68 if status:
69 raise StreamError (status)
70
71 def close (self):
72 status = stream.close (self.stm)
73 if status:
74 raise StreamError (status)
75
76 def flush (self):
77 status = stream.flush (self.stm)
78 if status:
79 raise StreamError (status)
80
81 def wait (self, wflags):
82 status = stream.wait (self.stm, wflags)
83 if status:
84 raise StreamError (status)
85
86 def read (self, offset = 0):
87 status, rbuf, self.read_count = stream.read (self.stm, offset)
88 if status:
89 raise StreamError (status)
90 return rbuf
91
92 def write (self, wbuf, offset = 0):
93 status, self.write_count = stream.write (self.stm, wbuf, offset)
94 if status:
95 raise StreamError (status)
96
97 def readline (self, offset = 0):
98 status, rbuf, self.read_count = stream.readline (self.stm, offset)
99 if status:
100 raise StreamError (status)
101 return rbuf
102
103 def sequential_readline (self):
104 status, rbuf, self.read_count = stream.readline (self.stm)
105 if status:
106 raise StreamError (status)
107 return rbuf
108
109 def sequential_write (self, wbuf, size = None):
110 if size == None:
111 size = len (wbuf)
112 status = stream.sequential_write (self.stm, wbuf, size)
113 if status:
114 raise StreamError (status)
115
116 class TcpStream (Stream):
117 def __init__ (self, host, port, flags = MU_STREAM_READ):
118 Stream.__init__ (self)
119 status = stream.tcp_stream_create (self.stm, host, port, flags)
120 if status:
121 raise StreamError (status)
122
123 class FileStream (Stream):
124 def __init__ (self, filename, flags = MU_STREAM_READ):
125 Stream.__init__ (self)
126 status = stream.file_stream_create (self.stm, filename, flags)
127 if status:
128 raise StreamError (status)
129
130 class StdioStream (Stream):
131 def __init__ (self, file, flags = MU_STREAM_READ):
132 Stream.__init__ (self)
133 status = stream.stdio_stream_create (self.stm, file, flags)
134 if status:
135 raise StreamError (status)
136
137 class ProgStream (Stream):
138 def __init__ (self, progname, flags = MU_STREAM_READ):
139 Stream.__init__ (self)
140 status = stream.prog_stream_create (self.stm, progname, flags)
141 if status:
142 raise StreamError (status)
1 #
2 # GNU Mailutils -- a suite of utilities for electronic mail
3 # Copyright (C) 2009 Free Software Foundation, Inc.
4 #
5 # This library is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU Lesser General Public
7 # License as published by the Free Software Foundation; either
8 # version 3 of the License, or (at your option) any later version.
9 #
10 # This library is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 # Lesser General Public License for more details.
14 #
15 # You should have received a copy of the GNU Lesser General
16 # Public License along with this library; if not, write to the
17 # Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 # Boston, MA 02110-1301 USA
19 #
20
21 from mailutils.c_api import url
22 from mailutils.error import *
23
24 class Url:
25 __owner = False
26
27 def __init__ (self, u):
28 if isinstance (u, url.UrlType):
29 self.url = u
30 else:
31 self.url = url.UrlType ()
32 self.__owner = True
33 status = url.create (self.url, u)
34 if status:
35 raise UrlError (status)
36
37 def __del__ (self):
38 if self.__owner:
39 url.destroy (self.url)
40 del self.url
41
42 def __str__ (self):
43 return url.to_string (self.url)
44
45 def parse (self):
46 """Parses the url, after calling this the get functions
47 can be called."""
48 if self.__owner:
49 status = url.parse (self.url)
50 if status:
51 raise UrlError (status)
52
53 def get_port (self):
54 status, port = url.get_port (self.url)
55 if status:
56 raise UrlError (status)
57 return port
58
59 def get_scheme (self):
60 status, scheme = url.get_scheme (self.url)
61 if status == MU_ERR_NOENT:
62 return ''
63 elif status:
64 raise UrlError (status)
65 return scheme
66
67 def get_user (self):
68 status, user = url.get_user (self.url)
69 if status == MU_ERR_NOENT:
70 return ''
71 elif status:
72 raise UrlError (status)
73 return user
74
75 def get_passwd (self):
76 status, passwd = url.get_passwd (self.url)
77 if status == MU_ERR_NOENT:
78 return ''
79 elif status:
80 raise UrlError (status)
81 return passwd
82
83 def get_auth (self):
84 status, auth = url.get_auth (self.url)
85 if status == MU_ERR_NOENT:
86 return ''
87 elif status:
88 raise UrlError (status)
89 return auth
90
91 def get_host (self):
92 status, host = url.get_host (self.url)
93 if status == MU_ERR_NOENT:
94 return ''
95 elif status:
96 raise UrlError (status)
97 return host
98
99 def get_path (self):
100 status, path = url.get_path (self.url)
101 if status == MU_ERR_NOENT:
102 return ''
103 elif status:
104 raise UrlError (status)
105 return path
106
107 def get_query (self):
108 status, query = url.get_query (self.url)
109 if status == MU_ERR_NOENT:
110 return ''
111 elif status:
112 raise UrlError (status)
113 return query
1 #
2 # GNU Mailutils -- a suite of utilities for electronic mail
3 # Copyright (C) 2009 Free Software Foundation, Inc.
4 #
5 # This library is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU Lesser General Public
7 # License as published by the Free Software Foundation; either
8 # version 3 of the License, or (at your option) any later version.
9 #
10 # This library is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 # Lesser General Public License for more details.
14 #
15 # You should have received a copy of the GNU Lesser General
16 # Public License along with this library; if not, write to the
17 # Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 # Boston, MA 02110-1301 USA
19 #
20
21 from mailutils.c_api import util
22
23 def get_user_email (name = None):
24 if name == None:
25 return util.get_user_email ()
26 else:
27 return util.get_user_email (name)
28
29 def set_user_email (email):
30 util.set_user_email (email)
31
32 def get_user_email_domain ():
33 status, domain = util.get_user_email_domain ()
34 return domain
35
36 def set_user_email_domain (domain):
37 util.set_user_email_domain (domain)
38
39 def tempname (tmpdir = None):
40 return util.tempname (tmpdir)
...@@ -11,5 +11,6 @@ ltmain.sh ...@@ -11,5 +11,6 @@ ltmain.sh
11 mailutils.spec 11 mailutils.spec
12 mdate-sh 12 mdate-sh
13 missing 13 missing
14 py-compile
14 texinfo.tex 15 texinfo.tex
15 ylwrap 16 ylwrap
......