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>
Sam Roberts <sroberts@uniserve.com>
The parsing code for email addresses.
Wojciech Polak <polak@gnu.org>
TLS, NLS, libmu_cpp, docs, misc hacking.
TLS, NLS, Python interface, libmu_cpp, docs, misc hacking.
......
......@@ -54,7 +54,8 @@ SUBDIRS = \
dotlock\
mh\
movemail\
mimeview
mimeview\
python
EXTRA_DIST = COPYING.LESSER
......
......@@ -158,6 +158,10 @@ mailutils-specific configuration options:
Enable GSSAPI authentication. For this to work, you will have
to have Kerberos V installed on your system.
--without-python
Do not build Python interface library.
--without-guile
Do not build Guile interface library.
......
......@@ -22,6 +22,7 @@ AC_CONFIG_SRCDIR([mailbox/mailbox.c])
AC_CONFIG_AUX_DIR([scripts])
AM_INIT_AUTOMAKE
AC_CONFIG_HEADERS([config.h])
AC_CONFIG_MACRO_DIR([m4])
AC_PREREQ(2.60)
......@@ -1092,6 +1093,35 @@ if test "$EMACS" != "no"; then
fi
AC_SUBST(lisp_LISP)
# Check for Python
AC_ARG_WITH([python],
AC_HELP_STRING([--without-python],
[do not build Python interface]),
[
case "${withval}" in
yes) status_python=yes ;;
no) status_python=no ;;
*) AC_MSG_ERROR(bad value ${withval} for --without-python) ;;
esac],[status_python=yes])
if test "$status_python" = yes; then
AM_PATH_PYTHON(2.5.0,, [status_python=no])
if test "$status_python" = yes; then
AC_ARG_VAR([PYTHON_CONFIG], [The name of python-config binary])
AC_PATH_PROG([PYTHON_CONFIG], python-config)
if test -n "$PYTHON_CONFIG"; then
AC_SUBST(PYTHON_LIBS,`python-config --libs`)
AC_SUBST(PYTHON_INCLUDES,`python-config --includes`)
else
status_python=no
fi
if test "$status_python" = yes; then
AC_SUBST(MU_PYTHON_LTLIBS,'$(MU_PYTHON_LTLIBS)')
fi
fi
fi
# Default mailbox record
# Note: 1. Support for mbox type is always enabled.
# 2. Only local mailbox types are allowed for MU_DEFAULT_SCHEME
......@@ -1162,6 +1192,7 @@ Use GNU TLS.................... $status_gnutls
Use GSASL...................... $status_gsasl
Use GSSAPI..................... $status_gssapi
Use Guile...................... $status_guile
Use Python..................... $status_python
Use TCP wrappers............... $status_tcpwrap
Pthread support................ $status_pthread
Readline support............... $status_readline
......@@ -1198,6 +1229,7 @@ status_gnutls=$WITH_GNUTLS
status_gsasl=$status_gsasl
status_gssapi=$WITH_GSSAPI
status_guile=$useguile
status_python=$status_python
status_tcpwrap=$status_tcpwrap
status_pthread=$usepthread
status_readline=$usereadline
......@@ -1226,6 +1258,7 @@ AC_CONFIG_FILES([Makefile
examples/Makefile
examples/config/Makefile
examples/cpp/Makefile
examples/python/Makefile
examples/scheme/Makefile
frm/Makefile
frm/testsuite/Makefile
......@@ -1271,6 +1304,9 @@ AC_CONFIG_FILES([Makefile
po/Makefile.in
pop3d/Makefile
pop3d/testsuite/Makefile
python/Makefile
python/c_api/Makefile
python/mailutils/Makefile
readmsg/Makefile
readmsg/testsuite/Makefile
scripts/Makefile
......
......@@ -17,7 +17,7 @@
## Foundation, Inc. 51 Franklin Street, Fifth Floor, Boston, MA
## 02110-1301 USA
SUBDIRS = config cpp scheme
SUBDIRS = config cpp python scheme
noinst_PROGRAMS = \
aclck\
......
## Process this file with GNU Automake to create Makefile.in
## Copyright (C) 2009 Free Software Foundation, Inc.
##
## GNU Mailutils is free software; you can redistribute it and/or
## modify it under the terms of the GNU General Public License as
## published by the Free Software Foundation; either version 3, or (at
## your option) any later version.
##
## This program is distributed in the hope that it will be useful, but
## WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
## General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with this program; if not, write to the Free Software
## Foundation, Inc. 51 Franklin Street, Fifth Floor, Boston, MA
## 02110-1301 USA
EXTRA_DIST = \
addr.py\
auth.py\
iconv.py\
lsf.py\
mailcap.py\
mimetest.py\
msg-send.py\
sfrom.py\
url-parse.py
# GNU Mailutils -- a suite of utilities for electronic mail
# Copyright (C) 2009 Free Software Foundation, Inc.
#
# GNU Mailutils is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3, or (at your option)
# any later version.
#
# GNU Mailutils is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with GNU Mailutils; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301 USA
import sys
from mailutils import address
from mailutils import util
from mailutils.error import *
def parse (str):
util.set_user_email_domain ("localhost")
try:
addr = address.Address (str)
count = addr.get_count ()
print "%s => count %d" % (addr, len (addr))
for no in range (1, count + 1):
isgroup = addr.is_group (no)
print "%d " % no,
if isgroup:
print "group <%s>" % addr.get_personal (no)
else:
print "email <%s>" % addr.get_email (no)
if not isgroup:
print " personal <%s>" % addr.get_personal (no)
print " comments <%s>" % addr.get_comments (no)
print " local-part <%s> domain <%s>" % (addr.get_local_part (no),
addr.get_domain (no))
print " route <%s>" % addr.get_route (no)
except AddressError, e:
print e
print
def parseinput ():
try:
while True:
line = sys.stdin.readline ().strip ()
if line == '':
break
parse (line)
except KeyboardInterrupt:
sys.exit ()
if __name__ == '__main__':
if len (sys.argv) == 1:
parseinput ()
sys.exit ()
for arg in sys.argv[1:]:
if arg == '-':
parseinput ()
else:
parse (arg)
# GNU Mailutils -- a suite of utilities for electronic mail
# Copyright (C) 2009 Free Software Foundation, Inc.
#
# GNU Mailutils is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3, or (at your option)
# any later version.
#
# GNU Mailutils is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with GNU Mailutils; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301 USA
import sys
import getopt
import getpass
from mailutils import auth
from mailutils.error import AuthError
if __name__ == '__main__':
key_type = 'name'
try:
opts, args = getopt.getopt (sys.argv[1:], 'p:un',
['password=', 'uid', 'name'])
for o, arg in opts:
if o in ('-p', '--password'):
password = arg
elif o in ('-u', '--uid'):
key_type = 'uid'
elif o in ('-n', '--name'):
key_type = 'name'
except getopt.GetoptError:
print "Usage: %s [OPTION...] key" % sys.argv[0]
print """%s -- test mailutils authentication and authorization schemes
-n, --name test getpwnam functions
-p, --password=STRING user password
-u, --uid test getpwuid functions
""" % sys.argv[0]
sys.exit (0)
if not len (args):
print "%s: not enough arguments, try --help" % sys.argv[0]
sys.exit (0)
if key_type == 'uid':
key = int (args[0])
else:
key = args[0]
auth.register_module (('system', 'generic'))
if key_type == 'name':
auth_data = auth.get_auth_by_name (key)
elif key_type == 'uid':
auth_data = auth.get_auth_by_uid (key)
if not auth_data:
print '"%s" not found' % key
sys.exit (0)
print "source: %s" % auth_data.source
print "user name: %s" % auth_data.name
print "password: %s" % auth_data.passwd
print "uid: %d" % auth_data.uid
print "gid: %d" % auth_data.gid
print "gecos: %s" % auth_data.gecos
print "home: %s" % auth_data.dir
print "shell: %s" % auth_data.shell
print "mailbox: %s" % auth_data.mailbox
print "quota: %d" % auth_data.quota
print "change_uid: %d" % auth_data.change_uid
if not vars ().has_key ('password'):
password = getpass.getpass ()
try:
auth.authenticate (auth_data, password)
print 'Authenticated!'
except AuthError, e:
print e
# GNU Mailutils -- a suite of utilities for electronic mail
# Copyright (C) 2009 Free Software Foundation, Inc.
#
# GNU Mailutils is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3, or (at your option)
# any later version.
#
# GNU Mailutils is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with GNU Mailutils; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301 USA
import sys
from mailutils import stream
from mailutils import filter
if len (sys.argv) != 3:
print "usage: %s from-code to-code" % sys.argv[0]
sys.exit (0)
sti = stream.StdioStream (sys.stdin)
sti.open ()
cvt = filter.FilterIconvStream (sti, sys.argv[1], sys.argv[2])
cvt.open ()
out = stream.StdioStream (sys.stdout, 0)
out.open ()
total = 0
while True:
buf = cvt.read (total)
out.sequential_write (buf)
total += cvt.read_count
if not cvt.read_count:
break
out.flush ()
out.close ()
sti.close ()
# GNU Mailutils -- a suite of utilities for electronic mail
# Copyright (C) 2009 Free Software Foundation, Inc.
#
# GNU Mailutils is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3, or (at your option)
# any later version.
#
# GNU Mailutils is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with GNU Mailutils; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301 USA
import sys
from mailutils import folder
from mailutils import registrar
from mailutils.error import *
def ls_folders (fname, ref, pattern, level):
try:
fld = folder.Folder (fname)
fld.open ()
list = fld.list (ref, pattern, level)
for f in list:
print f
print "Number of folders: %d" % len (list)
fld.close ()
except Error, e:
print e
if __name__ == '__main__':
pattern = "*"
level = 0
argc = len (sys.argv)
if argc == 5:
level = int (sys.argv[4])
pattern = sys.argv[3]
ref = sys.argv[2]
fname = sys.argv[1]
elif argc == 4:
pattern = sys.argv[3]
ref = sys.argv[2]
fname = sys.argv[1]
elif argc == 3:
ref = sys.argv[2]
fname = sys.argv[1]
elif argc == 2:
fname = sys.argv[1]
else:
print "usage: lsf folder [ref] [pattern] [recursion-level]"
sys.exit (0)
registrar.register_format ()
ls_folders (fname, ref, pattern, level)
# GNU Mailutils -- a suite of utilities for electronic mail
# Copyright (C) 2009 Free Software Foundation, Inc.
#
# GNU Mailutils is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3, or (at your option)
# any later version.
#
# GNU Mailutils is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with GNU Mailutils; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301 USA
from mailutils import stream, mailcap
stm = stream.FileStream ("/etc/mailcap")
stm.open ()
mc = mailcap.Mailcap (stm)
for i, entry in enumerate (mc):
print "entry[%d]" % (i + 1)
# typefield
print "\ttypefield: %s" % entry.get_typefield ()
# view-command
print "\tview-command: %s" % entry.get_viewcommand ()
# fields
for j, ent in enumerate (entry):
print "\tfields[%d]: %s" % ((j + 1), ent)
print
# GNU Mailutils -- a suite of utilities for electronic mail
# Copyright (C) 2009 Free Software Foundation, Inc.
#
# GNU Mailutils is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3, or (at your option)
# any later version.
#
# GNU Mailutils is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with GNU Mailutils; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301 USA
import sys
import getopt
from mailutils import *
from mailutils.header import *
print_attachments = False
indent_level = 4
def print_file (fname, indent):
try:
fp = open (fname, 'r')
for line in fp:
print "%*.*s%s" % (indent, indent, '', line)
fp.close ()
remove (fname)
except OSError, e:
print e
def print_message_part_sizes (part, indent):
print "%*.*sMessage part size - %d/%d: %d/%d, %d/%d" % \
(indent, indent, '',
part.size, part.lines,
part.header.size, part.header.lines,
part.body.size, part.body.lines)
def message_display_parts (msg, indent):
# How many parts does the message has?
nparts = msg.get_num_parts ()
# Iterate through all the parts. Treat type "message/rfc822"
# differently, since it is a message of its own that can have other
# subparts (recursive).
for j in range (1, nparts + 1):
part = msg.get_part (j)
hdr = part.get_header ()
type = hdr.get_value (MU_HEADER_CONTENT_TYPE, 'text/plain')
encoding = hdr.get_value (MU_HEADER_CONTENT_TRANSFER_ENCODING, '7bit')
print "%*.*sType of part %d = %s" % (indent, indent, '', j, type)
print_message_part_sizes (part, indent)
ismulti = part.is_multipart ()
if type == "message/rfc822" or ismulti:
if not ismulti:
part = part.unencapsulate ()
hdr = part.get_header ()
frm = hdr.get_value (MU_HEADER_FROM, "[none]")
subject = hdr.get_value (MU_HEADER_SUBJECT, "[none]")
print "%*.*sEncapsulated message : %s\t%s" % \
(indent, indent, '', frm, subject)
print "%*.*sBegin" % (indent, indent, '')
nsubparts = part.get_num_parts ()
message_display_parts (part, indent + indent_level)
elif (type.startswith ("text/plain") or
type.startswith ("text/html") or type == ''):
print "%*.*sText Message" % (indent, indent, '')
print "%*.*sBegin" % (indent, indent, '')
flt = filter.FilterStream (part.body.get_stream (), encoding)
offset = 0
while True:
buf = flt.readline (offset)
offset += flt.read_count
if not flt.read_count:
break
print "%*.*s%s" % (indent, indent, '', buf),
else:
# Save the attachements.
try:
fname = part.get_attachment_name ()
except:
fname = util.tempname ()
print "%*.*sAttachment - saving [%s]" % \
(indent, indent, '', fname)
print "%*.*sBegin" % (indent, indent, '')
part.save_attachment ()
if print_attachments:
print_file (fname, indent)
print "%*.*sEnd" % (indent, indent, '')
if __name__ == '__main__':
optdebug = False
try:
opts, args = getopt.getopt (sys.argv[1:], 'dpi:')
for o, a in opts:
if o == '-d':
optdebug = True
elif o == '-p':
print_attachments = True
elif o == '-i':
indent_level = int (a)
except getopt.GetoptError:
sys.exit (0)
# Registration.
registrar.register_format (('imap', 'pop', 'mbox'))
registrar.set_default_format ('mbox')
if args:
args = args[0]
else:
args = ''
mbox = mailbox.MailboxDefault (args)
# Debugging trace.
if optdebug:
mbox.debug.set_level (debug.MU_DEBUG_PROT)
# Open the mailbox for reading only.
mbox.open ()
# Iterate through the entire message set.
for i, msg in enumerate (mbox):
print "Message: %d" % (i + 1)
print "From: %s" % msg.header.get_value (MU_HEADER_FROM, "[none]")
print "Subject: %s" % msg.header.get_value (MU_HEADER_SUBJECT, "[none]")
print "Number of parts in message - %d" % msg.get_num_parts ()
print "Total message size - %d/%d" % (msg.size, msg.lines)
try:
message_display_parts (msg, 0)
except Error, e:
print e
mbox.close ()
# GNU Mailutils -- a suite of utilities for electronic mail
# Copyright (C) 2009 Free Software Foundation, Inc.
#
# GNU Mailutils is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3, or (at your option)
# any later version.
#
# GNU Mailutils is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with GNU Mailutils; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301 USA
import sys
import getopt
from mailutils import *
USAGE = "usage: mailer [-hd] [-m mailer] [-f from] [to]..."
HELP = """
-h print this helpful message
-m a mailer URL (default is \"sendmail:\")
-f the envelope from address (default is from user environment)
to a list of envelope to addresses (default is from message)
An RFC2822 formatted message is read from stdin and delivered using
the mailer."""
optmailer = "sendmail:"
optfrom = False
optdebug = False
try:
opts, args = getopt.getopt (sys.argv[1:], 'hdm:f:')
for o, a in opts:
if o == '-h':
print USAGE
print HELP
sys.exit (0)
elif o == '-d':
optdebug = True
elif o == '-m':
optmailer = a
elif o == '-f':
optfrom = a
except getopt.GetoptError:
print USAGE
sys.exit (0)
registrar.register_format ('sendmail')
frm = None
to = None
if optfrom:
frm = address.Address (optfrom)
if args:
to = address.Address (args)
sti = stream.StdioStream (sys.stdin, stream.MU_STREAM_SEEKABLE)
sti.open ()
msg = message.Message ()
msg.set_stream (sti)
mlr = mailer.Mailer (optmailer)
if optdebug:
mlr.debug.set_level (debug.MU_DEBUG_PROT)
mlr.open ()
mlr.send_message (msg, frm, to)
mlr.close ()
# GNU Mailutils -- a suite of utilities for electronic mail
# Copyright (C) 2009 Free Software Foundation, Inc.
#
# GNU Mailutils is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3, or (at your option)
# any later version.
#
# GNU Mailutils is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with GNU Mailutils; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301 USA
import sys
from mailutils import *
from mailutils.header import *
args = ''
if len (sys.argv) > 1:
args = sys.argv[1]
registrar.register_format ()
mbox = mailbox.MailboxDefault (args)
mbox.open ()
print "Total: %d" % len (mbox)
for msg in mbox:
print "%s %s" % (msg.header[MU_HEADER_FROM],
msg.header.get_value (MU_HEADER_SUBJECT, "(NO SUBJECT)"))
mbox.close ()
# GNU Mailutils -- a suite of utilities for electronic mail
# Copyright (C) 2009 Free Software Foundation, Inc.
#
# GNU Mailutils is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3, or (at your option)
# any later version.
#
# GNU Mailutils is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with GNU Mailutils; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301 USA
import sys
from mailutils import url
from mailutils.error import *
def parse (str):
try:
u = url.Url (str)
u.parse ()
print "URL: %s" % u
print "\tscheme <%s>" % u.get_scheme ()
print "\tuser <%s>" % u.get_user ()
print "\tpasswd <%s>" % u.get_passwd ()
print "\tauth <%s>" % u.get_auth ()
print "\thost <%s>" % u.get_host ()
print "\tport %d" % u.get_port ()
print "\tpath <%s>" % u.get_path ()
for i, param in enumerate (u.get_query ()):
print "\tquery[%d] %s" % (i, param)
except UrlError, e:
print e
def parseinput ():
try:
while True:
line = sys.stdin.readline ().strip ()
if line == '':
break
parse (line)
except KeyboardInterrupt:
sys.exit ()
if __name__ == '__main__':
if len (sys.argv) == 1:
parseinput ()
sys.exit ()
for arg in sys.argv[1:]:
if arg == '-':
parseinput ()
else:
parse (arg)
## Process this file with GNU Automake to create Makefile.in
## Copyright (C) 2009 Free Software Foundation, Inc.
##
## GNU Mailutils is free software; you can redistribute it and/or
## modify it under the terms of the GNU General Public License as
## published by the Free Software Foundation; either version 3, or (at
## your option) any later version.
##
## This program is distributed in the hope that it will be useful, but
## WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
## General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with this program; if not, write to the Free Software
## Foundation, Inc. 51 Franklin Street, Fifth Floor, Boston, MA
## 02110-1301 USA
SUBDIRS = c_api mailutils
## Process this file with GNU Automake to create Makefile.in
## Copyright (C) 2009 Free Software Foundation, Inc.
##
## GNU Mailutils is free software; you can redistribute it and/or
## modify it under the terms of the GNU General Public License as
## published by the Free Software Foundation; either version 3, or (at
## your option) any later version.
##
## This program is distributed in the hope that it will be useful, but
## WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
## General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with this program; if not, write to the Free Software
## Foundation, Inc. 51 Franklin Street, Fifth Floor, Boston, MA
## 02110-1301 USA
INCLUDES = @MU_COMMON_INCLUDES@ $(PYTHON_INCLUDES)
MU_PYTHON_LTLIBS = c_api.la
EXTRA_LTLIBRARIES = c_api.la
pkgpyexec_LTLIBRARIES = @MU_PYTHON_LTLIBS@
c_api_la_LDFLAGS = -avoid-version -module -rpath $(pkgpyexecdir)
c_api_la_LIBADD = $(PYTHON_LIBS) @MU_COMMON_LIBRARIES@ \
${MU_LIB_MBOX}\
${MU_LIB_IMAP}\
${MU_LIB_POP}\
${MU_LIB_NNTP}\
${MU_LIB_MH}\
${MU_LIB_MAILDIR}\
${MU_LIB_AUTH}\
${MU_LIB_MAILER}\
@MU_AUTHLIBS@\
${MU_LIB_MAILUTILS}
c_api_la_SOURCES = \
c_api.c \
c_api.h \
error.c \
address.c \
address-private.h \
attribute.c \
attribute-private.h \
auth.c \
auth-private.h \
body.c \
body-private.h \
debug.c \
debug-private.h \
envelope.c \
envelope-private.h \
filter.c \
folder.c \
folder-private.h \
list.c \
list-private.h \
header.c \
header-private.h \
mailer.c \
mailer-private.h \
mailbox.c \
mailbox-private.h \
mailcap.c \
mailcap-private.h \
message.c \
message-private.h \
mime.c \
mime-private.h \
stream.c \
stream-private.h \
registrar.c \
url.c \
url-private.h \
util.c
/*
GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 2009 Free Software Foundation, Inc.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General
Public License along with this library; if not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301 USA
*/
#ifndef _MUCAPI_ADDRESS_H
#define _MUCAPI_ADDRESS_H
#include <mailutils/address.h>
typedef struct {
PyObject_HEAD;
mu_address_t addr;
} PyAddress;
extern PyAddress * PyAddress_NEW ();
extern int PyAddress_Check (PyObject *x);
#endif /* not _MUCAPI_ADDRESS_H */
/*
GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 2009 Free Software Foundation, Inc.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General
Public License along with this library; if not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301 USA
*/
#include "c_api.h"
#include "address-private.h"
#define PY_MODULE "address"
#define PY_CSNAME "AddressType"
static PyObject *
_repr (PyObject *self)
{
char buf[80];
sprintf (buf, "<" PY_MODULE "." PY_CSNAME " instance at %p>", self);
return PyString_FromString (buf);
}
static PyTypeObject PyAddressType = {
PyObject_HEAD_INIT(NULL)
0, /* ob_size */
PY_MODULE "." PY_CSNAME, /* tp_name */
sizeof (PyAddress), /* tp_basicsize */
0, /* tp_itemsize */
(destructor)py_dealloc, /* tp_dealloc */
0, /* tp_print */
0, /* tp_getattr; __getattr__ */
0, /* tp_setattr; __setattr__ */
0, /* tp_compare; __cmp__ */
_repr, /* tp_repr; __repr__ */
0, /* tp_as_number */
0, /* tp_as_sequence */
0, /* tp_as_mapping */
0, /* tp_hash; __hash__ */
0, /* tp_call; __call__ */
_repr, /* tp_str; __str__ */
0, /* tp_getattro */
0, /* tp_setattro */
0, /* tp_as_buffer */
Py_TPFLAGS_DEFAULT, /* tp_flags */
"", /* tp_doc */
0, /* tp_traverse */
0, /* tp_clear */
0, /* tp_richcompare */
0, /* tp_weaklistoffset */
0, /* tp_iter */
0, /* tp_iternext */
0, /* tp_methods */
0, /* tp_members */
0, /* tp_getset */
0, /* tp_base */
0, /* tp_dict */
0, /* tp_descr_get */
0, /* tp_descr_set */
0, /* tp_dictoffset */
0, /* tp_init */
0, /* tp_alloc */
0, /* tp_new */
};
PyAddress *
PyAddress_NEW ()
{
return (PyAddress *)PyObject_NEW (PyAddress, &PyAddressType);
}
int
PyAddress_Check (PyObject *x)
{
return x->ob_type == &PyAddressType;
}
static PyObject *
api_address_create (PyObject *self, PyObject *args)
{
int status;
char *str;
PyAddress *py_addr;
if (!PyArg_ParseTuple (args, "O!s", &PyAddressType, &py_addr, &str))
return NULL;
status = mu_address_create (&py_addr->addr, str);
return _ro (PyInt_FromLong (status));
}
static PyObject *
api_address_createv (PyObject *self, PyObject *args)
{
int status;
char *str;
PyAddress *py_addr;
PyObject *py_seq;
char **sv;
size_t len;
if (!PyArg_ParseTuple (args, "O!O", &PyAddressType, &py_addr, &py_seq))
return NULL;
if (!PySequence_Check (py_seq))
{
PyErr_SetString (PyExc_TypeError, "");
return NULL;
}
len = PySequence_Size (py_seq);
sv = (char **) malloc ((len + 1) * sizeof (char *));
if (!sv)
{
PyErr_NoMemory ();
return NULL;
}
else
{
PyObject *py_item;
int i;
for (i = 0; i < len; i++) {
py_item = PySequence_GetItem (py_seq, i);
if (py_item && PyString_Check (py_item))
sv[i] = strdup (PyString_AsString (py_item));
Py_DECREF (py_item);
}
if (PyErr_Occurred ()) {
PyErr_Print ();
return NULL;
}
}
status = mu_address_createv (&py_addr->addr, (const char**)sv, len);
return _ro (PyInt_FromLong (status));
}
static PyObject *
api_address_destroy (PyObject *self, PyObject *args)
{
PyAddress *py_addr;
if (!PyArg_ParseTuple (args, "O!", &PyAddressType, &py_addr))
return NULL;
mu_address_destroy (&py_addr->addr);
return _ro (Py_None);
}
static PyObject *
api_address_is_group (PyObject *self, PyObject *args)
{
int status, n, isgroup;
PyAddress *py_addr;
if (!PyArg_ParseTuple (args, "O!i", &PyAddressType, &py_addr, &n))
return NULL;
status = mu_address_is_group (py_addr->addr, n, &isgroup);
return status_object (status, PyBool_FromLong (isgroup));
}
static PyObject *
api_address_get_count (PyObject *self, PyObject *args)
{
size_t count = 0;
PyAddress *py_addr;
if (!PyArg_ParseTuple (args, "O!", &PyAddressType, &py_addr))
return NULL;
mu_address_get_count (py_addr->addr, &count);
return _ro (PyInt_FromLong (count));
}
static PyObject *
api_address_get_email (PyObject *self, PyObject *args)
{
int status, n;
const char *buf = NULL;
PyAddress *py_addr;
if (!PyArg_ParseTuple (args, "O!i", &PyAddressType, &py_addr, &n))
return NULL;
status = mu_address_sget_email (py_addr->addr, n, &buf);
return status_object (status, PyString_FromString (buf ? buf : ""));
}
static PyObject *
api_address_get_local_part (PyObject *self, PyObject *args)
{
int status, n;
const char *buf = NULL;
PyAddress *py_addr;
if (!PyArg_ParseTuple (args, "O!i", &PyAddressType, &py_addr, &n))
return NULL;
status = mu_address_sget_local_part (py_addr->addr, n, &buf);
return status_object (status, PyString_FromString (buf ? buf : ""));
}
static PyObject *
api_address_get_domain (PyObject *self, PyObject *args)
{
int status, n;
const char *buf = NULL;
PyAddress *py_addr;
if (!PyArg_ParseTuple (args, "O!i", &PyAddressType, &py_addr, &n))
return NULL;
status = mu_address_sget_domain (py_addr->addr, n, &buf);
return status_object (status, PyString_FromString (buf ? buf : ""));
}
static PyObject *
api_address_get_personal (PyObject *self, PyObject *args)
{
int status, n;
const char *buf = NULL;
PyAddress *py_addr;
if (!PyArg_ParseTuple (args, "O!i", &PyAddressType, &py_addr, &n))
return NULL;
status = mu_address_sget_personal (py_addr->addr, n, &buf);
return status_object (status, PyString_FromString (buf ? buf : ""));
}
static PyObject *
api_address_get_comments (PyObject *self, PyObject *args)
{
int status, n;
const char *buf = NULL;
PyAddress *py_addr;
if (!PyArg_ParseTuple (args, "O!i", &PyAddressType, &py_addr, &n))
return NULL;
status = mu_address_sget_comments (py_addr->addr, n, &buf);
return status_object (status, PyString_FromString (buf ? buf : ""));
}
static PyObject *
api_address_get_route (PyObject *self, PyObject *args)
{
int status, n;
const char *buf = NULL;
PyAddress *py_addr;
if (!PyArg_ParseTuple (args, "O!i", &PyAddressType, &py_addr, &n))
return NULL;
status = mu_address_sget_route (py_addr->addr, n, &buf);
return status_object (status, PyString_FromString (buf ? buf : ""));
}
static PyObject *
api_address_to_string (PyObject *self, PyObject *args)
{
int status, n;
char buf[256];
PyAddress *py_addr;
memset (buf, 0, sizeof (buf));
if (!PyArg_ParseTuple (args, "O!", &PyAddressType, &py_addr))
return NULL;
status = mu_address_to_string (py_addr->addr, buf, sizeof (buf), &n);
return status_object (status, PyString_FromString (buf));
}
static PyMethodDef methods[] = {
{ "create", (PyCFunction) api_address_create, METH_VARARGS,
"Allocate and initialize ADDR by parsing the RFC822 "
"address-list STRING." },
{ "createv", (PyCFunction) api_address_createv, METH_VARARGS,
"Allocate and initialize ADDR by parsing the RFC822 address-list." },
{ "destroy", (PyCFunction) api_address_destroy, METH_VARARGS,
"Destroy ADDR." },
{ "is_group", (PyCFunction) api_address_is_group, METH_VARARGS,
"Return True if address is just the name of a group, False otherwise." },
{ "get_count", (PyCFunction) api_address_get_count, METH_VARARGS,
"Return a count of the addresses in the address list." },
{ "get_email", (PyCFunction) api_address_get_email, METH_VARARGS,
"Return the Nth email address component of the address list." },
{ "get_local_part", (PyCFunction) api_address_get_local_part, METH_VARARGS,
"Return local part of the Nth email address from the address list." },
{ "get_domain", (PyCFunction) api_address_get_domain, METH_VARARGS,
"Return domain part of the Nth email address from the address list." },
{ "get_personal", (PyCFunction) api_address_get_personal, METH_VARARGS,
"Return personal part of the Nth email address from the address list." },
{ "get_comments", (PyCFunction) api_address_get_comments, METH_VARARGS,
"Return comment part of the Nth email address from the list." },
{ "get_route", (PyCFunction) api_address_get_route, METH_VARARGS,
"Return route part of the Nth email address from the list." },
{ "to_string", (PyCFunction) api_address_to_string, METH_VARARGS,
"Return the entire address list as a single RFC822 formatted address list." },
{ NULL, NULL, 0, NULL }
};
void
init_address ()
{
PyObject *m;
PyAddressType.tp_new = PyType_GenericNew;
if (PyType_Ready (&PyAddressType) < 0)
return;
if ((m = attach_module (PY_MODULE, methods)))
{
Py_INCREF (&PyAddressType);
PyModule_AddObject (m, PY_CSNAME, (PyObject *)&PyAddressType);
}
}
/*
GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 2009 Free Software Foundation, Inc.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General
Public License along with this library; if not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301 USA
*/
#ifndef _MUCAPI_ATTRIBUTE_H
#define _MUCAPI_ATTRIBUTE_H
#include <mailutils/attribute.h>
typedef struct {
PyObject_HEAD;
mu_attribute_t attr;
} PyAttribute;
extern PyAttribute * PyAttribute_NEW ();
#endif /* not _MUCAPI_ATTRIBUTE_H */
/*
GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 2009 Free Software Foundation, Inc.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General
Public License along with this library; if not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301 USA
*/
#include "c_api.h"
#include "attribute-private.h"
#define PY_MODULE "attribute"
#define PY_CSNAME "AttributeType"
static PyObject *
_repr (PyObject *self)
{
char buf[80];
sprintf (buf, "<" PY_MODULE "." PY_CSNAME " instance at %p>", self);
return PyString_FromString (buf);
}
static PyTypeObject PyAttributeType = {
PyObject_HEAD_INIT(NULL)
0, /* ob_size */
PY_MODULE "." PY_CSNAME, /* tp_name */
sizeof (PyAttribute), /* tp_basicsize */
0, /* tp_itemsize */
(destructor)py_dealloc, /* tp_dealloc */
0, /* tp_print */
0, /* tp_getattr; __getattr__ */
0, /* tp_setattr; __setattr__ */
0, /* tp_compare; __cmp__ */
_repr, /* tp_repr; __repr__ */
0, /* tp_as_number */
0, /* tp_as_sequence */
0, /* tp_as_mapping */
0, /* tp_hash; __hash__ */
0, /* tp_call; __call__ */
_repr, /* tp_str; __str__ */
0, /* tp_getattro */
0, /* tp_setattro */
0, /* tp_as_buffer */
Py_TPFLAGS_DEFAULT, /* tp_flags */
"", /* tp_doc */
0, /* tp_traverse */
0, /* tp_clear */
0, /* tp_richcompare */
0, /* tp_weaklistoffset */
0, /* tp_iter */
0, /* tp_iternext */
0, /* tp_methods */
0, /* tp_members */
0, /* tp_getset */
0, /* tp_base */
0, /* tp_dict */
0, /* tp_descr_get */
0, /* tp_descr_set */
0, /* tp_dictoffset */
0, /* tp_init */
0, /* tp_alloc */
0, /* tp_new */
};
PyAttribute *
PyAttribute_NEW ()
{
return (PyAttribute *)PyObject_NEW (PyAttribute, &PyAttributeType);
}
static PyObject *
api_attribute_create (PyObject *self, PyObject *args)
{
int status;
PyAttribute *py_attr;
if (!PyArg_ParseTuple (args, "O!", &PyAttributeType, &py_attr))
return NULL;
status = mu_attribute_create (&py_attr->attr, NULL);
return _ro (PyInt_FromLong (status));
}
static PyObject *
api_attribute_destroy (PyObject *self, PyObject *args)
{
PyAttribute *py_attr;
if (!PyArg_ParseTuple (args, "O!", &PyAttributeType, &py_attr))
return NULL;
mu_attribute_destroy (&py_attr->attr, NULL);
return _ro (Py_None);
}
static PyObject *
api_attribute_is_modified (PyObject *self, PyObject *args)
{
int state;
PyAttribute *py_attr;
if (!PyArg_ParseTuple (args, "O!", &PyAttributeType, &py_attr))
return NULL;
state = mu_attribute_is_modified (py_attr->attr);
return _ro (PyBool_FromLong (state));
}
static PyObject *
api_attribute_clear_modified (PyObject *self, PyObject *args)
{
PyAttribute *py_attr;
if (!PyArg_ParseTuple (args, "O!", &PyAttributeType, &py_attr))
return NULL;
mu_attribute_clear_modified (py_attr->attr);
return _ro (Py_None);
}
static PyObject *
api_attribute_set_modified (PyObject *self, PyObject *args)
{
PyAttribute *py_attr;
if (!PyArg_ParseTuple (args, "O!", &PyAttributeType, &py_attr))
return NULL;
mu_attribute_set_modified (py_attr->attr);
return _ro (Py_None);
}
static PyObject *
api_attribute_get_flags (PyObject *self, PyObject *args)
{
int status, flags = 0;
PyAttribute *py_attr;
if (!PyArg_ParseTuple (args, "O!", &PyAttributeType, &py_attr))
return NULL;
status = mu_attribute_get_flags (py_attr->attr, &flags);
return status_object (status, PyInt_FromLong (flags));
}
static PyObject *
api_attribute_set_flags (PyObject *self, PyObject *args)
{
int status, flags;
PyAttribute *py_attr;
if (!PyArg_ParseTuple (args, "O!i", &PyAttributeType, &py_attr, &flags))
return NULL;
status = mu_attribute_set_flags (py_attr->attr, flags);
return _ro (PyInt_FromLong (status));
}
static PyObject *
api_attribute_unset_flags (PyObject *self, PyObject *args)
{
int status, flags;
PyAttribute *py_attr;
if (!PyArg_ParseTuple (args, "O!i", &PyAttributeType, &py_attr, &flags))
return NULL;
status = mu_attribute_unset_flags (py_attr->attr, flags);
return _ro (PyInt_FromLong (status));
}
static PyObject *
api_attribute_to_string (PyObject *self, PyObject *args)
{
char buf[MU_STATUS_BUF_SIZE];
size_t na = 0;
PyAttribute *py_attr;
memset (buf, 0, sizeof (buf));
if (!PyArg_ParseTuple (args, "O!", &PyAttributeType, &py_attr))
return NULL;
mu_attribute_to_string (py_attr->attr, buf, sizeof (buf), &na);
return _ro (PyString_FromString (buf));
}
static PyMethodDef methods[] = {
{ "create", (PyCFunction) api_attribute_create, METH_VARARGS,
"" },
{ "destroy", (PyCFunction) api_attribute_destroy, METH_VARARGS,
"" },
{ "is_modified", (PyCFunction) api_attribute_is_modified, METH_VARARGS,
"Return TRUE or FALSE whether attribute has been modified." },
{ "clear_modified", (PyCFunction) api_attribute_clear_modified,
METH_VARARGS, "" },
{ "set_modified", (PyCFunction) api_attribute_set_modified, METH_VARARGS,
"" },
{ "get_flags", (PyCFunction) api_attribute_get_flags, METH_VARARGS,
"" },
{ "set_flags", (PyCFunction) api_attribute_set_flags, METH_VARARGS,
"" },
{ "unset_flags", (PyCFunction) api_attribute_unset_flags, METH_VARARGS,
"" },
{ "to_string", (PyCFunction) api_attribute_to_string, METH_VARARGS,
"" },
{ NULL, NULL, 0, NULL }
};
void
init_attribute ()
{
PyObject *m;
PyAttributeType.tp_new = PyType_GenericNew;
if (PyType_Ready (&PyAttributeType) < 0)
return;
if ((m = attach_module (PY_MODULE, methods)))
{
Py_INCREF (&PyAttributeType);
PyModule_AddObject (m, PY_CSNAME, (PyObject *)&PyAttributeType);
}
}
/*
GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 2009 Free Software Foundation, Inc.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General
Public License along with this library; if not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301 USA
*/
#ifndef _MUCAPI_AUTH_H
#define _MUCAPI_AUTH_H
#include <mailutils/auth.h>
#include <mailutils/mu_auth.h>
typedef struct {
PyObject_HEAD;
mu_authority_t auth;
} PyAuthority;
typedef struct {
PyObject_HEAD;
mu_ticket_t ticket;
} PyTicket;
typedef struct {
PyObject_HEAD;
mu_wicket_t wicket;
} PyWicket;
typedef struct {
PyObject_HEAD;
struct mu_auth_data *auth_data;
} PyAuthData;
extern PyAuthority * PyAuthority_NEW ();
extern int PyAuthority_Check (PyObject *x);
extern PyTicket * PyTicket_NEW ();
extern int PyTicket_Check (PyObject *x);
extern PyWicket * PyWicket_NEW ();
extern int PyWicket_Check (PyObject *x);
extern PyAuthData * PyAuthData_NEW ();
extern int PyAuthData_Check (PyObject *x);
#endif /* not _MUCAPI_AUTH_H */
/*
GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 2009 Free Software Foundation, Inc.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General
Public License along with this library; if not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301 USA
*/
#include "c_api.h"
#include "auth-private.h"
#define PY_MODULE "auth"
#define PY_CSNAME1 "AuthorityType"
#define PY_CSNAME2 "TicketType"
#define PY_CSNAME3 "WicketType"
#define PY_CSNAME4 "AuthDataType"
static PyObject *
_repr1 (PyObject *self)
{
char buf[80];
sprintf (buf, "<" PY_MODULE "." PY_CSNAME1 " instance at %p>", self);
return PyString_FromString (buf);
}
static PyObject *
_repr2 (PyObject *self)
{
char buf[80];
sprintf (buf, "<" PY_MODULE "." PY_CSNAME2 " instance at %p>", self);
return PyString_FromString (buf);
}
static PyObject *
_repr3 (PyObject *self)
{
char buf[80];
sprintf (buf, "<" PY_MODULE "." PY_CSNAME3 " instance at %p>", self);
return PyString_FromString (buf);
}
static PyObject *
_repr4 (PyObject *self)
{
char buf[80];
sprintf (buf, "<" PY_MODULE "." PY_CSNAME4 " instance at %p>", self);
return PyString_FromString (buf);
}
static PyTypeObject PyAuthorityType = {
PyObject_HEAD_INIT(NULL)
0, /* ob_size */
PY_MODULE "." PY_CSNAME1, /* tp_name */
sizeof (PyAuthority), /* tp_basicsize */
0, /* tp_itemsize */
(destructor)py_dealloc, /* tp_dealloc */
0, /* tp_print */
0, /* tp_getattr; __getattr__ */
0, /* tp_setattr; __setattr__ */
0, /* tp_compare; __cmp__ */
_repr1, /* tp_repr; __repr__ */
0, /* tp_as_number */
0, /* tp_as_sequence */
0, /* tp_as_mapping */
0, /* tp_hash; __hash__ */
0, /* tp_call; __call__ */
_repr1, /* tp_str; __str__ */
0, /* tp_getattro */
0, /* tp_setattro */
0, /* tp_as_buffer */
Py_TPFLAGS_DEFAULT, /* tp_flags */
"", /* tp_doc */
0, /* tp_traverse */
0, /* tp_clear */
0, /* tp_richcompare */
0, /* tp_weaklistoffset */
0, /* tp_iter */
0, /* tp_iternext */
0, /* tp_methods */
0, /* tp_members */
0, /* tp_getset */
0, /* tp_base */
0, /* tp_dict */
0, /* tp_descr_get */
0, /* tp_descr_set */
0, /* tp_dictoffset */
0, /* tp_init */
0, /* tp_alloc */
0, /* tp_new */
};
static PyTypeObject PyTicketType = {
PyObject_HEAD_INIT(NULL)
0, /* ob_size */
PY_MODULE "." PY_CSNAME2, /* tp_name */
sizeof (PyTicket), /* tp_basicsize */
0, /* tp_itemsize */
(destructor)py_dealloc, /* tp_dealloc */
0, /* tp_print */
0, /* tp_getattr; __getattr__ */
0, /* tp_setattr; __setattr__ */
0, /* tp_compare; __cmp__ */
_repr2, /* tp_repr; __repr__ */
0, /* tp_as_number */
0, /* tp_as_sequence */
0, /* tp_as_mapping */
0, /* tp_hash; __hash__ */
0, /* tp_call; __call__ */
_repr2, /* tp_str; __str__ */
0, /* tp_getattro */
0, /* tp_setattro */
0, /* tp_as_buffer */
Py_TPFLAGS_DEFAULT, /* tp_flags */
"", /* tp_doc */
0, /* tp_traverse */
0, /* tp_clear */
0, /* tp_richcompare */
0, /* tp_weaklistoffset */
0, /* tp_iter */
0, /* tp_iternext */
0, /* tp_methods */
0, /* tp_members */
0, /* tp_getset */
0, /* tp_base */
0, /* tp_dict */
0, /* tp_descr_get */
0, /* tp_descr_set */
0, /* tp_dictoffset */
0, /* tp_init */
0, /* tp_alloc */
0, /* tp_new */
};
static PyTypeObject PyWicketType = {
PyObject_HEAD_INIT(NULL)
0, /* ob_size */
PY_MODULE "." PY_CSNAME3, /* tp_name */
sizeof (PyWicket), /* tp_basicsize */
0, /* tp_itemsize */
(destructor)py_dealloc, /* tp_dealloc */
0, /* tp_print */
0, /* tp_getattr; __getattr__ */
0, /* tp_setattr; __setattr__ */
0, /* tp_compare; __cmp__ */
_repr3, /* tp_repr; __repr__ */
0, /* tp_as_number */
0, /* tp_as_sequence */
0, /* tp_as_mapping */
0, /* tp_hash; __hash__ */
0, /* tp_call; __call__ */
_repr3, /* tp_str; __str__ */
0, /* tp_getattro */
0, /* tp_setattro */
0, /* tp_as_buffer */
Py_TPFLAGS_DEFAULT, /* tp_flags */
"", /* tp_doc */
0, /* tp_traverse */
0, /* tp_clear */
0, /* tp_richcompare */
0, /* tp_weaklistoffset */
0, /* tp_iter */
0, /* tp_iternext */
0, /* tp_methods */
0, /* tp_members */
0, /* tp_getset */
0, /* tp_base */
0, /* tp_dict */
0, /* tp_descr_get */
0, /* tp_descr_set */
0, /* tp_dictoffset */
0, /* tp_init */
0, /* tp_alloc */
0, /* tp_new */
};
void
_dealloc4 (PyObject *self)
{
PyAuthData *py_ad = (PyAuthData *)self;
if (py_ad->auth_data)
mu_auth_data_free (py_ad->auth_data);
self->ob_type->tp_free (self);
}
static PyObject *
_getattr4 (PyObject *self, char *name)
{
PyAuthData *py_ad = (PyAuthData *)self;
struct mu_auth_data *ad = py_ad->auth_data;
if (!ad)
return NULL;
if (strcmp (name, "name") == 0) {
return PyString_FromString (ad->name);
}
else if (strcmp (name, "passwd") == 0) {
return PyString_FromString (ad->passwd);
}
else if (strcmp (name, "uid") == 0) {
return PyInt_FromLong (ad->uid);
}
else if (strcmp (name, "gid") == 0) {
return PyInt_FromLong (ad->gid);
}
else if (strcmp (name, "gecos") == 0) {
return PyString_FromString (ad->gecos);
}
else if (strcmp (name, "dir") == 0) {
return PyString_FromString (ad->dir);
}
else if (strcmp (name, "shell") == 0) {
return PyString_FromString (ad->shell);
}
else if (strcmp (name, "mailbox") == 0) {
return PyString_FromString (ad->mailbox);
}
else if (strcmp (name, "source") == 0) {
return PyString_FromString (ad->source);
}
else if (strcmp (name, "quota") == 0) {
return PyInt_FromLong (ad->quota);
}
else if (strcmp (name, "flags") == 0) {
return PyInt_FromLong (ad->flags);
}
else if (strcmp (name, "change_uid") == 0) {
return PyInt_FromLong (ad->change_uid);
}
return NULL;
}
static PyTypeObject PyAuthDataType = {
PyObject_HEAD_INIT(NULL)
0, /* ob_size */
PY_MODULE "." PY_CSNAME4, /* tp_name */
sizeof (PyAuthData), /* tp_basicsize */
0, /* tp_itemsize */
(destructor)_dealloc4, /* tp_dealloc */
0, /* tp_print */
_getattr4, /* tp_getattr; __getattr__ */
0, /* tp_setattr; __setattr__ */
0, /* tp_compare; __cmp__ */
_repr4, /* tp_repr; __repr__ */
0, /* tp_as_number */
0, /* tp_as_sequence */
0, /* tp_as_mapping */
0, /* tp_hash; __hash__ */
0, /* tp_call; __call__ */
_repr4, /* tp_str; __str__ */
0, /* tp_getattro */
0, /* tp_setattro */
0, /* tp_as_buffer */
Py_TPFLAGS_DEFAULT, /* tp_flags */
"", /* tp_doc */
0, /* tp_traverse */
0, /* tp_clear */
0, /* tp_richcompare */
0, /* tp_weaklistoffset */
0, /* tp_iter */
0, /* tp_iternext */
0, /* tp_methods */
0, /* tp_members */
0, /* tp_getset */
0, /* tp_base */
0, /* tp_dict */
0, /* tp_descr_get */
0, /* tp_descr_set */
0, /* tp_dictoffset */
0, /* tp_init */
0, /* tp_alloc */
0, /* tp_new */
};
PyAuthority *
PyAuthority_NEW ()
{
return (PyAuthority *)PyObject_NEW (PyAuthority, &PyAuthorityType);
}
int
PyAuthority_Check (PyObject *x)
{
return x->ob_type == &PyAuthorityType;
}
PyTicket *
PyTicket_NEW ()
{
return (PyTicket *)PyObject_NEW (PyTicket, &PyTicketType);
}
int
PyTicket_Check (PyObject *x)
{
return x->ob_type == &PyTicketType;
}
PyWicket *
PyWicket_NEW ()
{
return (PyWicket *)PyObject_NEW (PyWicket, &PyWicketType);
}
int
PyWicket_Check (PyObject *x)
{
return x->ob_type == &PyWicketType;
}
PyAuthData *
PyAuthData_NEW ()
{
return (PyAuthData *)PyObject_NEW (PyAuthData, &PyAuthDataType);
}
int
PyAuthData_Check (PyObject *x)
{
return x->ob_type == &PyAuthDataType;
}
/*
* Authority
*/
static PyObject *
api_authority_create (PyObject *self, PyObject *args)
{
int status;
PyAuthority *py_auth;
PyTicket *py_ticket;
if (!PyArg_ParseTuple (args, "O!O!",
&PyAuthorityType, &py_auth,
&PyTicketType, &py_ticket))
return NULL;
status = mu_authority_create (&py_auth->auth, py_ticket->ticket, NULL);
return _ro (PyInt_FromLong (status));
}
static PyObject *
api_authority_destroy (PyObject *self, PyObject *args)
{
PyAuthority *py_auth;
if (!PyArg_ParseTuple (args, "O!", &PyAuthorityType, &py_auth))
return NULL;
mu_authority_destroy (&py_auth->auth, NULL);
return _ro (Py_None);
}
static PyObject *
api_authority_get_ticket (PyObject *self, PyObject *args)
{
int status;
PyAuthority *py_auth;
PyTicket *py_ticket = PyTicket_NEW ();
if (!PyArg_ParseTuple (args, "O!", &PyAuthorityType, &py_auth))
return NULL;
Py_INCREF (py_ticket);
status = mu_authority_get_ticket (py_auth->auth, &py_ticket->ticket);
return status_object (status, (PyObject *)py_ticket);
}
static PyObject *
api_authority_set_ticket (PyObject *self, PyObject *args)
{
int status;
PyAuthority *py_auth;
PyTicket *py_ticket;
if (!PyArg_ParseTuple (args, "O!O!",
&PyAuthorityType, &py_auth,
&PyTicketType, &py_ticket))
return NULL;
status = mu_authority_set_ticket (py_auth->auth, py_ticket->ticket);
return _ro (PyInt_FromLong (status));
}
static PyObject *
api_authority_authenticate (PyObject *self, PyObject *args)
{
int status;
PyAuthority *py_auth;
if (!PyArg_ParseTuple (args, "O!", &PyAuthorityType, &py_auth))
return NULL;
status = mu_authority_authenticate (py_auth->auth);
return _ro (PyInt_FromLong (status));
}
/*
* Ticket
*/
static PyObject *
api_ticket_create (PyObject *self, PyObject *args)
{
int status;
PyTicket *py_ticket;
if (!PyArg_ParseTuple (args, "O!", &PyTicketType, &py_ticket))
return NULL;
status = mu_ticket_create (&py_ticket->ticket, NULL);
return _ro (PyInt_FromLong (status));
}
static PyObject *
api_ticket_destroy (PyObject *self, PyObject *args)
{
PyTicket *py_ticket;
if (!PyArg_ParseTuple (args, "O!", &PyTicketType, &py_ticket))
return NULL;
mu_ticket_destroy (&py_ticket->ticket, NULL);
return _ro (Py_None);
}
/*
* Wicket
*/
static PyObject *
api_wicket_create (PyObject *self, PyObject *args)
{
int status;
char *filename;
PyWicket *py_wicket;
if (!PyArg_ParseTuple (args, "O!s", &PyWicketType, &py_wicket, &filename))
return NULL;
status = mu_wicket_create (&py_wicket->wicket, filename);
return _ro (PyInt_FromLong (status));
}
static PyObject *
api_wicket_destroy (PyObject *self, PyObject *args)
{
PyWicket *py_wicket;
if (!PyArg_ParseTuple (args, "O!", &PyWicketType, &py_wicket))
return NULL;
mu_wicket_destroy (&py_wicket->wicket);
return _ro (Py_None);
}
static PyObject *
api_wicket_get_filename (PyObject *self, PyObject *args)
{
int status;
size_t n;
char filename[512];
PyWicket *py_wicket;
memset (filename, 0, sizeof (filename));
if (!PyArg_ParseTuple (args, "O!", &PyWicketType, &py_wicket))
return NULL;
status = mu_wicket_get_filename (py_wicket->wicket, filename,
sizeof (filename), &n);
return status_object (status, PyString_FromString (filename));
}
static PyObject *
api_wicket_set_filename (PyObject *self, PyObject *args)
{
int status;
char *filename;
PyWicket *py_wicket;
if (!PyArg_ParseTuple (args, "O!s", &PyWicketType, &py_wicket, &filename))
return NULL;
status = mu_wicket_set_filename (py_wicket->wicket, filename);
return _ro (PyInt_FromLong (status));
}
/*
* mu_auth
*/
struct module_record {
char *name;
struct mu_auth_module *module;
};
static struct module_record module_table[] = {
{ "system", &mu_auth_system_module },
{ "generic", &mu_auth_generic_module },
{ "pam", &mu_auth_pam_module },
{ "sql", &mu_auth_sql_module },
{ "virtual", &mu_auth_virtual_module },
{ "radius", &mu_auth_radius_module },
{ "ldap", &mu_auth_ldap_module },
{ NULL, NULL },
};
static struct mu_auth_module *
find_module (const struct module_record *table, const char *name)
{
for (; table->name; table++)
if (strcmp (table->name, name) == 0)
break;
return table->module;
}
static int
register_module (const char *name)
{
int status = 0;
if (!name)
{
struct module_record *table;
for (table = module_table; table->name; table++)
mu_auth_register_module (table->module);
}
else
{
struct mu_auth_module *module = find_module (module_table, name);
if (module)
mu_auth_register_module (module);
else
status = EINVAL;
}
return status;
}
static PyObject *
api_register_module (PyObject *self, PyObject *args)
{
int status;
char *name = NULL;
if (!PyArg_ParseTuple (args, "|s", &name))
return NULL;
status = register_module (name);
return _ro (PyInt_FromLong (status));
}
static PyObject *
api_get_auth_by_name (PyObject *self, PyObject *args)
{
int status;
char *username;
PyAuthData *py_ad = PyAuthData_NEW ();
if (!PyArg_ParseTuple (args, "s", &username))
return NULL;
Py_INCREF (py_ad);
py_ad->auth_data = mu_get_auth_by_name (username);
if (!py_ad->auth_data)
return _ro (Py_None);
return _ro ((PyObject *)py_ad);
}
static PyObject *
api_get_auth_by_uid (PyObject *self, PyObject *args)
{
int status;
uid_t uid;
PyAuthData *py_ad = PyAuthData_NEW ();
if (!PyArg_ParseTuple (args, "i", &uid))
return NULL;
Py_INCREF (py_ad);
py_ad->auth_data = mu_get_auth_by_uid (uid);
if (!py_ad->auth_data)
return _ro (Py_None);
return _ro ((PyObject *)py_ad);
}
static PyObject *
api_authenticate (PyObject *self, PyObject *args)
{
int status;
char *pass;
PyAuthData *py_ad;
if (!PyArg_ParseTuple (args, "O!s", &PyAuthDataType, &py_ad, &pass))
return NULL;
status = mu_authenticate (py_ad->auth_data, pass);
return _ro (PyInt_FromLong (status));
}
static PyMethodDef methods[] = {
{ "authority_create", (PyCFunction) api_authority_create, METH_VARARGS,
"" },
{ "authority_destroy", (PyCFunction) api_authority_destroy, METH_VARARGS,
"" },
{ "authority_get_ticket", (PyCFunction) api_authority_get_ticket,
METH_VARARGS, "" },
{ "authority_set_ticket", (PyCFunction) api_authority_set_ticket,
METH_VARARGS, "" },
{ "authority_authenticate", (PyCFunction) api_authority_authenticate,
METH_VARARGS, "" },
{ "ticket_create", (PyCFunction) api_ticket_create, METH_VARARGS,
"" },
{ "ticket_destroy", (PyCFunction) api_ticket_destroy, METH_VARARGS,
"" },
{ "wicket_create", (PyCFunction) api_wicket_create, METH_VARARGS,
"" },
{ "wicket_destroy", (PyCFunction) api_wicket_destroy, METH_VARARGS,
"" },
{ "wicket_get_filename", (PyCFunction) api_wicket_get_filename, METH_VARARGS,
"" },
{ "wicket_set_filename", (PyCFunction) api_wicket_set_filename, METH_VARARGS,
"" },
{ "register_module", (PyCFunction) api_register_module, METH_VARARGS,
"" },
{ "get_auth_by_name", (PyCFunction) api_get_auth_by_name, METH_VARARGS,
"" },
{ "get_auth_by_uid", (PyCFunction) api_get_auth_by_uid, METH_VARARGS,
"" },
{ "authenticate", (PyCFunction) api_authenticate, METH_VARARGS,
"" },
{ NULL, NULL, 0, NULL }
};
void
init_auth ()
{
PyObject *m;
PyAuthorityType.tp_new = PyType_GenericNew;
PyTicketType.tp_new = PyType_GenericNew;
PyWicketType.tp_new = PyType_GenericNew;
PyAuthDataType.tp_new = PyType_GenericNew;
if (PyType_Ready (&PyAuthorityType) < 0)
return;
if (PyType_Ready (&PyTicketType) < 0)
return;
if (PyType_Ready (&PyWicketType) < 0)
return;
if (PyType_Ready (&PyAuthDataType) < 0)
return;
if ((m = attach_module (PY_MODULE, methods)))
{
Py_INCREF (&PyAuthorityType);
Py_INCREF (&PyTicketType);
Py_INCREF (&PyWicketType);
Py_INCREF (&PyAuthDataType);
PyModule_AddObject (m, PY_CSNAME1, (PyObject *)&PyAuthorityType);
PyModule_AddObject (m, PY_CSNAME2, (PyObject *)&PyTicketType);
PyModule_AddObject (m, PY_CSNAME3, (PyObject *)&PyWicketType);
PyModule_AddObject (m, PY_CSNAME4, (PyObject *)&PyAuthDataType);
}
}
/*
GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 2009 Free Software Foundation, Inc.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General
Public License along with this library; if not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301 USA
*/
#ifndef _MUCAPI_BODY_H
#define _MUCAPI_BODY_H
#include <mailutils/body.h>
typedef struct {
PyObject_HEAD;
mu_body_t body;
} PyBody;
extern PyBody * PyBody_NEW ();
#endif /* not _MUCAPI_BODY_H */
/*
GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 2009 Free Software Foundation, Inc.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General
Public License along with this library; if not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301 USA
*/
#include "c_api.h"
#include "body-private.h"
#include "stream-private.h"
#define PY_MODULE "body"
#define PY_CSNAME "BodyType"
static PyObject *
_repr (PyObject *self)
{
char buf[80];
sprintf (buf, "<" PY_MODULE "." PY_CSNAME " instance at %p>", self);
return PyString_FromString (buf);
}
static PyTypeObject PyBodyType = {
PyObject_HEAD_INIT(NULL)
0, /* ob_size */
PY_MODULE "." PY_CSNAME, /* tp_name */
sizeof (PyBody), /* tp_basicsize */
0, /* tp_itemsize */
(destructor)py_dealloc, /* tp_dealloc */
0, /* tp_print */
0, /* tp_getattr; __getattr__ */
0, /* tp_setattr; __setattr__ */
0, /* tp_compare; __cmp__ */
_repr, /* tp_repr; __repr__ */
0, /* tp_as_number */
0, /* tp_as_sequence */
0, /* tp_as_mapping */
0, /* tp_hash; __hash__ */
0, /* tp_call; __call__ */
_repr, /* tp_str; __str__ */
0, /* tp_getattro */
0, /* tp_setattro */
0, /* tp_as_buffer */
Py_TPFLAGS_DEFAULT, /* tp_flags */
"", /* tp_doc */
0, /* tp_traverse */
0, /* tp_clear */
0, /* tp_richcompare */
0, /* tp_weaklistoffset */
0, /* tp_iter */
0, /* tp_iternext */
0, /* tp_methods */
0, /* tp_members */
0, /* tp_getset */
0, /* tp_base */
0, /* tp_dict */
0, /* tp_descr_get */
0, /* tp_descr_set */
0, /* tp_dictoffset */
0, /* tp_init */
0, /* tp_alloc */
0, /* tp_new */
};
PyBody *
PyBody_NEW ()
{
return (PyBody *)PyObject_NEW (PyBody, &PyBodyType);
}
static PyObject *
api_body_size (PyObject *self, PyObject *args)
{
int status;
size_t size;
PyBody *py_body;
if (!PyArg_ParseTuple (args, "O!", &PyBodyType, &py_body))
return NULL;
status = mu_body_size (py_body->body, &size);
return status_object (status, PyInt_FromLong (size));
}
static PyObject *
api_body_lines (PyObject *self, PyObject *args)
{
int status;
size_t lines;
PyBody *py_body;
if (!PyArg_ParseTuple (args, "O!", &PyBodyType, &py_body))
return NULL;
status = mu_body_lines (py_body->body, &lines);
return status_object (status, PyInt_FromLong (lines));
}
static PyObject *
api_body_get_stream (PyObject *self, PyObject *args)
{
int status;
size_t lines;
PyBody *py_body;
PyStream *py_stm = PyStream_NEW ();
if (!PyArg_ParseTuple (args, "O!", &PyBodyType, &py_body))
return NULL;
Py_INCREF (py_stm);
status = mu_body_get_stream (py_body->body, &py_stm->stm);
return status_object (status, (PyObject *)py_stm);
}
static PyMethodDef methods[] = {
{ "size", (PyCFunction) api_body_size, METH_VARARGS,
"Retrieve BODY size." },
{ "lines", (PyCFunction) api_body_lines, METH_VARARGS,
"Retrieve BODY number of lines." },
{ "get_stream", (PyCFunction) api_body_get_stream, METH_VARARGS,
"" },
{ NULL, NULL, 0, NULL }
};
void
init_body ()
{
PyObject *m;
PyBodyType.tp_new = PyType_GenericNew;
if (PyType_Ready (&PyBodyType) < 0)
return;
if ((m = attach_module (PY_MODULE, methods)))
{
Py_INCREF (&PyBodyType);
PyModule_AddObject (m, PY_CSNAME, (PyObject *)&PyBodyType);
}
}
/*
GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 2009 Free Software Foundation, Inc.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General
Public License along with this library; if not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301 USA
*/
#include "c_api.h"
inline PyObject *
_ro (PyObject *obj)
{
Py_INCREF (obj);
return obj;
}
void
py_dealloc (PyObject *self)
{
self->ob_type->tp_free (self);
}
PyObject *
status_object (int status, PyObject *py_obj)
{
PyObject *py_ret = PyTuple_New (2);
PyTuple_SetItem (py_ret, 0, PyInt_FromLong (status));
PyTuple_SetItem (py_ret, 1, py_obj);
return _ro (py_ret);
}
static PyMethodDef nomethods[] = {
{ NULL, NULL }
};
static PyObject *package;
static PyObject *all;
PyObject *
attach_module (const char *name, PyMethodDef *methods)
{
PyObject *module, *m;
char ns[64] = PY_PACKAGE_NAME "." PY_ROOT_NAME ".";
strcat (ns, name);
if (!(module = PyImport_AddModule (ns)))
return NULL;
if (PyModule_AddObject (package, name, module))
return NULL;
Py_INCREF (module);
if (!(m = Py_InitModule (ns, methods)))
return NULL;
PyList_Append (all, PyString_FromString (name));
return m;
}
PyMODINIT_FUNC
initc_api (void)
{
package = Py_InitModule (PY_ROOT_NAME, nomethods);
if (!package)
return;
PyModule_AddStringConstant (package, "__version__", PY_PACKAGE_VERSION);
if (!PyModule_AddObject (package, "__all__", _ro (PyList_New (0))))
{
all = PyObject_GetAttrString (package, "__all__");
if (!all || !PyList_Check (all))
return;
}
init_error ();
init_address ();
init_attribute ();
init_auth ();
init_body ();
init_debug ();
init_envelope ();
init_header ();
init_filter ();
init_folder ();
init_mailer ();
init_mailbox ();
init_mailcap ();
init_message ();
init_mime ();
init_registrar ();
init_stream ();
init_url ();
init_util ();
}
/*
GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 2009 Free Software Foundation, Inc.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General
Public License along with this library; if not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301 USA
*/
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <Python.h>
#define PY_PACKAGE_NAME "mailutils"
#define PY_ROOT_NAME "c_api"
#define PY_PACKAGE_VERSION PACKAGE_VERSION
extern inline PyObject * _ro (PyObject *obj);
extern void py_dealloc (PyObject *self);
extern PyObject * status_object (int status, PyObject *py_obj);
extern PyObject * attach_module (const char *name, PyMethodDef *methods);
extern void init_error ();
extern void init_address ();
extern void init_attribute ();
extern void init_auth ();
extern void init_body ();
extern void init_debug ();
extern void init_envelope ();
extern void init_header ();
extern void init_filter ();
extern void init_folder ();
extern void init_mailer ();
extern void init_mailbox ();
extern void init_mailcap ();
extern void init_message ();
extern void init_mime ();
extern void init_registrar ();
extern void init_stream ();
extern void init_url ();
extern void init_util ();
/*
GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 2009 Free Software Foundation, Inc.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General
Public License along with this library; if not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301 USA
*/
#ifndef _MUCAPI_DEBUG_H
#define _MUCAPI_DEBUG_H
#include <mailutils/debug.h>
typedef struct {
PyObject_HEAD;
mu_debug_t dbg;
} PyDebug;
extern PyDebug * PyDebug_NEW ();
#endif /* not _MUCAPI_DEBUG_H */
/*
GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 2009 Free Software Foundation, Inc.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General
Public License along with this library; if not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301 USA
*/
#include "c_api.h"
#include "debug-private.h"
#define PY_MODULE "debug"
#define PY_CSNAME "DebugType"
static PyObject *
_repr (PyObject *self)
{
char buf[80];
sprintf (buf, "<" PY_MODULE "." PY_CSNAME " instance at %p>", self);
return PyString_FromString (buf);
}
static PyTypeObject PyDebugType = {
PyObject_HEAD_INIT(NULL)
0, /* ob_size */
PY_MODULE "." PY_CSNAME, /* tp_name */
sizeof (PyDebug), /* tp_basicsize */
0, /* tp_itemsize */
(destructor)py_dealloc, /* tp_dealloc */
0, /* tp_print */
0, /* tp_getattr; __getattr__ */
0, /* tp_setattr; __setattr__ */
0, /* tp_compare; __cmp__ */
_repr, /* tp_repr; __repr__ */
0, /* tp_as_number */
0, /* tp_as_sequence */
0, /* tp_as_mapping */
0, /* tp_hash; __hash__ */
0, /* tp_call; __call__ */
_repr, /* tp_str; __str__ */
0, /* tp_getattro */
0, /* tp_setattro */
0, /* tp_as_buffer */
Py_TPFLAGS_DEFAULT, /* tp_flags */
"", /* tp_doc */
0, /* tp_traverse */
0, /* tp_clear */
0, /* tp_richcompare */
0, /* tp_weaklistoffset */
0, /* tp_iter */
0, /* tp_iternext */
0, /* tp_methods */
0, /* tp_members */
0, /* tp_getset */
0, /* tp_base */
0, /* tp_dict */
0, /* tp_descr_get */
0, /* tp_descr_set */
0, /* tp_dictoffset */
0, /* tp_init */
0, /* tp_alloc */
0, /* tp_new */
};
PyDebug *
PyDebug_NEW ()
{
return (PyDebug *)PyObject_NEW (PyDebug, &PyDebugType);
}
static PyObject *
api_debug_set_level (PyObject *self, PyObject *args)
{
int status, level;
PyDebug *py_dbg;
if (!PyArg_ParseTuple (args, "O!i", &PyDebugType, &py_dbg, &level))
return NULL;
status = mu_debug_set_level (py_dbg->dbg,
MU_DEBUG_LEVEL_UPTO (level));
return _ro (PyInt_FromLong (status));
}
static PyMethodDef methods[] = {
{ "set_level", (PyCFunction) api_debug_set_level, METH_VARARGS,
"" },
{ NULL, NULL, 0, NULL }
};
void
init_debug ()
{
PyObject *m;
PyDebugType.tp_new = PyType_GenericNew;
if (PyType_Ready (&PyDebugType) < 0)
return;
if ((m = attach_module (PY_MODULE, methods)))
{
Py_INCREF (&PyDebugType);
PyModule_AddObject (m, PY_CSNAME, (PyObject *)&PyDebugType);
}
}
/*
GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 2009 Free Software Foundation, Inc.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General
Public License along with this library; if not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301 USA
*/
#ifndef _MUCAPI_ENVELOPE_H
#define _MUCAPI_ENVELOPE_H
#include <mailutils/envelope.h>
typedef struct {
PyObject_HEAD;
mu_envelope_t env;
} PyEnvelope;
extern PyEnvelope * PyEnvelope_NEW ();
#endif /* not _MUCAPI_ENVELOPE_H */
/*
GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 2009 Free Software Foundation, Inc.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General
Public License along with this library; if not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301 USA
*/
#include "c_api.h"
#include "envelope-private.h"
#define PY_MODULE "envelope"
#define PY_CSNAME "EnvelopeType"
static PyObject *
_repr (PyObject *self)
{
char buf[80];
sprintf (buf, "<" PY_MODULE "." PY_CSNAME " instance at %p>", self);
return PyString_FromString (buf);
}
static PyTypeObject PyEnvelopeType = {
PyObject_HEAD_INIT(NULL)
0, /* ob_size */
PY_MODULE "." PY_CSNAME, /* tp_name */
sizeof (PyEnvelope), /* tp_basicsize */
0, /* tp_itemsize */
(destructor)py_dealloc, /* tp_dealloc */
0, /* tp_print */
0, /* tp_getattr; __getattr__ */
0, /* tp_setattr; __setattr__ */
0, /* tp_compare; __cmp__ */
_repr, /* tp_repr; __repr__ */
0, /* tp_as_number */
0, /* tp_as_sequence */
0, /* tp_as_mapping */
0, /* tp_hash; __hash__ */
0, /* tp_call; __call__ */
_repr, /* tp_str; __str__ */
0, /* tp_getattro */
0, /* tp_setattro */
0, /* tp_as_buffer */
Py_TPFLAGS_DEFAULT, /* tp_flags */
"", /* tp_doc */
0, /* tp_traverse */
0, /* tp_clear */
0, /* tp_richcompare */
0, /* tp_weaklistoffset */
0, /* tp_iter */
0, /* tp_iternext */
0, /* tp_methods */
0, /* tp_members */
0, /* tp_getset */
0, /* tp_base */
0, /* tp_dict */
0, /* tp_descr_get */
0, /* tp_descr_set */
0, /* tp_dictoffset */
0, /* tp_init */
0, /* tp_alloc */
0, /* tp_new */
};
PyEnvelope *
PyEnvelope_NEW ()
{
return (PyEnvelope *)PyObject_NEW (PyEnvelope, &PyEnvelopeType);
}
static PyObject *
api_envelope_create (PyObject *self, PyObject *args)
{
int status;
PyEnvelope *py_env;
if (!PyArg_ParseTuple (args, "O!", &PyEnvelopeType, &py_env))
return NULL;
status = mu_envelope_create (&py_env->env, NULL);
return _ro (PyInt_FromLong (status));
}
static PyObject *
api_envelope_destroy (PyObject *self, PyObject *args)
{
PyEnvelope *py_env;
if (!PyArg_ParseTuple (args, "O!", &PyEnvelopeType, &py_env))
return NULL;
mu_envelope_destroy (&py_env->env, NULL);
return _ro (Py_None);
}
static PyObject *
api_envelope_get_sender (PyObject *self, PyObject *args)
{
int status;
const char *sender = NULL;
PyEnvelope *py_env;
if (!PyArg_ParseTuple (args, "O!", &PyEnvelopeType, &py_env))
return NULL;
status = mu_envelope_sget_sender (py_env->env, &sender);
return status_object (status, PyString_FromString (sender ? sender : ""));
}
static PyObject *
api_envelope_get_date (PyObject *self, PyObject *args)
{
int status;
const char *date = NULL;
PyEnvelope *py_env;
if (!PyArg_ParseTuple (args, "O!", &PyEnvelopeType, &py_env))
return NULL;
status = mu_envelope_sget_date (py_env->env, &date);
return status_object (status, PyString_FromString (date ? date : ""));
}
static PyMethodDef methods[] = {
{ "create", (PyCFunction) api_envelope_create, METH_VARARGS,
"" },
{ "destroy", (PyCFunction) api_envelope_destroy, METH_VARARGS,
"" },
{ "get_sender", (PyCFunction) api_envelope_get_sender, METH_VARARGS,
"Get the address that this message was reportedly received from." },
{ "get_date", (PyCFunction) api_envelope_get_date, METH_VARARGS,
"Get the date that the message was delivered to the mailbox." },
{ NULL, NULL, 0, NULL }
};
void
init_envelope ()
{
PyObject *m;
PyEnvelopeType.tp_new = PyType_GenericNew;
if (PyType_Ready (&PyEnvelopeType) < 0)
return;
if ((m = attach_module (PY_MODULE, methods)))
{
Py_INCREF (&PyEnvelopeType);
PyModule_AddObject (m, PY_CSNAME, (PyObject *)&PyEnvelopeType);
}
}
/*
GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 2009 Free Software Foundation, Inc.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General
Public License along with this library; if not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301 USA
*/
#include "c_api.h"
#define PY_MODULE "error"
static PyObject *
api_strerror (PyObject *self, PyObject *args)
{
int status;
char *str = NULL;
if (!PyArg_ParseTuple (args, "i", &status))
return NULL;
str = (char *)mu_strerror (status);
return _ro (PyString_FromString (str));
}
static PyMethodDef methods[] = {
{ "strerror", (PyCFunction) api_strerror, METH_VARARGS,
"Return the error message corresponding to ERR, "
"which must be an integer value." },
{ NULL, NULL, 0, NULL }
};
void
init_error ()
{
attach_module (PY_MODULE, methods);
}
/*
GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 2009 Free Software Foundation, Inc.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General
Public License along with this library; if not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301 USA
*/
#include "c_api.h"
#include "stream-private.h"
#include <mailutils/filter.h>
#define PY_MODULE "filter"
static PyObject *
api_filter_create (PyObject *self, PyObject *args)
{
int status, mode, flags;
char *code = NULL;
PyStream *py_stm, *py_transport;
if (!PyArg_ParseTuple (args, "OOsii",
&py_stm, &py_transport,
&code, &mode, &flags))
return NULL;
if (!PyStream_Check ((PyObject *)py_stm) &&
!PyStream_Check ((PyObject *)py_transport))
{
PyErr_SetString (PyExc_TypeError, "");
return NULL;
}
status = mu_filter_create (&py_stm->stm, py_transport->stm,
code, mode, flags);
return _ro (PyInt_FromLong (status));
}
static PyObject *
api_filter_iconv_create (PyObject *self, PyObject *args)
{
int status, flags;
char *fromcode = NULL;
char *tocode = NULL;
PyStream *py_stm, *py_transport;
if (!PyArg_ParseTuple (args, "OOssi",
&py_stm, &py_transport,
&fromcode, &tocode, &flags))
return NULL;
if (!PyStream_Check ((PyObject *)py_stm) &&
!PyStream_Check ((PyObject *)py_transport))
{
PyErr_SetString (PyExc_TypeError, "");
return NULL;
}
status = mu_filter_iconv_create (&py_stm->stm, py_transport->stm,
fromcode, tocode, flags,
mu_fallback_none);
return _ro (PyInt_FromLong (status));
}
static PyMethodDef methods[] = {
{ "create", (PyCFunction) api_filter_create, METH_VARARGS,
"" },
{ "iconv_create", (PyCFunction) api_filter_iconv_create, METH_VARARGS,
"" },
{ NULL, NULL, 0, NULL }
};
void
init_filter ()
{
attach_module (PY_MODULE, methods);
}
/*
GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 2009 Free Software Foundation, Inc.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General
Public License along with this library; if not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301 USA
*/
#ifndef _MUCAPI_FOLDER_H
#define _MUCAPI_FOLDER_H
#include <mailutils/folder.h>
typedef struct {
PyObject_HEAD;
mu_folder_t folder;
} PyFolder;
extern PyFolder * PyFolder_NEW ();
#endif /* not _MUCAPI_FOLDER_H */
/*
GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 2009 Free Software Foundation, Inc.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General
Public License along with this library; if not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301 USA
*/
#include "c_api.h"
#include "folder-private.h"
#include "stream-private.h"
#include "auth-private.h"
#include "url-private.h"
#define PY_MODULE "folder"
#define PY_CSNAME "FolderType"
static PyObject *
_repr (PyObject *self)
{
char buf[80];
sprintf (buf, "<" PY_MODULE "." PY_CSNAME " instance at %p>", self);
return PyString_FromString (buf);
}
static PyTypeObject PyFolderType = {
PyObject_HEAD_INIT(NULL)
0, /* ob_size */
PY_MODULE "." PY_CSNAME, /* tp_name */
sizeof (PyFolder), /* tp_basicsize */
0, /* tp_itemsize */
(destructor)py_dealloc, /* tp_dealloc */
0, /* tp_print */
0, /* tp_getattr; __getattr__ */
0, /* tp_setattr; __setattr__ */
0, /* tp_compare; __cmp__ */
_repr, /* tp_repr; __repr__ */
0, /* tp_as_number */
0, /* tp_as_sequence */
0, /* tp_as_mapping */
0, /* tp_hash; __hash__ */
0, /* tp_call; __call__ */
_repr, /* tp_str; __str__ */
0, /* tp_getattro */
0, /* tp_setattro */
0, /* tp_as_buffer */
Py_TPFLAGS_DEFAULT, /* tp_flags */
"", /* tp_doc */
0, /* tp_traverse */
0, /* tp_clear */
0, /* tp_richcompare */
0, /* tp_weaklistoffset */
0, /* tp_iter */
0, /* tp_iternext */
0, /* tp_methods */
0, /* tp_members */
0, /* tp_getset */
0, /* tp_base */
0, /* tp_dict */
0, /* tp_descr_get */
0, /* tp_descr_set */
0, /* tp_dictoffset */
0, /* tp_init */
0, /* tp_alloc */
0, /* tp_new */
};
PyFolder *
PyFolder_NEW ()
{
return (PyFolder *)PyObject_NEW (PyFolder, &PyFolderType);
}
static PyObject *
api_folder_create (PyObject *self, PyObject *args)
{
int status;
char *name;
PyFolder *py_folder;
if (!PyArg_ParseTuple (args, "O!s", &PyFolderType, &py_folder, &name))
return NULL;
status = mu_folder_create (&py_folder->folder, name);
return _ro (PyInt_FromLong (status));
}
static PyObject *
api_folder_destroy (PyObject *self, PyObject *args)
{
PyFolder *py_folder;
if (!PyArg_ParseTuple (args, "O!", &PyFolderType, &py_folder))
return NULL;
mu_folder_destroy (&py_folder->folder);
return _ro (Py_None);
}
static PyObject *
api_folder_open (PyObject *self, PyObject *args)
{
int status;
PyFolder *py_folder;
if (!PyArg_ParseTuple (args, "O!", &PyFolderType, &py_folder))
return NULL;
status = mu_folder_open (py_folder->folder, MU_STREAM_READ);
return _ro (PyInt_FromLong (status));
}
static PyObject *
api_folder_close (PyObject *self, PyObject *args)
{
int status;
PyFolder *py_folder;
if (!PyArg_ParseTuple (args, "O!", &PyFolderType, &py_folder))
return NULL;
status = mu_folder_close (py_folder->folder);
return _ro (PyInt_FromLong (status));
}
static PyObject *
api_folder_get_stream (PyObject *self, PyObject *args)
{
int status;
PyFolder *py_folder;
PyStream *py_stm = PyStream_NEW ();
if (!PyArg_ParseTuple (args, "O!", &PyFolderType, &py_folder))
return NULL;
Py_INCREF (py_stm);
status = mu_folder_get_stream (py_folder->folder, &py_stm->stm);
return status_object (status, (PyObject *)py_stm);
}
static PyObject *
api_folder_set_stream (PyObject *self, PyObject *args)
{
int status;
PyFolder *py_folder;
PyStream *py_stm;
if (!PyArg_ParseTuple (args, "O!O", &PyFolderType, &py_folder, &py_stm))
return NULL;
if (!PyStream_Check ((PyObject *)py_stm))
{
PyErr_SetString (PyExc_TypeError, "");
return NULL;
}
status = mu_folder_set_stream (py_folder->folder, py_stm->stm);
return _ro (PyInt_FromLong (status));
}
static PyObject *
api_folder_get_authority (PyObject *self, PyObject *args)
{
int status;
PyFolder *py_folder;
PyAuthority *py_auth = PyAuthority_NEW ();
if (!PyArg_ParseTuple (args, "O!", &PyFolderType, &py_folder))
return NULL;
Py_INCREF (py_auth);
status = mu_folder_get_authority (py_folder->folder, &py_auth->auth);
return status_object (status, (PyObject *)py_auth);
}
static PyObject *
api_folder_set_authority (PyObject *self, PyObject *args)
{
int status;
PyFolder *py_folder;
PyAuthority *py_auth;
if (!PyArg_ParseTuple (args, "O!O", &PyFolderType, &py_folder, &py_auth))
return NULL;
if (!PyAuthority_Check ((PyObject *)py_auth))
{
PyErr_SetString (PyExc_TypeError, "");
return NULL;
}
status = mu_folder_set_authority (py_folder->folder, py_auth->auth);
return _ro (PyInt_FromLong (status));
}
static PyObject *
api_folder_get_url (PyObject *self, PyObject *args)
{
int status;
PyFolder *py_folder;
PyUrl *py_url = PyUrl_NEW ();
if (!PyArg_ParseTuple (args, "O!", &PyFolderType, &py_folder))
return NULL;
Py_INCREF (py_url);
status = mu_folder_get_url (py_folder->folder, &py_url->url);
return status_object (status, (PyObject *)py_url);
}
static int
folderdata_extractor (void *data, PyObject **dst)
{
struct mu_list_response *resp = (struct mu_list_response *)data;
char separator[4];
char *attr = (resp->type & MU_FOLDER_ATTRIBUTE_DIRECTORY) ? "d" :
(resp->type & MU_FOLDER_ATTRIBUTE_FILE) ? "f" : "-";
snprintf (separator, sizeof (separator), "%c", resp->separator);
*dst = PyTuple_New (4);
PyTuple_SetItem (*dst, 0, PyString_FromString (attr));
PyTuple_SetItem (*dst, 1, PyInt_FromLong (resp->level));
PyTuple_SetItem (*dst, 2, PyString_FromString (separator));
PyTuple_SetItem (*dst, 3, PyString_FromString (resp->name));
return 0;
}
static PyObject *
api_folder_list (PyObject *self, PyObject *args)
{
int status = 0;
size_t max_level = 0;
char *dirname, *pattern;
PyFolder *py_folder;
PyObject *py_list;
mu_list_t c_list = NULL;
if (!PyArg_ParseTuple (args, "O!zs|i", &PyFolderType, &py_folder,
&dirname, &pattern, &max_level))
return NULL;
status = mu_folder_list (py_folder->folder, dirname, pattern, max_level,
&c_list);
if (c_list)
py_list = mulist_to_pylist (c_list, folderdata_extractor);
else
py_list = PyTuple_New (0);
return status_object (status, py_list);
}
static PyMethodDef methods[] = {
{ "create", (PyCFunction) api_folder_create, METH_VARARGS,
"" },
{ "destroy", (PyCFunction) api_folder_destroy, METH_VARARGS,
"" },
{ "open", (PyCFunction) api_folder_open, METH_VARARGS,
"" },
{ "close", (PyCFunction) api_folder_close, METH_VARARGS,
"" },
{ "get_stream", (PyCFunction) api_folder_get_stream, METH_VARARGS,
"" },
{ "set_stream", (PyCFunction) api_folder_set_stream, METH_VARARGS,
"" },
{ "get_authority", (PyCFunction) api_folder_get_authority, METH_VARARGS,
"" },
{ "set_authority", (PyCFunction) api_folder_set_authority, METH_VARARGS,
"" },
{ "get_url", (PyCFunction) api_folder_get_url, METH_VARARGS,
"" },
{ "list", (PyCFunction) api_folder_list, METH_VARARGS,
"" },
{ NULL, NULL, 0, NULL }
};
void
init_folder ()
{
PyObject *m;
PyFolderType.tp_new = PyType_GenericNew;
if (PyType_Ready (&PyFolderType) < 0)
return;
if ((m = attach_module (PY_MODULE, methods)))
{
Py_INCREF (&PyFolderType);
PyModule_AddObject (m, PY_CSNAME, (PyObject *)&PyFolderType);
}
}
/*
GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 2009 Free Software Foundation, Inc.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General
Public License along with this library; if not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301 USA
*/
#ifndef _MUCAPI_HEADER_H
#define _MUCAPI_HEADER_H
#include <mailutils/header.h>
typedef struct {
PyObject_HEAD;
mu_header_t hdr;
} PyHeader;
extern PyHeader * PyHeader_NEW ();
#endif /* not _MUCAPI_HEADER_H */
/*
GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 2009 Free Software Foundation, Inc.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General
Public License along with this library; if not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301 USA
*/
#include "c_api.h"
#include "header-private.h"
#define PY_MODULE "header"
#define PY_CSNAME "HeaderType"
static PyObject *
_repr (PyObject *self)
{
char buf[80];
sprintf (buf, "<" PY_MODULE "." PY_CSNAME " instance at %p>", self);
return PyString_FromString (buf);
}
static PyTypeObject PyHeaderType = {
PyObject_HEAD_INIT(NULL)
0, /* ob_size */
PY_MODULE "." PY_CSNAME, /* tp_name */
sizeof (PyHeader), /* tp_basicsize */
0, /* tp_itemsize */
(destructor)py_dealloc, /* tp_dealloc */
0, /* tp_print */
0, /* tp_getattr; __getattr__ */
0, /* tp_setattr; __setattr__ */
0, /* tp_compare; __cmp__ */
_repr, /* tp_repr; __repr__ */
0, /* tp_as_number */
0, /* tp_as_sequence */
0, /* tp_as_mapping */
0, /* tp_hash; __hash__ */
0, /* tp_call; __call__ */
_repr, /* tp_str; __str__ */
0, /* tp_getattro */
0, /* tp_setattro */
0, /* tp_as_buffer */
Py_TPFLAGS_DEFAULT, /* tp_flags */
"", /* tp_doc */
0, /* tp_traverse */
0, /* tp_clear */
0, /* tp_richcompare */
0, /* tp_weaklistoffset */
0, /* tp_iter */
0, /* tp_iternext */
0, /* tp_methods */
0, /* tp_members */
0, /* tp_getset */
0, /* tp_base */
0, /* tp_dict */
0, /* tp_descr_get */
0, /* tp_descr_set */
0, /* tp_dictoffset */
0, /* tp_init */
0, /* tp_alloc */
0, /* tp_new */
};
PyHeader *
PyHeader_NEW ()
{
return (PyHeader *)PyObject_NEW (PyHeader, &PyHeaderType);
}
static PyObject *
api_header_size (PyObject *self, PyObject *args)
{
int status;
size_t size;
PyHeader *py_hdr;
if (!PyArg_ParseTuple (args, "O!", &PyHeaderType, &py_hdr))
return NULL;
status = mu_header_size (py_hdr->hdr, &size);
return status_object (status, PyInt_FromLong (size));
}
static PyObject *
api_header_lines (PyObject *self, PyObject *args)
{
int status;
size_t lines;
PyHeader *py_hdr;
if (!PyArg_ParseTuple (args, "O!", &PyHeaderType, &py_hdr))
return NULL;
status = mu_header_lines (py_hdr->hdr, &lines);
return status_object (status, PyInt_FromLong (lines));
}
static PyObject *
api_header_get_value (PyObject *self, PyObject *args)
{
int status;
char *name;
const char *value = NULL;
PyHeader *py_hdr;
if (!PyArg_ParseTuple (args, "O!s", &PyHeaderType, &py_hdr, &name))
return NULL;
status = mu_header_sget_value (py_hdr->hdr, name, &value);
return status_object (status, PyString_FromString (value ? value : ""));
}
static PyObject *
api_header_set_value (PyObject *self, PyObject *args)
{
int status, replace = 1;
char *name, *value;
PyHeader *py_hdr;
if (!PyArg_ParseTuple (args, "O!ss|i", &PyHeaderType, &py_hdr, &name,
&value, &replace))
return NULL;
status = mu_header_set_value (py_hdr->hdr, name, value, replace);
return _ro (PyInt_FromLong (status));
}
static PyObject *
api_header_get_field_count (PyObject *self, PyObject *args)
{
int status;
size_t count = 0;
PyHeader *py_hdr;
if (!PyArg_ParseTuple (args, "O!", &PyHeaderType, &py_hdr))
return NULL;
status = mu_header_get_field_count (py_hdr->hdr, &count);
return status_object (status, PyInt_FromLong (count));
}
static PyObject *
api_header_get_field_name (PyObject *self, PyObject *args)
{
int status;
size_t idx;
const char *name = NULL;
PyHeader *py_hdr;
if (!PyArg_ParseTuple (args, "O!i", &PyHeaderType, &py_hdr, &idx))
return NULL;
status = mu_header_sget_field_name (py_hdr->hdr, idx, &name);
return status_object (status, PyString_FromString (name ? name : ""));
}
static PyObject *
api_header_get_field_value (PyObject *self, PyObject *args)
{
int status;
size_t idx;
const char *value = NULL;
PyHeader *py_hdr;
if (!PyArg_ParseTuple (args, "O!i", &PyHeaderType, &py_hdr, &idx))
return NULL;
status = mu_header_sget_field_value (py_hdr->hdr, idx, &value);
return status_object (status, PyString_FromString (value ? value : ""));
}
static PyMethodDef methods[] = {
{ "size", (PyCFunction) api_header_size, METH_VARARGS,
"Retrieve HEADER size." },
{ "lines", (PyCFunction) api_header_lines, METH_VARARGS,
"Retrieve HEADER number of lines." },
{ "get_value", (PyCFunction) api_header_get_value, METH_VARARGS,
"Retrieve header field value." },
{ "set_value", (PyCFunction) api_header_set_value, METH_VARARGS,
"Set header field value." },
{ "get_field_count", (PyCFunction) api_header_get_field_count, METH_VARARGS,
"Retrieve the number of header fields." },
{ "get_field_name", (PyCFunction) api_header_get_field_name, METH_VARARGS,
"Retrieve header field name by field index IDX." },
{ "get_field_value", (PyCFunction) api_header_get_field_value, METH_VARARGS,
"Retrieve header field value by field index IDX." },
{ NULL, NULL, 0, NULL }
};
void
init_header ()
{
PyObject *m;
PyHeaderType.tp_new = PyType_GenericNew;
if (PyType_Ready (&PyHeaderType) < 0)
return;
if ((m = attach_module (PY_MODULE, methods)))
{
Py_INCREF (&PyHeaderType);
PyModule_AddObject (m, PY_CSNAME, (PyObject *)&PyHeaderType);
}
}
/*
GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 2009 Free Software Foundation, Inc.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General
Public License along with this library; if not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301 USA
*/
#ifndef _MUCAPI_LIST_H
#define _MUCAPI_LIST_H
#include <mailutils/list.h>
typedef int (*mulist_extractor_fp) (void *data, PyObject **dst);
extern PyObject * mulist_to_pylist (mu_list_t list, mulist_extractor_fp fnc);
#endif /* not _MUCAPI_LIST_H */
/*
GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 2009 Free Software Foundation, Inc.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General
Public License along with this library; if not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301 USA
*/
#include "c_api.h"
#include "list-private.h"
PyObject *
mulist_to_pylist (mu_list_t list, mulist_extractor_fp extractor)
{
int status, i;
size_t list_count;
PyObject *py_list;
if (!list)
return NULL;
status = mu_list_count (list, &list_count);
if (status)
return NULL;
py_list = PyList_New (list_count);
if (!py_list)
return NULL;
for (i = 0; i < list_count; i++)
{
void *item;
PyObject *py_item = NULL;
status = mu_list_get (list, i, &item);
if (!status)
{
status = (*extractor)(item, &py_item);
if (!status && py_item)
PyList_SetItem (py_list, i, py_item);
}
}
return py_list;
}
/*
GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 2009 Free Software Foundation, Inc.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General
Public License along with this library; if not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301 USA
*/
#ifndef _MUCAPI_MAILBOX_H
#define _MUCAPI_MAILBOX_H
#include <mailutils/mailbox.h>
typedef struct {
PyObject_HEAD;
mu_mailbox_t mbox;
} PyMailbox;
#endif /* not _MUCAPI_MAILBOX_H */
/*
GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 2009 Free Software Foundation, Inc.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General
Public License along with this library; if not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301 USA
*/
#include "c_api.h"
#include "mailbox-private.h"
#include "message-private.h"
#include "folder-private.h"
#include "url-private.h"
#include "debug-private.h"
#define PY_MODULE "mailbox"
#define PY_CSNAME "MailboxType"
static PyObject *
_repr (PyObject *self)
{
char buf[80];
sprintf (buf, "<" PY_MODULE "." PY_CSNAME " instance at %p>", self);
return PyString_FromString (buf);
}
static PyTypeObject PyMailboxType = {
PyObject_HEAD_INIT(NULL)
0, /* ob_size */
PY_MODULE "." PY_CSNAME, /* tp_name */
sizeof (PyMailbox), /* tp_basicsize */
0, /* tp_itemsize */
(destructor)py_dealloc, /* tp_dealloc */
0, /* tp_print */
0, /* tp_getattr; __getattr__ */
0, /* tp_setattr; __setattr__ */
0, /* tp_compare; __cmp__ */
_repr, /* tp_repr; __repr__ */
0, /* tp_as_number */
0, /* tp_as_sequence */
0, /* tp_as_mapping */
0, /* tp_hash; __hash__ */
0, /* tp_call; __call__ */
_repr, /* tp_str; __str__ */
0, /* tp_getattro */
0, /* tp_setattro */
0, /* tp_as_buffer */
Py_TPFLAGS_DEFAULT, /* tp_flags */
"", /* tp_doc */
0, /* tp_traverse */
0, /* tp_clear */
0, /* tp_richcompare */
0, /* tp_weaklistoffset */
0, /* tp_iter */
0, /* tp_iternext */
0, /* tp_methods */
0, /* tp_members */
0, /* tp_getset */
0, /* tp_base */
0, /* tp_dict */
0, /* tp_descr_get */
0, /* tp_descr_set */
0, /* tp_dictoffset */
0, /* tp_init */
0, /* tp_alloc */
0, /* tp_new */
};
static PyObject *
api_mailbox_create (PyObject *self, PyObject *args)
{
int status;
char *name;
PyMailbox *py_mbox;
if (!PyArg_ParseTuple (args, "O!s", &PyMailboxType, &py_mbox, &name))
return NULL;
status = mu_mailbox_create (&py_mbox->mbox, name);
return _ro (PyInt_FromLong (status));
}
static PyObject *
api_mailbox_create_default (PyObject *self, PyObject *args)
{
int status;
char *name;
PyMailbox *py_mbox;
if (!PyArg_ParseTuple (args, "O!s", &PyMailboxType, &py_mbox, &name))
return NULL;
status = mu_mailbox_create_default (&py_mbox->mbox, name);
return _ro (PyInt_FromLong (status));
}
static PyObject *
api_mailbox_destroy (PyObject *self, PyObject *args)
{
PyMailbox *py_mbox;
if (!PyArg_ParseTuple (args, "O!", &PyMailboxType, &py_mbox))
return NULL;
mu_mailbox_destroy (&py_mbox->mbox);
return _ro (Py_None);
}
static PyObject *
api_mailbox_open (PyObject *self, PyObject *args)
{
int status;
int flag;
PyMailbox *py_mbox;
if (!PyArg_ParseTuple (args, "O!i", &PyMailboxType, &py_mbox, &flag))
return NULL;
status = mu_mailbox_open (py_mbox->mbox, flag);
return _ro (PyInt_FromLong (status));
}
static PyObject *
api_mailbox_close (PyObject *self, PyObject *args)
{
int status;
PyMailbox *py_mbox;
if (!PyArg_ParseTuple (args, "O!", &PyMailboxType, &py_mbox))
return NULL;
status = mu_mailbox_close (py_mbox->mbox);
return _ro (PyInt_FromLong (status));
}
static PyObject *
api_mailbox_flush (PyObject *self, PyObject *args)
{
int status, expunge = 0;
PyMailbox *py_mbox;
if (!PyArg_ParseTuple (args, "O!i", &PyMailboxType, &py_mbox, &expunge))
return NULL;
status = mu_mailbox_flush (py_mbox->mbox, expunge);
return _ro (PyInt_FromLong (status));
}
static PyObject *
api_mailbox_messages_count (PyObject *self, PyObject *args)
{
int status;
size_t total = 0;
PyMailbox *py_mbox;
if (!PyArg_ParseTuple (args, "O!", &PyMailboxType, &py_mbox))
return NULL;
status = mu_mailbox_messages_count (py_mbox->mbox, &total);
return status_object (status, PyInt_FromLong (total));
}
static PyObject *
api_mailbox_messages_recent (PyObject *self, PyObject *args)
{
int status;
size_t recent = 0;
PyMailbox *py_mbox;
if (!PyArg_ParseTuple (args, "O!", &PyMailboxType, &py_mbox))
return NULL;
status = mu_mailbox_messages_recent (py_mbox->mbox, &recent);
return status_object (status, PyInt_FromLong (recent));
}
static PyObject *
api_mailbox_message_unseen (PyObject *self, PyObject *args)
{
int status;
size_t unseen = 0;
PyMailbox *py_mbox;
if (!PyArg_ParseTuple (args, "O!", &PyMailboxType, &py_mbox))
return NULL;
status = mu_mailbox_message_unseen (py_mbox->mbox, &unseen);
return status_object (status, PyInt_FromLong (unseen));
}
static PyObject *
api_mailbox_get_message (PyObject *self, PyObject *args)
{
int status;
size_t msgno;
PyMailbox *py_mbox;
PyMessage *py_msg = PyMessage_NEW ();
if (!PyArg_ParseTuple (args, "O!i", &PyMailboxType, &py_mbox, &msgno))
return NULL;
status = mu_mailbox_get_message (py_mbox->mbox, msgno, &py_msg->msg);
Py_INCREF (py_msg);
return status_object (status, (PyObject *)py_msg);
}
static PyObject *
api_mailbox_append_message (PyObject *self, PyObject *args)
{
int status;
PyMailbox *py_mbox;
PyMessage *py_msg;
if (!PyArg_ParseTuple (args, "O!O", &PyMailboxType, &py_mbox, &py_msg))
return NULL;
if (!PyMessage_Check ((PyObject *)py_msg))
{
PyErr_SetString (PyExc_TypeError, "");
return NULL;
}
status = mu_mailbox_append_message (py_mbox->mbox, py_msg->msg);
return status_object (status, PyInt_FromLong (status));
}
static PyObject *
api_mailbox_expunge (PyObject *self, PyObject *args)
{
int status;
PyMailbox *py_mbox;
if (!PyArg_ParseTuple (args, "O!", &PyMailboxType, &py_mbox))
return NULL;
status = mu_mailbox_expunge (py_mbox->mbox);
return _ro (PyInt_FromLong (status));
}
static PyObject *
api_mailbox_sync (PyObject *self, PyObject *args)
{
int status;
PyMailbox *py_mbox;
if (!PyArg_ParseTuple (args, "O!", &PyMailboxType, &py_mbox))
return NULL;
status = mu_mailbox_sync (py_mbox->mbox);
return _ro (PyInt_FromLong (status));
}
static PyObject *
api_mailbox_lock (PyObject *self, PyObject *args)
{
int status;
PyMailbox *py_mbox;
if (!PyArg_ParseTuple (args, "O!", &PyMailboxType, &py_mbox))
return NULL;
status = mu_mailbox_lock (py_mbox->mbox);
return _ro (PyInt_FromLong (status));
}
static PyObject *
api_mailbox_unlock (PyObject *self, PyObject *args)
{
int status;
PyMailbox *py_mbox;
if (!PyArg_ParseTuple (args, "O!", &PyMailboxType, &py_mbox))
return NULL;
status = mu_mailbox_unlock (py_mbox->mbox);
return _ro (PyInt_FromLong (status));
}
static PyObject *
api_mailbox_get_size (PyObject *self, PyObject *args)
{
int status;
mu_off_t size = 0;
PyMailbox *py_mbox;
if (!PyArg_ParseTuple (args, "O!", &PyMailboxType, &py_mbox))
return NULL;
status = mu_mailbox_get_size (py_mbox->mbox, &size);
return status_object (status, PyInt_FromLong (size));
}
static PyObject *
api_mailbox_get_debug (PyObject *self, PyObject *args)
{
int status;
PyMailbox *py_mbox;
PyDebug *py_dbg = PyDebug_NEW ();
if (!PyArg_ParseTuple (args, "O!", &PyMailboxType, &py_mbox))
return NULL;
status = mu_mailbox_get_debug (py_mbox->mbox, &py_dbg->dbg);
Py_INCREF (py_dbg);
return status_object (status, (PyObject *)py_dbg);
}
static PyObject *
api_mailbox_get_folder (PyObject *self, PyObject *args)
{
int status;
PyMailbox *py_mbox;
PyFolder *py_folder = PyFolder_NEW ();
if (!PyArg_ParseTuple (args, "O!", &PyMailboxType, &py_mbox))
return NULL;
py_folder->folder = NULL;
status = mu_mailbox_get_folder (py_mbox->mbox, &py_folder->folder);
Py_INCREF (py_folder);
return status_object (status, (PyObject *)py_folder);
}
static PyObject *
api_mailbox_get_url (PyObject *self, PyObject *args)
{
int status;
PyMailbox *py_mbox;
PyUrl *py_url = PyUrl_NEW ();
if (!PyArg_ParseTuple (args, "O!", &PyMailboxType, &py_mbox))
return NULL;
Py_INCREF (py_url);
status = mu_mailbox_get_url (py_mbox->mbox, &py_url->url);
return status_object (status, (PyObject *)py_url);
}
static PyMethodDef methods[] = {
{ "create", (PyCFunction) api_mailbox_create, METH_VARARGS,
"Allocate and initialize MBOX. The concrete mailbox type "
"instantiate is based on the scheme of the url NAME." },
{ "create_default", (PyCFunction) api_mailbox_create_default, METH_VARARGS,
"Create a mailbox with mu_mailbox_create() based on the "
"environment variable MAIL or the string formed by "
"__PATH_MAILDIR_/USER or LOGNAME if USER is null." },
{ "destroy", (PyCFunction) api_mailbox_destroy, METH_VARARGS,
"Destroy and release resources held by MBOX." },
{ "open", (PyCFunction) api_mailbox_open, METH_VARARGS,
"A connection is open, if no stream was provided, a stream is "
"created based on the MBOX type. The FLAG can be OR'ed." },
{ "close", (PyCFunction) api_mailbox_close, METH_VARARGS,
"The stream attached to MBOX is closed." },
{ "flush", (PyCFunction) api_mailbox_flush, METH_VARARGS,
"" },
{ "messages_count", (PyCFunction) api_mailbox_messages_count, METH_VARARGS,
"Give the number of messages in MBOX." },
{ "messages_recent", (PyCFunction) api_mailbox_messages_recent, METH_VARARGS,
"Give the number of recent messages in MBOX." },
{ "message_unseen", (PyCFunction) api_mailbox_message_unseen, METH_VARARGS,
"Give the number of first unseen message in MBOX." },
{ "get_message", (PyCFunction) api_mailbox_get_message, METH_VARARGS,
"Retrieve message number MSGNO, MESSAGE is allocated and initialized." },
{ "append_message", (PyCFunction) api_mailbox_append_message, METH_VARARGS,
"Append MESSAGE to the mailbox MBOX." },
{ "expunge", (PyCFunction) api_mailbox_expunge, METH_VARARGS,
"Expunge deleted messages from the mailbox MBOX." },
{ "sync", (PyCFunction) api_mailbox_sync, METH_VARARGS,
"" },
{ "lock", (PyCFunction) api_mailbox_lock, METH_VARARGS,
"" },
{ "unlock", (PyCFunction) api_mailbox_unlock, METH_VARARGS,
"" },
{ "get_size", (PyCFunction) api_mailbox_get_size, METH_VARARGS,
"" },
{ "get_debug", (PyCFunction) api_mailbox_get_debug, METH_VARARGS,
"" },
{ "get_folder", (PyCFunction) api_mailbox_get_folder, METH_VARARGS,
"" },
{ "get_url", (PyCFunction) api_mailbox_get_url, METH_VARARGS,
"" },
{ NULL, NULL, 0, NULL }
};
void
init_mailbox ()
{
PyObject *m;
PyMailboxType.tp_new = PyType_GenericNew;
if (PyType_Ready (&PyMailboxType) < 0)
return;
if ((m = attach_module (PY_MODULE, methods)))
{
Py_INCREF (&PyMailboxType);
PyModule_AddObject (m, PY_CSNAME, (PyObject *)&PyMailboxType);
}
}
/*
GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 2009 Free Software Foundation, Inc.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General
Public License along with this library; if not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301 USA
*/
#ifndef _MUCAPI_MAILCAP_H
#define _MUCAPI_MAILCAP_H
#include <mailutils/mailcap.h>
typedef struct {
PyObject_HEAD;
mu_mailcap_t mc;
} PyMailcap;
typedef struct {
PyObject_HEAD;
mu_mailcap_entry_t entry;
} PyMailcapEntry;
extern PyMailcap * PyMailcap_NEW ();
extern PyMailcapEntry * PyMailcapEntry_NEW ();
#endif /* not _MUCAPI_MAILCAP_H */
/*
GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 2009 Free Software Foundation, Inc.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General
Public License along with this library; if not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301 USA
*/
#include "c_api.h"
#include "mailcap-private.h"
#include "stream-private.h"
#define PY_MODULE "mailcap"
#define PY_CSNAME1 "MailcapType"
#define PY_CSNAME2 "MailcapEntryType"
static PyObject *
_repr1 (PyObject *self)
{
char buf[80];
sprintf (buf, "<" PY_MODULE "." PY_CSNAME1 " instance at %p>", self);
return PyString_FromString (buf);
}
static PyTypeObject PyMailcapType = {
PyObject_HEAD_INIT(NULL)
0, /* ob_size */
PY_MODULE "." PY_CSNAME1, /* tp_name */
sizeof (PyMailcap), /* tp_basicsize */
0, /* tp_itemsize */
(destructor)py_dealloc, /* tp_dealloc */
0, /* tp_print */
0, /* tp_getattr; __getattr__ */
0, /* tp_setattr; __setattr__ */
0, /* tp_compare; __cmp__ */
_repr1, /* tp_repr; __repr__ */
0, /* tp_as_number */
0, /* tp_as_sequence */
0, /* tp_as_mapping */
0, /* tp_hash; __hash__ */
0, /* tp_call; __call__ */
_repr1, /* tp_str; __str__ */
0, /* tp_getattro */
0, /* tp_setattro */
0, /* tp_as_buffer */
Py_TPFLAGS_DEFAULT, /* tp_flags */
"", /* tp_doc */
0, /* tp_traverse */
0, /* tp_clear */
0, /* tp_richcompare */
0, /* tp_weaklistoffset */
0, /* tp_iter */
0, /* tp_iternext */
0, /* tp_methods */
0, /* tp_members */
0, /* tp_getset */
0, /* tp_base */
0, /* tp_dict */
0, /* tp_descr_get */
0, /* tp_descr_set */
0, /* tp_dictoffset */
0, /* tp_init */
0, /* tp_alloc */
0, /* tp_new */
};
PyMailcap *
PyMailcap_NEW ()
{
return (PyMailcap *)PyObject_NEW (PyMailcap, &PyMailcapType);
}
static PyObject *
_repr2 (PyObject *self)
{
char buf[80];
sprintf (buf, "<" PY_MODULE "." PY_CSNAME2 " instance at %p>", self);
return PyString_FromString (buf);
}
static PyTypeObject PyMailcapEntryType = {
PyObject_HEAD_INIT(NULL)
0, /* ob_size */
PY_MODULE "." PY_CSNAME2, /* tp_name */
sizeof (PyMailcapEntry), /* tp_basicsize */
0, /* tp_itemsize */
(destructor)py_dealloc, /* tp_dealloc */
0, /* tp_print */
0, /* tp_getattr; __getattr__ */
0, /* tp_setattr; __setattr__ */
0, /* tp_compare; __cmp__ */
_repr2, /* tp_repr; __repr__ */
0, /* tp_as_number */
0, /* tp_as_sequence */
0, /* tp_as_mapping */
0, /* tp_hash; __hash__ */
0, /* tp_call; __call__ */
_repr2, /* tp_str; __str__ */
0, /* tp_getattro */
0, /* tp_setattro */
0, /* tp_as_buffer */
Py_TPFLAGS_DEFAULT, /* tp_flags */
"", /* tp_doc */
0, /* tp_traverse */
0, /* tp_clear */
0, /* tp_richcompare */
0, /* tp_weaklistoffset */
0, /* tp_iter */
0, /* tp_iternext */
0, /* tp_methods */
0, /* tp_members */
0, /* tp_getset */
0, /* tp_base */
0, /* tp_dict */
0, /* tp_descr_get */
0, /* tp_descr_set */
0, /* tp_dictoffset */
0, /* tp_init */
0, /* tp_alloc */
0, /* tp_new */
};
PyMailcapEntry *
PyMailcapEntry_NEW ()
{
return (PyMailcapEntry *)PyObject_NEW (PyMailcapEntry,
&PyMailcapEntryType);
}
static PyObject *
api_mailcap_create (PyObject *self, PyObject *args)
{
int status;
PyMailcap *py_mc;
PyStream *py_stm;
if (!PyArg_ParseTuple (args, "O!O", &PyMailcapType, &py_mc, &py_stm))
return NULL;
if (!PyStream_Check ((PyObject *)py_stm))
{
PyErr_SetString (PyExc_TypeError, py_stm->ob_type->tp_name);
return NULL;
}
status = mu_mailcap_create (&py_mc->mc, py_stm->stm);
return _ro (PyInt_FromLong (status));
}
static PyObject *
api_mailcap_destroy (PyObject *self, PyObject *args)
{
PyMailcap *py_mc;
if (!PyArg_ParseTuple (args, "O!", &PyMailcapType, &py_mc))
return NULL;
mu_mailcap_destroy (&py_mc->mc);
return _ro (Py_None);
}
static PyObject *
api_mailcap_entries_count (PyObject *self, PyObject *args)
{
int status;
size_t count = 0;
PyMailcap *py_mc;
if (!PyArg_ParseTuple (args, "O!", &PyMailcapType, &py_mc))
return NULL;
status = mu_mailcap_entries_count (py_mc->mc, &count);
return status_object (status, PyInt_FromLong (count));
}
static PyObject *
api_mailcap_get_entry (PyObject *self, PyObject *args)
{
int status, i;
PyMailcap *py_mc;
PyMailcapEntry *py_entry = PyMailcapEntry_NEW ();
if (!PyArg_ParseTuple (args, "O!i", &PyMailcapType, &py_mc, &i))
return NULL;
status = mu_mailcap_get_entry (py_mc->mc, i, &py_entry->entry);
Py_INCREF (py_entry);
return status_object (status, (PyObject *)py_entry);
}
static PyObject *
api_mailcap_entry_fields_count (PyObject *self, PyObject *args)
{
int status;
size_t count;
PyMailcapEntry *py_entry;
if (!PyArg_ParseTuple (args, "O!", &PyMailcapEntryType, &py_entry))
return NULL;
status = mu_mailcap_entry_fields_count (py_entry->entry, &count);
return status_object (status, PyInt_FromLong (count));
}
static PyObject *
api_mailcap_entry_get_field (PyObject *self, PyObject *args)
{
int status, i;
char buf[256];
PyMailcapEntry *py_entry;
if (!PyArg_ParseTuple (args, "O!i", &PyMailcapEntryType, &py_entry,
&i))
return NULL;
status = mu_mailcap_entry_get_field (py_entry->entry, i, buf,
sizeof (buf), NULL);
return status_object (status, PyString_FromString (buf));
}
static PyObject *
api_mailcap_entry_get_typefield (PyObject *self, PyObject *args)
{
int status;
char buf[256];
PyMailcapEntry *py_entry;
if (!PyArg_ParseTuple (args, "O!", &PyMailcapEntryType, &py_entry))
return NULL;
status = mu_mailcap_entry_get_typefield (py_entry->entry, buf,
sizeof (buf), NULL);
return status_object (status, PyString_FromString (buf));
}
static PyObject *
api_mailcap_entry_get_viewcommand (PyObject *self, PyObject *args)
{
int status;
char buf[256];
PyMailcapEntry *py_entry;
if (!PyArg_ParseTuple (args, "O!", &PyMailcapEntryType, &py_entry))
return NULL;
status = mu_mailcap_entry_get_viewcommand (py_entry->entry, buf,
sizeof (buf), NULL);
return status_object (status, PyString_FromString (buf));
}
static PyMethodDef methods[] = {
{ "create", (PyCFunction) api_mailcap_create, METH_VARARGS,
"Allocate, parse the buffer from the STREAM and initializes MAILCAP." },
{ "destroy", (PyCFunction) api_mailcap_destroy, METH_VARARGS,
"Release any resources from the mailcap object." },
{ "entries_count", (PyCFunction) api_mailcap_entries_count, METH_VARARGS,
"Return the number of entries found in the mailcap." },
{ "get_entry", (PyCFunction) api_mailcap_get_entry, METH_VARARGS,
"Return in ENTRY the mailcap entry of NO." },
{ "entry_fields_count", (PyCFunction) api_mailcap_entry_fields_count,
METH_VARARGS,
"Return the number of fields found in the entry." },
{ "entry_get_field", (PyCFunction) api_mailcap_entry_get_field,
METH_VARARGS,
"" },
{ "entry_get_typefield", (PyCFunction) api_mailcap_entry_get_typefield,
METH_VARARGS,
"" },
{ "entry_get_viewcommand",
(PyCFunction) api_mailcap_entry_get_viewcommand, METH_VARARGS,
"" },
{ NULL, NULL, 0, NULL }
};
void
init_mailcap ()
{
PyObject *m;
PyMailcapType.tp_new = PyType_GenericNew;
PyMailcapEntryType.tp_new = PyType_GenericNew;
if (PyType_Ready (&PyMailcapType) < 0 ||
PyType_Ready (&PyMailcapEntryType) < 0)
return;
if ((m = attach_module (PY_MODULE, methods)))
{
Py_INCREF (&PyMailcapType);
Py_INCREF (&PyMailcapEntryType);
PyModule_AddObject (m, PY_CSNAME1, (PyObject *)&PyMailcapType);
PyModule_AddObject (m, PY_CSNAME2, (PyObject *)&PyMailcapEntryType);
}
}
/*
GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 2009 Free Software Foundation, Inc.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General
Public License along with this library; if not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301 USA
*/
#ifndef _MUCAPI_MAILER_H
#define _MUCAPI_MAILER_H
#include <mailutils/mailer.h>
typedef struct {
PyObject_HEAD;
mu_mailer_t mlr;
} PyMailer;
extern PyMailer * PyMailer_NEW ();
#endif /* not _MUCAPI_MAILER_H */
/*
GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 2009 Free Software Foundation, Inc.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General
Public License along with this library; if not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301 USA
*/
#include "c_api.h"
#include "mailer-private.h"
#include "address-private.h"
#include "message-private.h"
#include "debug-private.h"
#define PY_MODULE "mailer"
#define PY_CSNAME "MailerType"
static PyObject *
_repr (PyObject *self)
{
char buf[80];
sprintf (buf, "<" PY_MODULE "." PY_CSNAME " instance at %p>", self);
return PyString_FromString (buf);
}
static PyTypeObject PyMailerType = {
PyObject_HEAD_INIT(NULL)
0, /* ob_size */
PY_MODULE "." PY_CSNAME, /* tp_name */
sizeof (PyMailer), /* tp_basicsize */
0, /* tp_itemsize */
(destructor)py_dealloc, /* tp_dealloc */
0, /* tp_print */
0, /* tp_getattr; __getattr__ */
0, /* tp_setattr; __setattr__ */
0, /* tp_compare; __cmp__ */
_repr, /* tp_repr; __repr__ */
0, /* tp_as_number */
0, /* tp_as_sequence */
0, /* tp_as_mapping */
0, /* tp_hash; __hash__ */
0, /* tp_call; __call__ */
_repr, /* tp_str; __str__ */
0, /* tp_getattro */
0, /* tp_setattro */
0, /* tp_as_buffer */
Py_TPFLAGS_DEFAULT, /* tp_flags */
"", /* tp_doc */
0, /* tp_traverse */
0, /* tp_clear */
0, /* tp_richcompare */
0, /* tp_weaklistoffset */
0, /* tp_iter */
0, /* tp_iternext */
0, /* tp_methods */
0, /* tp_members */
0, /* tp_getset */
0, /* tp_base */
0, /* tp_dict */
0, /* tp_descr_get */
0, /* tp_descr_set */
0, /* tp_dictoffset */
0, /* tp_init */
0, /* tp_alloc */
0, /* tp_new */
};
PyMailer *
PyMailer_NEW ()
{
return (PyMailer *)PyObject_NEW (PyMailer, &PyMailerType);
}
static PyObject *
api_mailer_create (PyObject *self, PyObject *args)
{
int status;
char *url;
PyMailer *py_mlr;
if (!PyArg_ParseTuple (args, "O!s", &PyMailerType, &py_mlr, &url))
return NULL;
status = mu_mailer_create (&py_mlr->mlr, url);
return _ro (PyInt_FromLong (status));
}
static PyObject *
api_mailer_destroy (PyObject *self, PyObject *args)
{
PyMailer *py_mlr;
if (!PyArg_ParseTuple (args, "O!", &PyMailerType, &py_mlr))
return NULL;
mu_mailer_destroy (&py_mlr->mlr);
return _ro (Py_None);
}
static PyObject *
api_mailer_open (PyObject *self, PyObject *args)
{
int status, flags;
PyMailer *py_mlr;
if (!PyArg_ParseTuple (args, "O!i", &PyMailerType, &py_mlr, &flags))
return NULL;
status = mu_mailer_open (py_mlr->mlr, flags);
return _ro (PyInt_FromLong (status));
}
static PyObject *
api_mailer_close (PyObject *self, PyObject *args)
{
int status;
PyMailer *py_mlr;
if (!PyArg_ParseTuple (args, "O!", &PyMailerType, &py_mlr))
return NULL;
status = mu_mailer_close (py_mlr->mlr);
return _ro (PyInt_FromLong (status));
}
static PyObject *
api_mailer_send_message (PyObject *self, PyObject *args)
{
int status;
PyMailer *py_mlr;
PyMessage *py_msg;
PyAddress *py_from, *py_to;
mu_address_t c_from = NULL, c_to = NULL;
if (!PyArg_ParseTuple (args, "O!OOO", &PyMailerType, &py_mlr,
&py_msg, &py_from, &py_to))
return NULL;
if (!PyMessage_Check ((PyObject *)py_msg))
{
PyErr_SetString (PyExc_TypeError, "");
return NULL;
}
if (!PyAddress_Check ((PyObject *)py_from) &&
(PyObject *)py_from != Py_None)
{
PyErr_SetString (PyExc_TypeError, "");
return NULL;
}
if (!PyAddress_Check ((PyObject *)py_to) &&
(PyObject *)py_to != Py_None)
{
PyErr_SetString (PyExc_TypeError, "");
return NULL;
}
if ((PyObject *)py_from != Py_None)
c_from = py_from->addr;
if ((PyObject *)py_to != Py_None)
c_to = py_to->addr;
status = mu_mailer_send_message (py_mlr->mlr, py_msg->msg,
c_from, c_to);
return _ro (PyInt_FromLong (status));
}
static PyObject *
api_mailer_get_debug (PyObject *self, PyObject *args)
{
int status;
PyMailer *py_mlr;
PyDebug *py_dbg = PyDebug_NEW ();
if (!PyArg_ParseTuple (args, "O!", &PyMailerType, &py_mlr))
return NULL;
status = mu_mailer_get_debug (py_mlr->mlr, &py_dbg->dbg);
Py_INCREF (py_dbg);
return status_object (status, (PyObject *)py_dbg);
}
static PyMethodDef methods[] = {
{ "create", (PyCFunction) api_mailer_create, METH_VARARGS,
"Create mailer." },
{ "destroy", (PyCFunction) api_mailer_destroy, METH_VARARGS,
"The resources allocate for MSG are freed." },
{ "open", (PyCFunction) api_mailer_open, METH_VARARGS,
"" },
{ "close", (PyCFunction) api_mailer_close, METH_VARARGS,
"" },
{ "send_message", (PyCFunction) api_mailer_send_message, METH_VARARGS,
"" },
{ "get_debug", (PyCFunction) api_mailer_get_debug, METH_VARARGS,
"" },
{ NULL, NULL, 0, NULL }
};
void
init_mailer ()
{
PyObject *m;
PyMailerType.tp_new = PyType_GenericNew;
if (PyType_Ready (&PyMailerType) < 0)
return;
if ((m = attach_module (PY_MODULE, methods)))
{
Py_INCREF (&PyMailerType);
PyModule_AddObject (m, PY_CSNAME, (PyObject *)&PyMailerType);
}
}
/*
GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 2009 Free Software Foundation, Inc.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General
Public License along with this library; if not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301 USA
*/
#ifndef _MUCAPI_MESSAGE_H
#define _MUCAPI_MESSAGE_H
#include <mailutils/message.h>
typedef struct {
PyObject_HEAD;
mu_message_t msg;
} PyMessage;
extern PyMessage * PyMessage_NEW ();
extern int PyMessage_Check (PyObject *x);
#endif /* not _MUCAPI_MESSAGE_H */
/*
GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 2009 Free Software Foundation, Inc.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General
Public License along with this library; if not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301 USA
*/
#include "c_api.h"
#include "message-private.h"
#include "envelope-private.h"
#include "header-private.h"
#include "body-private.h"
#include "attribute-private.h"
#include "stream-private.h"
#define PY_MODULE "message"
#define PY_CSNAME "MessageType"
static PyObject *
_repr (PyObject *self)
{
char buf[80];
sprintf (buf, "<" PY_MODULE "." PY_CSNAME " instance at %p>", self);
return PyString_FromString (buf);
}
static PyTypeObject PyMessageType = {
PyObject_HEAD_INIT(NULL)
0, /* ob_size */
PY_MODULE "." PY_CSNAME, /* tp_name */
sizeof (PyMessage), /* tp_basicsize */
0, /* tp_itemsize */
(destructor)py_dealloc, /* tp_dealloc */
0, /* tp_print */
0, /* tp_getattr; __getattr__ */
0, /* tp_setattr; __setattr__ */
0, /* tp_compare; __cmp__ */
_repr, /* tp_repr; __repr__ */
0, /* tp_as_number */
0, /* tp_as_sequence */
0, /* tp_as_mapping */
0, /* tp_hash; __hash__ */
0, /* tp_call; __call__ */
_repr, /* tp_str; __str__ */
0, /* tp_getattro */
0, /* tp_setattro */
0, /* tp_as_buffer */
Py_TPFLAGS_DEFAULT, /* tp_flags */
"", /* tp_doc */
0, /* tp_traverse */
0, /* tp_clear */
0, /* tp_richcompare */
0, /* tp_weaklistoffset */
0, /* tp_iter */
0, /* tp_iternext */
0, /* tp_methods */
0, /* tp_members */
0, /* tp_getset */
0, /* tp_base */
0, /* tp_dict */
0, /* tp_descr_get */
0, /* tp_descr_set */
0, /* tp_dictoffset */
0, /* tp_init */
0, /* tp_alloc */
0, /* tp_new */
};
PyMessage *
PyMessage_NEW ()
{
return (PyMessage *)PyObject_NEW (PyMessage, &PyMessageType);
}
int
PyMessage_Check (PyObject *x)
{
return x->ob_type == &PyMessageType;
}
static PyObject *
api_message_create (PyObject *self, PyObject *args)
{
int status;
PyMessage *py_msg;
if (!PyArg_ParseTuple (args, "O!", &PyMessageType, &py_msg))
return NULL;
status = mu_message_create (&py_msg->msg, NULL);
return _ro (PyInt_FromLong (status));
}
static PyObject *
api_message_destroy (PyObject *self, PyObject *args)
{
PyMessage *py_msg;
if (!PyArg_ParseTuple (args, "O!", &PyMessageType, &py_msg))
return NULL;
mu_message_destroy (&py_msg->msg, NULL);
return _ro (Py_None);
}
static PyObject *
api_message_is_multipart (PyObject *self, PyObject *args)
{
int status, ismulti;
PyMessage *py_msg;
if (!PyArg_ParseTuple (args, "O!", &PyMessageType, &py_msg))
return NULL;
status = mu_message_is_multipart (py_msg->msg, &ismulti);
return status_object (status, PyBool_FromLong (ismulti));
}
static PyObject *
api_message_size (PyObject *self, PyObject *args)
{
int status;
size_t size;
PyMessage *py_msg;
if (!PyArg_ParseTuple (args, "O!", &PyMessageType, &py_msg))
return NULL;
status = mu_message_size (py_msg->msg, &size);
return status_object (status, PyInt_FromLong (size));
}
static PyObject *
api_message_lines (PyObject *self, PyObject *args)
{
int status;
size_t lines;
PyMessage *py_msg;
if (!PyArg_ParseTuple (args, "O!", &PyMessageType, &py_msg))
return NULL;
status = mu_message_lines (py_msg->msg, &lines);
return status_object (status, PyInt_FromLong (lines));
}
static PyObject *
api_message_get_envelope (PyObject *self, PyObject *args)
{
int status;
PyMessage *py_msg;
PyEnvelope *py_env = PyEnvelope_NEW ();
if (!PyArg_ParseTuple (args, "O!", &PyMessageType, &py_msg))
return NULL;
status = mu_message_get_envelope (py_msg->msg, &py_env->env);
Py_INCREF (py_env);
return status_object (status, (PyObject *)py_env);
}
static PyObject *
api_message_get_header (PyObject *self, PyObject *args)
{
int status;
PyMessage *py_msg;
PyHeader *py_hdr = PyHeader_NEW ();
if (!PyArg_ParseTuple (args, "O!", &PyMessageType, &py_msg))
return NULL;
status = mu_message_get_header (py_msg->msg, &py_hdr->hdr);
Py_INCREF (py_hdr);
return status_object (status, (PyObject *)py_hdr);
}
static PyObject *
api_message_get_body (PyObject *self, PyObject *args)
{
int status;
PyMessage *py_msg;
PyBody *py_body = PyBody_NEW ();
if (!PyArg_ParseTuple (args, "O!", &PyMessageType, &py_msg))
return NULL;
status = mu_message_get_body (py_msg->msg, &py_body->body);
Py_INCREF (py_body);
return status_object (status, (PyObject *)py_body);
}
static PyObject *
api_message_get_attribute (PyObject *self, PyObject *args)
{
int status;
PyMessage *py_msg;
PyAttribute *py_attr = PyAttribute_NEW ();
if (!PyArg_ParseTuple (args, "O!", &PyMessageType, &py_msg))
return NULL;
status = mu_message_get_attribute (py_msg->msg, &py_attr->attr);
Py_INCREF (py_attr);
return status_object (status, (PyObject *)py_attr);
}
static PyObject *
api_message_get_num_parts (PyObject *self, PyObject *args)
{
int status;
size_t parts;
PyMessage *py_msg;
if (!PyArg_ParseTuple (args, "O!", &PyMessageType, &py_msg))
return NULL;
status = mu_message_get_num_parts (py_msg->msg, &parts);
return status_object (status, PyInt_FromLong (parts));
}
static PyObject *
api_message_get_part (PyObject *self, PyObject *args)
{
int status;
size_t npart;
PyMessage *py_msg;
PyMessage *py_part = PyMessage_NEW ();
if (!PyArg_ParseTuple (args, "O!i", &PyMessageType, &py_msg, &npart))
return NULL;
status = mu_message_get_part (py_msg->msg, npart, &py_part->msg);
Py_INCREF (py_part);
return status_object (status, (PyObject *)py_part);
}
static PyObject *
api_message_get_uid (PyObject *self, PyObject *args)
{
int status;
size_t uid;
PyMessage *py_msg;
if (!PyArg_ParseTuple (args, "O!", &PyMessageType, &py_msg))
return NULL;
status = mu_message_get_uid (py_msg->msg, &uid);
return status_object (status, PyInt_FromLong (uid));
}
static PyObject *
api_message_get_uidl (PyObject *self, PyObject *args)
{
int status;
char buf[512];
size_t writen;
PyMessage *py_msg;
memset (buf, 0, sizeof (buf));
if (!PyArg_ParseTuple (args, "O!", &PyMessageType, &py_msg))
return NULL;
status = mu_message_get_uidl (py_msg->msg, buf, sizeof (buf), &writen);
return status_object (status, PyString_FromString (buf));
}
static PyObject *
api_message_get_attachment_name (PyObject *self, PyObject *args)
{
int status;
char *name = NULL;
PyMessage *py_msg;
if (!PyArg_ParseTuple (args, "O!", &PyMessageType, &py_msg))
return NULL;
status = mu_message_aget_attachment_name (py_msg->msg, &name);
return status_object (status, PyString_FromString (name ? name : ""));
}
static PyObject *
api_message_save_attachment (PyObject *self, PyObject *args)
{
int status;
char *filename = NULL;
PyMessage *py_msg;
if (!PyArg_ParseTuple (args, "O!|s", &PyMessageType, &py_msg,
&filename))
return NULL;
if (!strlen (filename))
filename = NULL;
status = mu_message_save_attachment (py_msg->msg, filename, NULL);
return _ro (PyInt_FromLong (status));
}
static PyObject *
api_message_unencapsulate (PyObject *self, PyObject *args)
{
int status;
char *filename = NULL;
PyMessage *py_msg;
PyMessage *py_unen = PyMessage_NEW ();
if (!PyArg_ParseTuple (args, "O!|s", &PyMessageType, &py_msg,
&filename))
return NULL;
Py_INCREF (py_unen);
status = mu_message_unencapsulate (py_msg->msg, &py_unen->msg, NULL);
return status_object (status, (PyObject *)py_unen);
}
static PyObject *
api_message_set_stream (PyObject *self, PyObject *args)
{
int status;
PyMessage *py_msg;
PyStream *py_stm;
if (!PyArg_ParseTuple (args, "O!O", &PyMessageType, &py_msg, &py_stm))
return NULL;
if (!PyStream_Check ((PyObject *)py_stm))
{
PyErr_SetString (PyExc_TypeError, "");
return NULL;
}
status = mu_message_set_stream (py_msg->msg, py_stm->stm, NULL);
py_stm->stm = NULL;
return _ro (PyInt_FromLong (status));
}
static PyMethodDef methods[] = {
{ "create", (PyCFunction) api_message_create, METH_VARARGS,
"Create message." },
{ "destroy", (PyCFunction) api_message_destroy, METH_VARARGS,
"The resources allocate for MSG are freed." },
{ "is_multipart", (PyCFunction) api_message_is_multipart, METH_VARARGS,
"" },
{ "size", (PyCFunction) api_message_size, METH_VARARGS,
"Retrieve MSG size." },
{ "lines", (PyCFunction) api_message_lines, METH_VARARGS,
"Retrieve MSG number of lines." },
{ "get_envelope", (PyCFunction) api_message_get_envelope, METH_VARARGS,
"Retrieve MSG envelope." },
{ "get_header", (PyCFunction) api_message_get_header, METH_VARARGS,
"Retrieve MSG header." },
{ "get_body", (PyCFunction) api_message_get_body, METH_VARARGS,
"Retrieve MSG body." },
{ "get_attribute", (PyCFunction) api_message_get_attribute, METH_VARARGS,
"Retrieve MSG attribute." },
{ "get_num_parts", (PyCFunction) api_message_get_num_parts, METH_VARARGS,
"" },
{ "get_part", (PyCFunction) api_message_get_part, METH_VARARGS,
"" },
{ "get_uid", (PyCFunction) api_message_get_uid, METH_VARARGS,
"" },
{ "get_uidl", (PyCFunction) api_message_get_uidl, METH_VARARGS,
"" },
{ "get_attachment_name", (PyCFunction) api_message_get_attachment_name,
METH_VARARGS, "" },
{ "save_attachment", (PyCFunction) api_message_save_attachment,
METH_VARARGS, "" },
{ "unencapsulate", (PyCFunction) api_message_unencapsulate,
METH_VARARGS, "" },
{ "set_stream", (PyCFunction) api_message_set_stream, METH_VARARGS,
"" },
{ NULL, NULL, 0, NULL }
};
void
init_message ()
{
PyObject *m;
PyMessageType.tp_new = PyType_GenericNew;
if (PyType_Ready (&PyMessageType) < 0)
return;
if ((m = attach_module (PY_MODULE, methods)))
{
Py_INCREF (&PyMessageType);
PyModule_AddObject (m, PY_CSNAME, (PyObject *)&PyMessageType);
}
}
/*
GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 2009 Free Software Foundation, Inc.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General
Public License along with this library; if not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301 USA
*/
#ifndef _MUCAPI_MIME_H
#define _MUCAPI_MIME_H
#include <mailutils/mime.h>
typedef struct {
PyObject_HEAD;
mu_mime_t mime;
} PyMime;
extern PyMime * PyMime_NEW ();
#endif /* not _MUCAPI_MIME_H */
/*
GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 2009 Free Software Foundation, Inc.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General
Public License along with this library; if not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301 USA
*/
#include "c_api.h"
#include "mime-private.h"
#include "message-private.h"
#define PY_MODULE "mime"
#define PY_CSNAME "MimeType"
static PyObject *
_repr (PyObject *self)
{
char buf[80];
sprintf (buf, "<" PY_MODULE "." PY_CSNAME " instance at %p>", self);
return PyString_FromString (buf);
}
static PyTypeObject PyMimeType = {
PyObject_HEAD_INIT(NULL)
0, /* ob_size */
PY_MODULE "." PY_CSNAME, /* tp_name */
sizeof (PyMime), /* tp_basicsize */
0, /* tp_itemsize */
(destructor)py_dealloc, /* tp_dealloc */
0, /* tp_print */
0, /* tp_getattr; __getattr__ */
0, /* tp_setattr; __setattr__ */
0, /* tp_compare; __cmp__ */
_repr, /* tp_repr; __repr__ */
0, /* tp_as_number */
0, /* tp_as_sequence */
0, /* tp_as_mapping */
0, /* tp_hash; __hash__ */
0, /* tp_call; __call__ */
_repr, /* tp_str; __str__ */
0, /* tp_getattro */
0, /* tp_setattro */
0, /* tp_as_buffer */
Py_TPFLAGS_DEFAULT, /* tp_flags */
"", /* tp_doc */
0, /* tp_traverse */
0, /* tp_clear */
0, /* tp_richcompare */
0, /* tp_weaklistoffset */
0, /* tp_iter */
0, /* tp_iternext */
0, /* tp_methods */
0, /* tp_members */
0, /* tp_getset */
0, /* tp_base */
0, /* tp_dict */
0, /* tp_descr_get */
0, /* tp_descr_set */
0, /* tp_dictoffset */
0, /* tp_init */
0, /* tp_alloc */
0, /* tp_new */
};
PyMime *
PyMime_NEW ()
{
return (PyMime *)PyObject_NEW (PyMime, &PyMimeType);
}
static PyObject *
api_mime_create (PyObject *self, PyObject *args)
{
int status, flags;
PyMime *py_mime;
PyMessage *py_msg;
if (!PyArg_ParseTuple (args, "O!Oi", &PyMimeType, &py_mime,
&py_msg, &flags))
return NULL;
if (!PyMessage_Check ((PyObject *)py_msg))
{
PyErr_SetString (PyExc_TypeError, "");
return NULL;
}
status = mu_mime_create (&py_mime->mime, py_msg->msg, flags);
return _ro (PyInt_FromLong (status));
}
static PyObject *
api_mime_destroy (PyObject *self, PyObject *args)
{
PyMime *py_mime;
if (!PyArg_ParseTuple (args, "O!", &PyMimeType, &py_mime))
return NULL;
mu_mime_destroy (&py_mime->mime);
return _ro (Py_None);
}
static PyObject *
api_mime_is_multipart (PyObject *self, PyObject *args)
{
int ismulti;
PyMime *py_mime;
if (!PyArg_ParseTuple (args, "O!", &PyMimeType, &py_mime))
return NULL;
ismulti = mu_mime_is_multipart (py_mime->mime);
return _ro (PyBool_FromLong (ismulti));
}
static PyObject *
api_mime_get_num_parts (PyObject *self, PyObject *args)
{
int status;
size_t nparts;
PyMime *py_mime;
if (!PyArg_ParseTuple (args, "O!", &PyMimeType, &py_mime))
return NULL;
status = mu_mime_get_num_parts (py_mime->mime, &nparts);
return status_object (status, PyInt_FromLong (nparts));
}
static PyObject *
api_mime_get_part (PyObject *self, PyObject *args)
{
int status;
size_t npart;
PyMime *py_mime;
PyMessage *py_part = PyMessage_NEW ();
if (!PyArg_ParseTuple (args, "O!i", &PyMimeType, &py_mime, &npart))
return NULL;
status = mu_mime_get_part (py_mime->mime, npart, &py_part->msg);
Py_INCREF (py_part);
return status_object (status, (PyObject *)py_part);
}
static PyObject *
api_mime_add_part (PyObject *self, PyObject *args)
{
int status;
PyMime *py_mime;
PyMessage *py_msg;
if (!PyArg_ParseTuple (args, "O!O", &PyMimeType, &py_mime, &py_msg))
return NULL;
if (!PyMessage_Check ((PyObject *)py_msg))
{
PyErr_SetString (PyExc_TypeError, "");
return NULL;
}
status = mu_mime_add_part (py_mime->mime, py_msg->msg);
return _ro (PyInt_FromLong (status));
}
static PyObject *
api_mime_get_message (PyObject *self, PyObject *args)
{
int status;
PyMime *py_mime;
PyMessage *py_msg = PyMessage_NEW ();
if (!PyArg_ParseTuple (args, "O!", &PyMimeType, &py_mime))
return NULL;
status = mu_mime_get_message (py_mime->mime, &py_msg->msg);
Py_INCREF (py_msg);
return status_object (status, (PyObject *)py_msg);
}
static PyObject *
api_rfc2047_decode (PyObject *self, PyObject *args)
{
int status;
char *tocode, *text;
char *buf = NULL;
if (!PyArg_ParseTuple (args, "ss", &tocode, &text))
return NULL;
status = mu_rfc2047_decode (tocode, text, &buf);
return status_object (status, PyString_FromString (buf ? buf : ""));
}
static PyObject *
api_rfc2047_encode (PyObject *self, PyObject *args)
{
int status;
char *charset, *encoding, *text;
char *buf = NULL;
if (!PyArg_ParseTuple (args, "sss", &charset, &encoding, &text))
return NULL;
status = mu_rfc2047_encode (charset, encoding, text, &buf);
return status_object (status, PyString_FromString (buf ? buf : ""));
}
static PyMethodDef methods[] = {
{ "create", (PyCFunction) api_mime_create, METH_VARARGS,
"" },
{ "destroy", (PyCFunction) api_mime_destroy, METH_VARARGS,
"" },
{ "is_multipart", (PyCFunction) api_mime_is_multipart, METH_VARARGS,
"" },
{ "get_num_parts", (PyCFunction) api_mime_get_num_parts, METH_VARARGS,
"" },
{ "get_part", (PyCFunction) api_mime_get_part, METH_VARARGS,
"" },
{ "add_part", (PyCFunction) api_mime_add_part, METH_VARARGS,
"" },
{ "get_message", (PyCFunction) api_mime_get_message, METH_VARARGS,
"" },
{ "rfc2047_decode", (PyCFunction) api_rfc2047_decode, METH_VARARGS,
"" },
{ "rfc2047_encode", (PyCFunction) api_rfc2047_encode, METH_VARARGS,
"" },
{ NULL, NULL, 0, NULL }
};
void
init_mime ()
{
PyObject *m;
PyMimeType.tp_new = PyType_GenericNew;
if (PyType_Ready (&PyMimeType) < 0)
return;
if ((m = attach_module (PY_MODULE, methods)))
{
Py_INCREF (&PyMimeType);
PyModule_AddObject (m, PY_CSNAME, (PyObject *)&PyMimeType);
}
}
/*
GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 2009 Free Software Foundation, Inc.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General
Public License along with this library; if not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301 USA
*/
#include "c_api.h"
#include <mailutils/registrar.h>
#include <mailutils/tls.h>
#define PY_MODULE "registrar"
struct format_record {
char *name;
mu_record_t *record;
};
static struct format_record format_table[] = {
{ "mbox", &mu_mbox_record },
{ "mh", &mu_mh_record },
{ "maildir", &mu_maildir_record },
{ "pop", &mu_pop_record },
{ "imap", &mu_imap_record },
#ifdef WITH_TLS
{ "pops", &mu_pops_record },
{ "imaps", &mu_imaps_record },
#endif /* WITH_TLS */
{ "sendmail", &mu_sendmail_record },
{ "smtp", &mu_smtp_record },
{ NULL, NULL },
};
static mu_record_t *
find_format (const struct format_record *table, const char *name)
{
for (; table->name; table++)
if (strcmp (table->name, name) == 0)
break;
return table->record;
}
static int
register_format (const char *name)
{
int status = 0;
if (!name)
{
struct format_record *table;
for (table = format_table; table->name; table++)
mu_registrar_record (*table->record);
}
else
{
mu_record_t *record = find_format (format_table, name);
if (record)
status = mu_registrar_record (*record);
else
status = EINVAL;
}
return status;
}
static int
set_default_format (const char *name)
{
int status = 0;
if (name)
{
mu_record_t *record = find_format (format_table, name);
if (record)
mu_registrar_set_default_record (*record);
else
status = EINVAL;
}
return status;
}
static PyObject *
api_registrar_register_format (PyObject *self, PyObject *args)
{
int status;
char *name = NULL;
if (!PyArg_ParseTuple (args, "|s", &name))
return NULL;
status = register_format (name);
return _ro (PyInt_FromLong (status));
}
static PyObject *
api_registrar_set_default_format (PyObject *self, PyObject *args)
{
int status;
char *name = NULL;
if (!PyArg_ParseTuple (args, "s", &name))
return NULL;
status = set_default_format (name);
return _ro (PyInt_FromLong (status));
}
static PyMethodDef methods[] = {
{ "register_format", (PyCFunction) api_registrar_register_format,
METH_VARARGS,
"Register desired mailutils formats. Any number of arguments "
"can be given." },
{ "set_default_format", (PyCFunction) api_registrar_set_default_format,
METH_VARARGS, "" },
{ NULL, NULL, 0, NULL }
};
void
init_registrar ()
{
attach_module (PY_MODULE, methods);
mu_registrar_record (MU_DEFAULT_RECORD);
mu_registrar_set_default_record (MU_DEFAULT_RECORD);
#ifdef WITH_TLS
mu_init_tls_libs ();
#endif /* WITH_TLS */
}
/*
GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 2009 Free Software Foundation, Inc.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General
Public License along with this library; if not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301 USA
*/
#ifndef _MUCAPI_STREAM_H
#define _MUCAPI_STREAM_H
#include <mailutils/stream.h>
typedef struct {
PyObject_HEAD;
mu_stream_t stm;
} PyStream;
extern PyStream * PyStream_NEW ();
extern int PyStream_Check (PyObject *x);
#endif /* not _MUCAPI_STREAM_H */
/*
GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 2009 Free Software Foundation, Inc.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General
Public License along with this library; if not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301 USA
*/
#include "c_api.h"
#include "stream-private.h"
#define PY_MODULE "stream"
#define PY_CSNAME "StreamType"
static PyObject *
_repr (PyObject *self)
{
char buf[80];
sprintf (buf, "<" PY_MODULE "." PY_CSNAME " instance at %p>", self);
return PyString_FromString (buf);
}
static PyTypeObject PyStreamType = {
PyObject_HEAD_INIT(NULL)
0, /* ob_size */
PY_MODULE "." PY_CSNAME, /* tp_name */
sizeof (PyStream), /* tp_basicsize */
0, /* tp_itemsize */
(destructor)py_dealloc, /* tp_dealloc */
0, /* tp_print */
0, /* tp_getattr; __getattr__ */
0, /* tp_setattr; __setattr__ */
0, /* tp_compare; __cmp__ */
_repr, /* tp_repr; __repr__ */
0, /* tp_as_number */
0, /* tp_as_sequence */
0, /* tp_as_mapping */
0, /* tp_hash; __hash__ */
0, /* tp_call; __call__ */
_repr, /* tp_str; __str__ */
0, /* tp_getattro */
0, /* tp_setattro */
0, /* tp_as_buffer */
Py_TPFLAGS_DEFAULT, /* tp_flags */
"", /* tp_doc */
0, /* tp_traverse */
0, /* tp_clear */
0, /* tp_richcompare */
0, /* tp_weaklistoffset */
0, /* tp_iter */
0, /* tp_iternext */
0, /* tp_methods */
0, /* tp_members */
0, /* tp_getset */
0, /* tp_base */
0, /* tp_dict */
0, /* tp_descr_get */
0, /* tp_descr_set */
0, /* tp_dictoffset */
0, /* tp_init */
0, /* tp_alloc */
0, /* tp_new */
};
PyStream *
PyStream_NEW ()
{
return (PyStream *)PyObject_NEW (PyStream, &PyStreamType);
}
int
PyStream_Check (PyObject *x)
{
return x->ob_type == &PyStreamType;
}
static PyObject *
api_tcp_stream_create (PyObject *self, PyObject *args)
{
int status, flags, port;
char *host;
PyStream *py_stm;
if (!PyArg_ParseTuple (args, "O!sii", &PyStreamType, &py_stm,
&host, &port, &flags))
return NULL;
status = mu_tcp_stream_create (&py_stm->stm, host, port, flags);
return _ro (PyInt_FromLong (status));
}
static PyObject *
api_file_stream_create (PyObject *self, PyObject *args)
{
int status, flags;
char *filename;
PyStream *py_stm;
if (!PyArg_ParseTuple (args, "O!si", &PyStreamType, &py_stm,
&filename, &flags))
return NULL;
status = mu_file_stream_create (&py_stm->stm, filename, flags);
return _ro (PyInt_FromLong (status));
}
static PyObject *
api_stdio_stream_create (PyObject *self, PyObject *args)
{
int status, flags;
char *filename;
FILE *fp;
PyStream *py_stm;
PyFileObject *py_file;
if (!PyArg_ParseTuple (args, "O!O!i",
&PyStreamType, &py_stm,
&PyFile_Type, &py_file,
&flags))
return NULL;
fp = PyFile_AsFile ((PyObject *)py_file);
status = mu_stdio_stream_create (&py_stm->stm, fp, flags);
return _ro (PyInt_FromLong (status));
}
static PyObject *
api_prog_stream_create (PyObject *self, PyObject *args)
{
int status, flags;
char *progname;
PyStream *py_stm;
if (!PyArg_ParseTuple (args, "O!si", &PyStreamType, &py_stm,
&progname, &flags))
return NULL;
status = mu_prog_stream_create (&py_stm->stm, progname, flags);
return _ro (PyInt_FromLong (status));
}
static PyObject *
api_filter_prog_stream_create (PyObject *self, PyObject *args)
{
int status;
char *progname;
PyStream *py_stm, *py_input;
if (!PyArg_ParseTuple (args, "O!sO!",
&PyStreamType, &py_stm,
&progname,
&PyStreamType, &py_input))
return NULL;
status = mu_filter_prog_stream_create (&py_stm->stm, progname,
py_input->stm);
return _ro (PyInt_FromLong (status));
}
static PyObject *
api_stream_destroy (PyObject *self, PyObject *args)
{
PyStream *py_stm;
if (!PyArg_ParseTuple (args, "O!", &PyStreamType, &py_stm))
return NULL;
mu_stream_destroy (&py_stm->stm, NULL);
return _ro (Py_None);
}
static PyObject *
api_stream_open (PyObject *self, PyObject *args)
{
int status;
PyStream *py_stm;
if (!PyArg_ParseTuple (args, "O!", &PyStreamType, &py_stm))
return NULL;
status = mu_stream_open (py_stm->stm);
return _ro (PyInt_FromLong (status));
}
static PyObject *
api_stream_close (PyObject *self, PyObject *args)
{
int status;
PyStream *py_stm;
if (!PyArg_ParseTuple (args, "O!", &PyStreamType, &py_stm))
return NULL;
status = mu_stream_close (py_stm->stm);
return _ro (PyInt_FromLong (status));
}
static PyObject *
api_stream_flush (PyObject *self, PyObject *args)
{
int status;
PyStream *py_stm;
if (!PyArg_ParseTuple (args, "O!", &PyStreamType, &py_stm))
return NULL;
status = mu_stream_flush (py_stm->stm);
return _ro (PyInt_FromLong (status));
}
static PyObject *
api_stream_wait (PyObject *self, PyObject *args)
{
int status, wflags;
PyStream *py_stm;
if (!PyArg_ParseTuple (args, "O!i", &PyStreamType, &py_stm, &wflags))
return NULL;
status = mu_stream_wait (py_stm->stm, &wflags, NULL);
return _ro (PyInt_FromLong (status));
}
static PyObject *
api_stream_read (PyObject *self, PyObject *args)
{
int status;
size_t offset;
size_t read_count;
char rbuf[1024];
PyObject *py_ret;
PyStream *py_stm;
memset (rbuf, 0, sizeof (rbuf));
if (!PyArg_ParseTuple (args, "O!i", &PyStreamType, &py_stm, &offset))
return NULL;
status = mu_stream_read (py_stm->stm, rbuf, sizeof (rbuf), offset,
&read_count);
py_ret = PyTuple_New (3);
PyTuple_SetItem (py_ret, 0, PyInt_FromLong (status));
PyTuple_SetItem (py_ret, 1, PyString_FromString (rbuf));
PyTuple_SetItem (py_ret, 2, PyInt_FromLong (read_count));
return _ro (py_ret);
}
static PyObject *
api_stream_write (PyObject *self, PyObject *args)
{
int status;
size_t offset;
size_t write_count;
char *wbuf;
PyStream *py_stm;
if (!PyArg_ParseTuple (args, "O!si", &PyStreamType, &py_stm,
&wbuf, &offset))
return NULL;
status = mu_stream_write (py_stm->stm, wbuf, strlen (wbuf), offset,
&write_count);
return status_object (status, PyInt_FromLong (write_count));
}
static PyObject *
api_stream_readline (PyObject *self, PyObject *args)
{
int status;
size_t offset;
size_t read_count;
char rbuf[1024];
PyObject *py_ret;
PyStream *py_stm;
memset (rbuf, 0, sizeof (rbuf));
if (!PyArg_ParseTuple (args, "O!i", &PyStreamType, &py_stm, &offset))
return NULL;
status = mu_stream_readline (py_stm->stm, rbuf, sizeof (rbuf), offset,
&read_count);
py_ret = PyTuple_New (3);
PyTuple_SetItem (py_ret, 0, PyInt_FromLong (status));
PyTuple_SetItem (py_ret, 1, PyString_FromString (rbuf));
PyTuple_SetItem (py_ret, 2, PyInt_FromLong (read_count));
return _ro (py_ret);
}
static PyObject *
api_stream_sequential_readline (PyObject *self, PyObject *args)
{
int status;
size_t read_count;
char rbuf[1024];
PyObject *py_ret;
PyStream *py_stm;
memset (rbuf, 0, sizeof (rbuf));
if (!PyArg_ParseTuple (args, "O!", &PyStreamType, &py_stm))
return NULL;
status = mu_stream_sequential_readline (py_stm->stm, rbuf, sizeof (rbuf),
&read_count);
py_ret = PyTuple_New (3);
PyTuple_SetItem (py_ret, 0, PyInt_FromLong (status));
PyTuple_SetItem (py_ret, 1, PyString_FromString (rbuf));
PyTuple_SetItem (py_ret, 2, PyInt_FromLong (read_count));
return _ro (py_ret);
}
static PyObject *
api_stream_sequential_write (PyObject *self, PyObject *args)
{
int status;
char *wbuf;
size_t size;
PyStream *py_stm;
if (!PyArg_ParseTuple (args, "O!si", &PyStreamType, &py_stm, &wbuf,
&size))
return NULL;
status = mu_stream_sequential_write (py_stm->stm, wbuf, size);
return _ro (PyInt_FromLong (status));
}
static PyMethodDef methods[] = {
{ "tcp_stream_create", (PyCFunction) api_tcp_stream_create, METH_VARARGS,
"" },
{ "file_stream_create", (PyCFunction) api_file_stream_create, METH_VARARGS,
"" },
{ "stdio_stream_create", (PyCFunction) api_stdio_stream_create, METH_VARARGS,
"" },
{ "prog_stream_create", (PyCFunction) api_prog_stream_create, METH_VARARGS,
"" },
{ "filter_prog_stream_create",
(PyCFunction) api_filter_prog_stream_create, METH_VARARGS,
"" },
{ "destroy", (PyCFunction) api_stream_destroy, METH_VARARGS,
"" },
{ "open", (PyCFunction) api_stream_open, METH_VARARGS,
"" },
{ "close", (PyCFunction) api_stream_close, METH_VARARGS,
"" },
{ "flush", (PyCFunction) api_stream_flush, METH_VARARGS,
"" },
{ "wait", (PyCFunction) api_stream_wait, METH_VARARGS,
"" },
{ "read", (PyCFunction) api_stream_read, METH_VARARGS,
"" },
{ "write", (PyCFunction) api_stream_write, METH_VARARGS,
"" },
{ "readline", (PyCFunction) api_stream_readline, METH_VARARGS,
"" },
{ "sequential_readline", (PyCFunction) api_stream_sequential_readline,
METH_VARARGS, "" },
{ "sequential_write", (PyCFunction) api_stream_sequential_write,
METH_VARARGS, "" },
{ NULL, NULL, 0, NULL }
};
void
init_stream ()
{
PyObject *m;
PyStreamType.tp_new = PyType_GenericNew;
if (PyType_Ready (&PyStreamType) < 0)
return;
if ((m = attach_module (PY_MODULE, methods)))
{
Py_INCREF (&PyStreamType);
PyModule_AddObject (m, PY_CSNAME, (PyObject *)&PyStreamType);
}
}
/*
GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 2009 Free Software Foundation, Inc.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General
Public License along with this library; if not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301 USA
*/
#ifndef _MUCAPI_URL_H
#define _MUCAPI_URL_H
#include <mailutils/url.h>
typedef struct {
PyObject_HEAD;
mu_url_t url;
} PyUrl;
extern PyUrl * PyUrl_NEW ();
#endif /* not _MUCAPI_URL_H */
/*
GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 2009 Free Software Foundation, Inc.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General
Public License along with this library; if not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301 USA
*/
#include "c_api.h"
#include "url-private.h"
#define PY_MODULE "url"
#define PY_CSNAME "UrlType"
static PyObject *
_repr (PyObject *self)
{
char buf[80];
sprintf (buf, "<" PY_MODULE "." PY_CSNAME " instance at %p>", self);
return PyString_FromString (buf);
}
static PyTypeObject PyUrlType = {
PyObject_HEAD_INIT(NULL)
0, /* ob_size */
PY_MODULE "." PY_CSNAME, /* tp_name */
sizeof (PyUrl), /* tp_basicsize */
0, /* tp_itemsize */
(destructor)py_dealloc, /* tp_dealloc */
0, /* tp_print */
0, /* tp_getattr; __getattr__ */
0, /* tp_setattr; __setattr__ */
0, /* tp_compare; __cmp__ */
_repr, /* tp_repr; __repr__ */
0, /* tp_as_number */
0, /* tp_as_sequence */
0, /* tp_as_mapping */
0, /* tp_hash; __hash__ */
0, /* tp_call; __call__ */
_repr, /* tp_str; __str__ */
0, /* tp_getattro */
0, /* tp_setattro */
0, /* tp_as_buffer */
Py_TPFLAGS_DEFAULT, /* tp_flags */
"", /* tp_doc */
0, /* tp_traverse */
0, /* tp_clear */
0, /* tp_richcompare */
0, /* tp_weaklistoffset */
0, /* tp_iter */
0, /* tp_iternext */
0, /* tp_methods */
0, /* tp_members */
0, /* tp_getset */
0, /* tp_base */
0, /* tp_dict */
0, /* tp_descr_get */
0, /* tp_descr_set */
0, /* tp_dictoffset */
0, /* tp_init */
0, /* tp_alloc */
0, /* tp_new */
};
PyUrl *
PyUrl_NEW ()
{
return (PyUrl *)PyObject_NEW (PyUrl, &PyUrlType);
}
static PyObject *
api_url_create (PyObject *self, PyObject *args)
{
int status;
char *str;
PyUrl *py_url;
if (!PyArg_ParseTuple (args, "O!s", &PyUrlType, &py_url, &str))
return NULL;
status = mu_url_create (&py_url->url, str);
return _ro (PyInt_FromLong (status));
}
static PyObject *
api_url_destroy (PyObject *self, PyObject *args)
{
PyUrl *py_url;
if (!PyArg_ParseTuple (args, "O!", &PyUrlType, &py_url))
return NULL;
mu_url_destroy (&py_url->url);
return _ro (Py_None);
}
static PyObject *
api_url_parse (PyObject *self, PyObject *args)
{
int status;
PyUrl *py_url;
if (!PyArg_ParseTuple (args, "O!", &PyUrlType, &py_url))
return NULL;
status = mu_url_parse (py_url->url);
return _ro (PyInt_FromLong (status));
}
static PyObject *
api_url_get_port (PyObject *self, PyObject *args)
{
int status;
long port;
PyUrl *py_url;
if (!PyArg_ParseTuple (args, "O!", &PyUrlType, &py_url))
return NULL;
status = mu_url_get_port (py_url->url, &port);
return status_object (status, PyInt_FromLong (port));
}
static PyObject *
api_url_get_scheme (PyObject *self, PyObject *args)
{
int status;
const char *buf = NULL;
PyUrl *py_url;
if (!PyArg_ParseTuple (args, "O!", &PyUrlType, &py_url))
return NULL;
status = mu_url_sget_scheme (py_url->url, &buf);
return status_object (status, PyString_FromString (buf ? buf : ""));
}
static PyObject *
api_url_get_user (PyObject *self, PyObject *args)
{
int status;
const char *buf = NULL;
PyUrl *py_url;
if (!PyArg_ParseTuple (args, "O!", &PyUrlType, &py_url))
return NULL;
status = mu_url_sget_user (py_url->url, &buf);
return status_object (status, PyString_FromString (buf ? buf : ""));
}
static PyObject *
api_url_get_passwd (PyObject *self, PyObject *args)
{
int status;
const char *buf = NULL;
PyUrl *py_url;
if (!PyArg_ParseTuple (args, "O!", &PyUrlType, &py_url))
return NULL;
status = mu_url_sget_passwd (py_url->url, &buf);
return status_object (status, PyString_FromString (buf ? buf : ""));
}
static PyObject *
api_url_get_auth (PyObject *self, PyObject *args)
{
int status;
const char *buf = NULL;
PyUrl *py_url;
if (!PyArg_ParseTuple (args, "O!", &PyUrlType, &py_url))
return NULL;
status = mu_url_sget_auth (py_url->url, &buf);
return status_object (status, PyString_FromString (buf ? buf : ""));
}
static PyObject *
api_url_get_host (PyObject *self, PyObject *args)
{
int status;
const char *buf = NULL;
PyUrl *py_url;
if (!PyArg_ParseTuple (args, "O!", &PyUrlType, &py_url))
return NULL;
status = mu_url_sget_host (py_url->url, &buf);
return status_object (status, PyString_FromString (buf ? buf : ""));
}
static PyObject *
api_url_get_path (PyObject *self, PyObject *args)
{
int status;
const char *buf = NULL;
PyUrl *py_url;
if (!PyArg_ParseTuple (args, "O!", &PyUrlType, &py_url))
return NULL;
status = mu_url_sget_path (py_url->url, &buf);
return status_object (status, PyString_FromString (buf ? buf : ""));
}
static PyObject *
api_url_get_query (PyObject *self, PyObject *args)
{
int status, i;
size_t argc;
char **argv;
PyObject *py_list;
PyUrl *py_url;
if (!PyArg_ParseTuple (args, "O!", &PyUrlType, &py_url))
return NULL;
status = mu_url_sget_query (py_url->url, &argc, &argv);
py_list = PyList_New (0);
for (i = 0; i < argc; i++)
PyList_Append (py_list, PyString_FromString (argv[i]));
return status_object (status, py_list);
}
static PyObject *
api_url_to_string (PyObject *self, PyObject *args)
{
int status;
const char *str;
PyUrl *py_url;
if (!PyArg_ParseTuple (args, "O!", &PyUrlType, &py_url))
return NULL;
str = mu_url_to_string (py_url->url);
return _ro (PyString_FromString (str ? str : ""));
}
static PyMethodDef methods[] = {
{ "create", (PyCFunction) api_url_create, METH_VARARGS,
"Create the url data structure, but do not parse it." },
{ "destroy", (PyCFunction) api_url_destroy, METH_VARARGS,
"Destroy the url and free its resources." },
{ "parse", (PyCFunction) api_url_parse, METH_VARARGS,
"Parse the url, after calling this the get functions can be called." },
{ "to_string", (PyCFunction) api_url_to_string, METH_VARARGS,
"" },
{ "get_port", (PyCFunction) api_url_get_port, METH_VARARGS, "" },
{ "get_scheme", (PyCFunction) api_url_get_scheme, METH_VARARGS, "" },
{ "get_user", (PyCFunction) api_url_get_user, METH_VARARGS, "" },
{ "get_passwd", (PyCFunction) api_url_get_passwd, METH_VARARGS, "" },
{ "get_auth", (PyCFunction) api_url_get_auth, METH_VARARGS, "" },
{ "get_host", (PyCFunction) api_url_get_host, METH_VARARGS, "" },
{ "get_path", (PyCFunction) api_url_get_path, METH_VARARGS, "" },
{ "get_query", (PyCFunction) api_url_get_query, METH_VARARGS, "" },
{ NULL, NULL, 0, NULL }
};
void
init_url ()
{
PyObject *m;
PyUrlType.tp_new = PyType_GenericNew;
if (PyType_Ready (&PyUrlType) < 0)
return;
if ((m = attach_module (PY_MODULE, methods)))
{
Py_INCREF (&PyUrlType);
PyModule_AddObject (m, PY_CSNAME, (PyObject *)&PyUrlType);
}
}
/*
GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 2009 Free Software Foundation, Inc.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General
Public License along with this library; if not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301 USA
*/
#include "c_api.h"
#include <mailutils/mutil.h>
#define PY_MODULE "util"
static PyObject *
api_util_get_user_email (PyObject *self, PyObject *args)
{
int status;
char *name = NULL;
char *email = NULL;
if (!PyArg_ParseTuple (args, "|s", &name))
return NULL;
email = mu_get_user_email (name);
return _ro (PyString_FromString (email ? email : ""));
}
static PyObject *
api_util_set_user_email (PyObject *self, PyObject *args)
{
int status;
char *email;
if (!PyArg_ParseTuple (args, "s", &email))
return NULL;
status = mu_set_user_email (email);
return _ro (PyInt_FromLong (status));
}
static PyObject *
api_util_get_user_email_domain (PyObject *self, PyObject *args)
{
int status;
const char *domain = NULL;
status = mu_get_user_email_domain (&domain);
return status_object (status, PyString_FromString (domain ? domain : ""));
}
static PyObject *
api_util_set_user_email_domain (PyObject *self, PyObject *args)
{
int status;
char *domain;
if (!PyArg_ParseTuple (args, "s", &domain))
return NULL;
status = mu_set_user_email_domain (domain);
return _ro (PyInt_FromLong (status));
}
static PyObject *
api_util_tempname (PyObject *self, PyObject *args)
{
char *tmpdir = NULL, *tmpname = NULL;
if (!PyArg_ParseTuple (args, "|z", &tmpdir))
return NULL;
tmpname = mu_tempname (tmpdir);
return _ro (PyString_FromString (tmpname ? tmpname : ""));
}
static PyMethodDef methods[] = {
{ "get_user_email", (PyCFunction) api_util_get_user_email, METH_VARARGS,
"Get the default user email address." },
{ "set_user_email", (PyCFunction) api_util_set_user_email, METH_VARARGS,
"Set the default user email address." },
{ "get_user_email_domain", (PyCFunction) api_util_get_user_email_domain,
METH_VARARGS,
"Get the default user email address domain." },
{ "set_user_email_domain", (PyCFunction) api_util_set_user_email_domain,
METH_VARARGS,
"Set the default user email address domain." },
{ "tempname", (PyCFunction) api_util_tempname,
METH_VARARGS, "" },
{ NULL, NULL, 0, NULL }
};
void
init_util ()
{
attach_module (PY_MODULE, methods);
}
## Process this file with GNU Automake to create Makefile.in
## Copyright (C) 2009 Free Software Foundation, Inc.
##
## GNU Mailutils is free software; you can redistribute it and/or
## modify it under the terms of the GNU General Public License as
## published by the Free Software Foundation; either version 3, or (at
## your option) any later version.
##
## This program is distributed in the hope that it will be useful, but
## WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
## General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with this program; if not, write to the Free Software
## Foundation, Inc. 51 Franklin Street, Fifth Floor, Boston, MA
## 02110-1301 USA
pkgpython_PYTHON = \
__init__.py \
error.py \
address.py \
attribute.py \
auth.py \
body.py \
debug.py \
envelope.py \
filter.py \
folder.py \
header.py \
mailer.py \
mailbox.py \
mailcap.py \
message.py \
mime.py \
registrar.py \
stream.py \
url.py \
util.py
# GNU Mailutils -- a suite of utilities for electronic mail
# Copyright (C) 2009 Free Software Foundation, Inc.
#
# GNU Mailutils is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3, or (at your option)
# any later version.
#
# GNU Mailutils is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with GNU Mailutils; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301 USA
__all__ = [
"error",
"address",
"attribute",
"auth",
"body",
"debug",
"envelope",
"filter",
"folder",
"header",
"mailer",
"mailbox",
"mailcap",
"message",
"mime",
"registrar",
"stream",
"url",
"util",
]
#
# GNU Mailutils -- a suite of utilities for electronic mail
# Copyright (C) 2009 Free Software Foundation, Inc.
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 3 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General
# Public License along with this library; if not, write to the
# Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
# Boston, MA 02110-1301 USA
#
import types
from mailutils.c_api import address
from mailutils.error import AddressError
class Address:
def __init__ (self, addr):
self.addr = address.AddressType ()
if isinstance (addr, types.ListType):
status = address.createv (self.addr, addr)
else:
status = address.create (self.addr, addr)
if status:
raise AddressError (status)
def __del__ (self):
address.destroy (self.addr)
del self.addr
def __len__ (self):
return self.get_count ()
def __str__ (self):
status, str = address.to_string (self.addr)
if status:
raise AddressError (status)
return str
def __iter__ (self):
self.__count = 0
self.__len = self.get_count ()
return self
def next (self):
if self.__count >= self.__len:
self.__count = 0
raise StopIteration
else:
self.__count += 1
return self.get_email (self.__count)
def is_group (self, n):
"""Return True if this address is just the name of a group,
False otherwise."""
status, isgroup = address.is_group (self.addr, n)
if status:
raise AddressError (status)
return isgroup
def get_count (self):
"""Return a count of the addresses in the address list."""
return address.get_count (self.addr)
def get_email (self, n):
"""Return email part of the Nth email address."""
status, email = address.get_email (self.addr, n)
if status:
raise AddressError (status)
return email
def get_local_part (self, n):
"""Return local part of the Nth email address."""
status, local_part = address.get_local_part (self.addr, n)
if status:
raise AddressError (status)
return local_part
def get_domain (self, n):
"""Return domain part of the Nth email address."""
status, domain = address.get_domain (self.addr, n)
if status:
raise AddressError (status)
return domain
def get_personal (self, n):
"""Return personal part of the Nth email address."""
status, personal = address.get_personal (self.addr, n)
if status:
raise AddressError (status)
return personal
def get_comments (self, n):
"""Return comment part of the Nth email address."""
status, comments = address.get_comments (self.addr, n)
if status:
raise AddressError (status)
return comments
def get_route (self, n):
"""Return the route part of the Nth email address."""
status, route = address.get_route (self.addr, n)
if status:
raise AddressError (status)
return route
#
# GNU Mailutils -- a suite of utilities for electronic mail
# Copyright (C) 2009 Free Software Foundation, Inc.
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 3 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General
# Public License along with this library; if not, write to the
# Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
# Boston, MA 02110-1301 USA
#
import types
from mailutils.c_api import attribute
from mailutils.error import *
MU_ATTRIBUTE_ANSWERED = 0x01
MU_ATTRIBUTE_FLAGGED = 0x02
MU_ATTRIBUTE_DELETED = 0x04
MU_ATTRIBUTE_DRAFT = 0x08
MU_ATTRIBUTE_SEEN = 0x10
MU_ATTRIBUTE_READ = 0x20
MU_ATTRIBUTE_MODIFIED = 0x40
class Attribute:
def __init__ (self, attr):
self.attr = attr
def __del__ (self):
del self.attr
def __str__ (self):
return attribute.to_string (self.attr)
def __getitem__ (self, flag):
return self.is_flag (flag)
def __setitem__ (self, flag, value):
if value == True:
self.set_flags (flag)
elif value == False:
self.unset_flags (flag)
else:
raise TypeError, value
def is_modified (self):
return attribute.is_modified (self.attr)
def clear_modified (self):
attribute.clear_modified (self.attr)
def set_modified (self):
attribute.set_modified (self.attr)
def get_flags (self):
status, flags = attribute.get_flags (self.attr)
if status:
raise Error (status)
return flags
def set_flags (self, flags):
status = attribute.set_flags (self.attr, flags)
if status:
raise Error (status)
def unset_flags (self, flags):
status = attribute.unset_flags (self.attr, flags)
if status:
raise Error (status)
def is_flag (self, flag):
flags = self.get_flags ()
if flags & flag:
return True
return False
#
# GNU Mailutils -- a suite of utilities for electronic mail
# Copyright (C) 2009 Free Software Foundation, Inc.
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 3 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General
# Public License along with this library; if not, write to the
# Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
# Boston, MA 02110-1301 USA
#
import types
from mailutils.c_api import auth
from mailutils.error import AuthError
MU_AF_QUOTA = 0x1
def register_module (name = None):
if name == None:
status = auth.register_module ()
elif isinstance (name, types.TupleType) \
or isinstance (name, types.ListType):
for n in name:
status = auth.register_module (n)
else:
status = auth.register_module (name)
if status:
raise AuthError (status)
def get_auth_by_name (username):
return auth.get_auth_by_name (username)
def get_auth_by_uid (uid):
return auth.get_auth_by_uid (uid)
def authenticate (auth_data, password):
status = auth.authenticate (auth_data, password)
if status:
raise AuthError (status)
class Authority:
__owner = False
def __init__ (self, authority = None):
if isinstance (authority, auth.AuthorityType):
self.authority = authority
else:
self.authority = auth.AuthorityType ()
self.__owner = True
status = auth.authority_create (self.authority)
if status:
raise AuthError (status)
def __del__ (self):
if self.__owner:
auth.authority_destroy (self.authority)
del self.authority
def get_ticket (self):
status, ticket = auth.authority_get_ticket (self.authority)
if status:
raise AuthError (status)
return Ticket (ticket)
def set_ticket (self, ticket):
status = auth.authority_set_ticket (self.authority, ticket.ticket)
if status:
raise AuthError (status)
def authenticate (self):
status = auth.authority_authenticate (self.authority)
if status:
raise AuthError (status)
class Ticket:
__owner = False
def __init__ (self, ticket = None):
if isinstance (ticket, auth.TicketType):
self.ticket = ticket
else:
self.ticket = auth.TicketType ()
self.__owner = True
status = auth.ticket_create (self.ticket)
if status:
raise AuthError (status)
def __del__ (self):
if self.__owner:
auth.ticket_destroy (self.ticket)
del self.ticket
class Wicket:
__owner = False
def __init__ (self, wicket = None):
if isinstance (wicket, auth.WicketType):
self.wicket = wicket
else:
self.wicket = auth.WicketType ()
self.__owner = True
status = auth.wicket_create (self.wicket)
if status:
raise AuthError (status)
def __del__ (self):
if self.__owner:
auth.wicket_destroy (self.wicket)
del self.wicket
def __str__ (self):
return self.get_filename ()
def get_filename (self):
status, filename = auth.wicket_get_filename (self.wicket)
if status:
raise AuthError (status)
return filename
def set_filename (self, filename):
status = auth.wicket_set_filename (self.wicket, filename)
if status:
raise AuthError (status)
#
# GNU Mailutils -- a suite of utilities for electronic mail
# Copyright (C) 2009 Free Software Foundation, Inc.
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 3 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General
# Public License along with this library; if not, write to the
# Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
# Boston, MA 02110-1301 USA
#
from mailutils.c_api import body
from mailutils import stream
from mailutils.error import BodyError
class Body:
def __init__ (self, bd):
self.bd = bd
def __del__ (self):
del self.bd
def __getattr__ (self, name):
if name == 'size':
return self.get_size ()
elif name == 'lines':
return self.get_lines ()
else:
raise AttributeError, name
def __len__ (self):
return self.get_size ()
def get_size (self):
status, size = body.size (self.bd)
if status:
raise BodyError (status)
return size
def get_lines (self):
status, lines = body.lines (self.bd)
if status:
raise BodyError (status)
return lines
def get_stream (self):
status, stm = body.get_stream (self.bd)
if status:
raise BodyError (status)
return stream.Stream (stm)
#
# GNU Mailutils -- a suite of utilities for electronic mail
# Copyright (C) 2009 Free Software Foundation, Inc.
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 3 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General
# Public License along with this library; if not, write to the
# Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
# Boston, MA 02110-1301 USA
#
from mailutils.c_api import debug
from mailutils.error import DebugError
MU_DEBUG_ERROR = 0
MU_DEBUG_TRACE0 = 1
MU_DEBUG_TRACE = MU_DEBUG_TRACE0
MU_DEBUG_TRACE1 = 2
MU_DEBUG_TRACE2 = 3
MU_DEBUG_TRACE3 = 4
MU_DEBUG_TRACE4 = 5
MU_DEBUG_TRACE5 = 6
MU_DEBUG_TRACE6 = 7
MU_DEBUG_TRACE7 = 8
MU_DEBUG_PROT = 9
class Debug:
def __init__ (self, dbg):
self.dbg = dbg
def __del__ (self):
del self.dbg
def set_level (self, level = MU_DEBUG_PROT):
status = debug.set_level (self.dbg, level)
if status:
raise DebugError (status)
#
# GNU Mailutils -- a suite of utilities for electronic mail
# Copyright (C) 2009 Free Software Foundation, Inc.
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 3 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General
# Public License along with this library; if not, write to the
# Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
# Boston, MA 02110-1301 USA
#
from mailutils.c_api import envelope
from mailutils.error import EnvelopeError
MU_ENVELOPE_DATE_FORMAT = "%a %b %d %H:%M:%S %Y"
MU_ENVELOPE_DATE_LENGTH = 24
class Envelope:
def __init__ (self, env):
self.env = env
def __del__ (self):
del self.env
def get_sender (self):
"""Get the address that this message was reportedly received from."""
status, sender = envelope.get_sender (self.env)
if status:
raise EnvelopeError (status)
return sender
def get_date (self):
"""Get the date that the message was delivered to the mailbox, in
something close to ANSI ctime() format: Mon Jul 05 13:08:27 1999."""
status, date = envelope.get_date (self.env)
if status:
raise EnvelopeError (status)
return date
#
# GNU Mailutils -- a suite of utilities for electronic mail
# Copyright (C) 2009 Free Software Foundation, Inc.
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 3 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General
# Public License along with this library; if not, write to the
# Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
# Boston, MA 02110-1301 USA
#
from mailutils.c_api import error
def strerror (status):
return error.strerror (status)
class Error (Exception):
def __init__ (self, status):
self.status = status
self.strerror = strerror (status)
def __str__ (self):
return "%d: %s" % (self.status, self.strerror)
class AddressError (Error): pass
class AuthError (Error): pass
class BodyError (Error): pass
class DebugError (Error): pass
class EnvelopeError (Error): pass
class FolderError (Error): pass
class HeaderError (Error): pass
class MailerError (Error): pass
class MailboxError (Error): pass
class MailcapError (Error): pass
class MessageError (Error): pass
class MimeError (Error): pass
class StreamError (Error): pass
class UrlError (Error): pass
MU_ERR_BASE = 0x1000
MU_ERR_FAILURE = (MU_ERR_BASE+0)
MU_ERR_CANCELED = (MU_ERR_BASE+1)
MU_ERR_NO_HANDLER = (MU_ERR_BASE+2)
MU_ERR_EMPTY_VFN = (MU_ERR_BASE+3)
MU_ERR_OUT_NULL = (MU_ERR_BASE+4)
MU_ERR_OUT_PTR_NULL = (MU_ERR_BASE+5)
MU_ERR_MBX_NULL = (MU_ERR_BASE+6)
MU_ERR_BAD_822_FORMAT = (MU_ERR_BASE+7)
MU_ERR_EMPTY_ADDRESS = (MU_ERR_BASE+8)
MU_ERR_LOCKER_NULL = (MU_ERR_BASE+9)
MU_ERR_LOCK_CONFLICT = (MU_ERR_BASE+10)
MU_ERR_LOCK_BAD_LOCK = (MU_ERR_BASE+11)
MU_ERR_LOCK_BAD_FILE = (MU_ERR_BASE+12)
MU_ERR_LOCK_NOT_HELD = (MU_ERR_BASE+13)
MU_ERR_LOCK_EXT_FAIL = (MU_ERR_BASE+14)
MU_ERR_LOCK_EXT_ERR = (MU_ERR_BASE+15)
MU_ERR_LOCK_EXT_KILLED = (MU_ERR_BASE+16)
MU_ERR_NO_SUCH_USER = (MU_ERR_BASE+17)
MU_ERR_GETHOSTBYNAME = (MU_ERR_BASE+18)
MU_ERR_BAD_RESUMPTION = (MU_ERR_BASE+19)
MU_ERR_MAILER_BAD_FROM = (MU_ERR_BASE+20)
MU_ERR_MAILER_BAD_TO = (MU_ERR_BASE+21)
MU_ERR_MAILER_NO_RCPT_TO = (MU_ERR_BASE+22)
MU_ERR_MAILER_BAD_URL = (MU_ERR_BASE+23)
MU_ERR_SMTP_RCPT_FAILED = (MU_ERR_BASE+24)
MU_ERR_TCP_NO_HOST = (MU_ERR_BASE+25)
MU_ERR_TCP_NO_PORT = (MU_ERR_BASE+26)
MU_ERR_BAD_2047_INPUT = (MU_ERR_BASE+27)
MU_ERR_BAD_2047_ENCODING = (MU_ERR_BASE+28)
MU_ERR_NOUSERNAME = (MU_ERR_BASE+29)
MU_ERR_NOPASSWORD = (MU_ERR_BASE+30)
MU_ERR_UNSAFE_PERMS = (MU_ERR_BASE+31)
MU_ERR_BAD_AUTH_SCHEME = (MU_ERR_BASE+32)
MU_ERR_AUTH_FAILURE = (MU_ERR_BASE+33)
MU_ERR_PROCESS_NOEXEC = (MU_ERR_BASE+34)
MU_ERR_PROCESS_EXITED = (MU_ERR_BASE+35)
MU_ERR_PROCESS_SIGNALED = (MU_ERR_BASE+36)
MU_ERR_PROCESS_UNKNOWN_FAILURE = (MU_ERR_BASE+37)
MU_ERR_CONN_CLOSED = (MU_ERR_BASE+38)
MU_ERR_PARSE = (MU_ERR_BASE+39)
MU_ERR_NOENT = (MU_ERR_BASE+40)
MU_ERR_EXISTS = (MU_ERR_BASE+41)
MU_ERR_BUFSPACE = (MU_ERR_BASE+42)
MU_ERR_SQL = (MU_ERR_BASE+43)
MU_ERR_DB_ALREADY_CONNECTED = (MU_ERR_BASE+44)
MU_ERR_DB_NOT_CONNECTED = (MU_ERR_BASE+45)
MU_ERR_RESULT_NOT_RELEASED = (MU_ERR_BASE+46)
MU_ERR_NO_QUERY = (MU_ERR_BASE+47)
MU_ERR_BAD_COLUMN = (MU_ERR_BASE+48)
MU_ERR_NO_RESULT = (MU_ERR_BASE+49)
MU_ERR_NO_INTERFACE = (MU_ERR_BASE+50)
MU_ERR_BADOP = (MU_ERR_BASE+51)
MU_ERR_BAD_FILENAME = (MU_ERR_BASE+52)
MU_ERR_READ = (MU_ERR_BASE+53)
#
# GNU Mailutils -- a suite of utilities for electronic mail
# Copyright (C) 2009 Free Software Foundation, Inc.
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 3 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General
# Public License along with this library; if not, write to the
# Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
# Boston, MA 02110-1301 USA
#
from mailutils.c_api import filter
from mailutils.stream import *
from mailutils.error import StreamError
# Type
MU_FILTER_DECODE = 0
MU_FILTER_ENCODE = 1
# Direction
MU_FILTER_READ = MU_STREAM_READ
MU_FILTER_WRITE = MU_STREAM_WRITE
MU_FILTER_RDWR = MU_STREAM_RDWR
class FilterStream (Stream):
def __init__ (self, transport, name, type = MU_FILTER_DECODE,
direction = MU_FILTER_READ):
Stream.__init__ (self)
status = filter.create (self.stm, transport.stm, name,
type, direction)
if status:
raise StreamError (status)
class FilterIconvStream (Stream):
def __init__ (self, transport, fromcode, tocode, direction=MU_FILTER_READ):
Stream.__init__ (self)
status = filter.iconv_create (self.stm, transport.stm,
fromcode, tocode, direction)
if status:
raise StreamError (status)
#
# GNU Mailutils -- a suite of utilities for electronic mail
# Copyright (C) 2009 Free Software Foundation, Inc.
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 3 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General
# Public License along with this library; if not, write to the
# Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
# Boston, MA 02110-1301 USA
#
from mailutils.c_api import folder
from mailutils import stream
from mailutils import auth
from mailutils import url
from mailutils.error import FolderError
class Folder:
__owner = False
def __init__ (self, f):
if isinstance (f, folder.FolderType):
self.folder = f
else:
self.folder = folder.FolderType ()
self.__owner = True
status = folder.create (self.folder, f)
if status:
raise FolderError (status)
def __del__ (self):
if self.__owner:
folder.destroy (self.folder)
del self.folder
def open (self):
status = folder.open (self.folder)
if status:
raise FolderError (status)
def close (self):
status = folder.close (self.folder)
if status:
raise FolderError (status)
def get_stream (self):
status, stream = folder.get_stream (self.folder)
if status:
raise FolderError (status)
return stream.Stream (stm)
def set_stream (self, stream):
status = folder.set_stream (self.folder, stream.stm)
if status:
raise FolderError (status)
def get_authority (self):
status, authority = folder.get_authority (self.folder)
if status:
raise FolderError (status)
return auth.Authority (authority)
def set_authority (self, authority):
status = folder.set_authority (self.folder, authority.authority)
if status:
raise FolderError (status)
def get_url (self):
status, u = folder.get_url (self.folder)
if status:
raise FolderError (status)
return url.Url (u)
def list (self, dirname, pattern, max_level = 0):
status, lst = folder.list (self.folder, dirname, pattern, max_level)
if status:
raise FolderError (status)
return lst
#
# GNU Mailutils -- a suite of utilities for electronic mail
# Copyright (C) 2009 Free Software Foundation, Inc.
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 3 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General
# Public License along with this library; if not, write to the
# Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
# Boston, MA 02110-1301 USA
#
import types
from mailutils.c_api import header
from mailutils.error import *
class Header:
def __init__ (self, hdr):
self.hdr = hdr
def __del__ (self):
del self.hdr
def __getitem__ (self, item):
if isinstance (item, types.IntType):
return self.get_field_name (item), self.get_field_value (item)
else:
return self.get_value (item)
def __setitem__ (self, name, value):
self.set_value (name, value)
def __getattr__ (self, name):
if name == 'size':
return self.get_size ()
elif name == 'lines':
return self.get_lines ()
else:
raise AttributeError, name
def __len__ (self):
return self.get_field_count ()
def __iter__ (self):
self.__count = 0
self.__len = self.get_field_count ()
return self
def next (self):
if self.__count >= self.__len:
self.__count = 0
raise StopIteration
else:
self.__count += 1
return self.__getitem__ (self.__count)
def get_size (self):
status, size = header.size (self.hdr)
if status:
raise HeaderError (status)
return size
def get_lines (self):
status, lines = header.lines (self.hdr)
if status:
raise HeaderError (status)
return lines
def get_value (self, name, default = None):
status, value = header.get_value (self.hdr, name)
if status == MU_ERR_NOENT:
if default != None:
return default
else:
raise KeyError (name)
elif status:
raise HeaderError (status)
return value
def set_value (self, name, value, replace = True):
status = header.set_value (self.hdr, name, value, replace)
if status:
raise HeaderError (status)
def get_field_count (self):
status, count = header.get_field_count (self.hdr)
if status:
raise HeaderError (status)
return count
def get_field_name (self, idx):
status, name = header.get_field_name (self.hdr, idx)
if status == MU_ERR_NOENT:
raise IndexError (idx)
elif status:
raise HeaderError (status)
return name
def get_field_value (self, idx):
status, value = header.get_field_value (self.hdr, idx)
if status == MU_ERR_NOENT:
raise IndexError (idx)
elif status:
raise HeaderError (status)
return value
MU_HEADER_UNIX_FROM = "From "
MU_HEADER_RETURN_PATH = "Return-Path"
MU_HEADER_RECEIVED = "Received"
MU_HEADER_DATE = "Date"
MU_HEADER_DCC = "Dcc"
MU_HEADER_FROM = "From"
MU_HEADER_SENDER = "Sender"
MU_HEADER_RESENT_FROM = "Resent-From"
MU_HEADER_SUBJECT = "Subject"
MU_HEADER_SENDER = "Sender"
MU_HEADER_RESENT_SENDER = "Resent-SENDER"
MU_HEADER_TO = "To"
MU_HEADER_RESENT_TO = "Resent-To"
MU_HEADER_CC = "Cc"
MU_HEADER_RESENT_CC = "Resent-Cc"
MU_HEADER_BCC = "Bcc"
MU_HEADER_RESENT_BCC = "Resent-Bcc"
MU_HEADER_REPLY_TO = "Reply-To"
MU_HEADER_RESENT_REPLY_TO = "Resent-Reply-To"
MU_HEADER_MESSAGE_ID = "Message-ID"
MU_HEADER_RESENT_MESSAGE_ID = "Resent-Message-ID"
MU_HEADER_IN_REPLY_TO = "In-Reply-To"
MU_HEADER_REFERENCE = "Reference"
MU_HEADER_REFERENCES = "References"
MU_HEADER_ENCRYPTED = "Encrypted"
MU_HEADER_PRECEDENCE = "Precedence"
MU_HEADER_STATUS = "Status"
MU_HEADER_CONTENT_LENGTH = "Content-Length"
MU_HEADER_CONTENT_LANGUAGE = "Content-Language"
MU_HEADER_CONTENT_TRANSFER_ENCODING = "Content-transfer-encoding"
MU_HEADER_CONTENT_ID = "Content-ID"
MU_HEADER_CONTENT_TYPE = "Content-Type"
MU_HEADER_CONTENT_DESCRIPTION = "Content-Description"
MU_HEADER_CONTENT_DISPOSITION = "Content-Disposition"
MU_HEADER_CONTENT_MD5 = "Content-MD5"
MU_HEADER_MIME_VERSION = "MIME-Version"
MU_HEADER_X_MAILER = "X-Mailer"
MU_HEADER_X_UIDL = "X-UIDL"
MU_HEADER_X_UID = "X-UID"
MU_HEADER_X_IMAPBASE = "X-IMAPbase"
MU_HEADER_ENV_SENDER = "X-Envelope-Sender"
MU_HEADER_ENV_DATE = "X-Envelope-Date"
MU_HEADER_FCC = "Fcc"
MU_HEADER_DELIVERY_DATE = "Delivery-date"
MU_HEADER_ENVELOPE_TO = "Envelope-to"
MU_HEADER_X_EXPIRE_TIMESTAMP = "X-Expire-Timestamp"
MU_HEADER_REPLACE = 0x01
MU_HEADER_BEFORE = 0x02
#
# GNU Mailutils -- a suite of utilities for electronic mail
# Copyright (C) 2009 Free Software Foundation, Inc.
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 3 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General
# Public License along with this library; if not, write to the
# Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
# Boston, MA 02110-1301 USA
#
from mailutils.c_api import mailbox
from mailutils import message
from mailutils import folder
from mailutils import url
from mailutils import debug
from mailutils.error import MailboxError
class MailboxBase:
def open (self, flags = 0):
"""Open the connection."""
status = mailbox.open (self.mbox, flags)
if status:
raise MailboxError (status)
def close (self):
"""Close the connection."""
status = mailbox.close (self.mbox)
if status:
raise MailboxError (status)
def flush (self, expunge = False):
"""Flush the mailbox."""
status = mailbox.flush (self.mbox, expunge)
if status:
raise MailboxError (status)
def messages_count (self):
"""Return the number of messages in mailbox."""
status, total = mailbox.messages_count (self.mbox)
if status:
raise MailboxError (status)
return total
def messages_recent (self):
"""Return the number of recent messages in mailbox."""
status, recent = mailbox.messages_recent (self.mbox)
if status:
raise MailboxError (status)
return recent
def message_unseen (self):
"""Return the number of first unseen message in mailbox."""
status, recent = mailbox.message_unseen (self.mbox)
if status:
raise MailboxError (status)
return unseen
def get_message (self, msgno):
"""Retrieve message number MSGNO."""
status, c_msg = mailbox.get_message (self.mbox, msgno)
if status:
raise MailboxError (status)
return message.Message (c_msg)
def append_message (self, msg):
"""Append MSG to the mailbox."""
status = mailbox.append_message (self.mbox, msg.msg)
if status:
raise MailboxError (status)
def expunge (self):
"""Remove all messages marked for deletion."""
status = mailbox.expunge (self.mbox)
if status:
raise MailboxError (status)
def sync (self):
"""Synchronize the mailbox."""
status = mailbox.sync (self.mbox)
if status:
raise MailboxError (status)
def lock (self):
"""Lock the mailbox."""
status = mailbox.lock (self.mbox)
if status:
raise MailboxError (status)
def unlock (self):
"""Unlock the mailbox."""
status = mailbox.unlock (self.mbox)
if status:
raise MailboxError (status)
def get_size (self):
"""Return the mailbox size."""
status, size = mailbox.get_size (self.mbox)
if status:
raise MailboxError (status)
return size
def get_folder (self):
"""Get the FOLDER."""
status, fld = mailbox.get_folder (self.mbox)
if status:
raise MailboxError (status)
return folder.Folder (fld)
def get_debug (self):
status, dbg = mailbox.get_debug (self.mbox)
if status:
raise MailboxError (status)
return debug.Debug (dbg)
def get_url (self):
status, u = mailbox.get_url (self.mbox)
if status:
raise MailboxError (status)
return url.Url (u)
def next (self):
if self.__count >= self.__len:
self.__count = 0
raise StopIteration
else:
self.__count += 1
return self.get_message (self.__count)
def __getitem__ (self, msgno):
return self.get_message (msgno)
def __iter__ (self):
self.__count = 0
self.__len = self.messages_count ()
return self
def __getattr__ (self, name):
if name == 'size':
return self.get_size ()
elif name == 'folder':
return self.get_folder ()
elif name == 'url':
return self.get_url ()
elif name == 'debug':
return self.get_debug ()
else:
raise AttributeError, name
def __len__ (self):
return self.messages_count ()
class Mailbox (MailboxBase):
def __init__ (self, name):
self.mbox = mailbox.MailboxType ()
status = mailbox.create (self.mbox, name)
if status:
raise MailboxError (status)
def __del__ (self):
mailbox.destroy (self.mbox)
del self.mbox
class MailboxDefault (MailboxBase):
def __init__ (self, name):
self.mbox = mailbox.MailboxType ()
status = mailbox.create_default (self.mbox, name)
if status:
raise MailboxError (status)
def __del__ (self):
mailbox.destroy (self.mbox)
del self.mbox
#
# GNU Mailutils -- a suite of utilities for electronic mail
# Copyright (C) 2009 Free Software Foundation, Inc.
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 3 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General
# Public License along with this library; if not, write to the
# Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
# Boston, MA 02110-1301 USA
#
from mailutils.c_api import mailcap
from mailutils.error import MailcapError
class Mailcap:
def __init__ (self, stream):
self.mc = mailcap.MailcapType ()
status = mailcap.create (self.mc, stream.stm)
if status:
raise MailcapError (status)
def __del__ (self):
mailcap.destroy (self.mc)
del self.mc
def __len__ (self):
return self.entries_count ()
def __getitem__ (self, item):
return self.get_entry (item)
def __iter__ (self):
self.__count = 0
self.__len = self.entries_count ()
return self
def next (self):
if self.__count >= self.__len:
self.__count = 0
raise StopIteration
else:
self.__count += 1
return self.__getitem__ (self.__count)
def entries_count (self):
"""Return the number of entries found in the mailcap."""
status, count = mailcap.entries_count (self.mc)
if status:
raise MailcapError (status)
return count
def get_entry (self, item):
"""Return in MailcapEntry the mailcap entry of ITEM."""
status, entry = mailcap.get_entry (self.mc, item)
if status:
raise MailcapError (status)
return MailcapEntry (entry)
class MailcapEntry:
def __init__ (self, entry):
self.entry = entry
def __len__ (self):
return self.fields_count ()
def __getitem__ (self, item):
return self.get_field (item)
def __iter__ (self):
self.__count = 0
self.__len = self.fields_count ()
return self
def next (self):
if self.__count >= self.__len:
self.__count = 0
raise StopIteration
else:
self.__count += 1
return self.__getitem__ (self.__count)
def fields_count (self):
status, count = mailcap.entry_fields_count (self.entry)
if status:
raise MailcapEntry (status)
return count
def get_field (self, i):
status, field = mailcap.entry_get_field (self.entry, i)
if status:
raise MailcapEntry (status)
return field
def get_typefield (self):
status, typefield = mailcap.entry_get_typefield (self.entry)
if status:
raise MailcapEntry (status)
return typefield
def get_viewcommand (self):
status, viewcommand = mailcap.entry_get_viewcommand (self.entry)
if status:
raise MailcapEntry (status)
return viewcommand
#
# GNU Mailutils -- a suite of utilities for electronic mail
# Copyright (C) 2009 Free Software Foundation, Inc.
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 3 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General
# Public License along with this library; if not, write to the
# Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
# Boston, MA 02110-1301 USA
#
from mailutils.c_api import mailer
from mailutils import address
from mailutils import debug
from mailutils.error import MailerError
class Mailer:
def __init__ (self, url):
self.mlr = mailer.MailerType ()
status = mailer.create (self.mlr, url)
if status:
raise MailerError (status)
def __del__ (self):
mailer.destroy (self.mlr)
del self.mlr
def __getattr__ (self, name):
if name == 'debug':
return self.get_debug ()
else:
raise AttributeError, name
def open (self, flags = 0):
status = mailer.open (self.mlr, flags)
if status:
raise MailerError (status)
def close (self):
status = mailer.close (self.mlr)
if status:
raise MailerError (status)
def send_message (self, msg, frm, to):
if isinstance (frm, address.Address):
frm = frm.addr
if isinstance (to, address.Address):
to = to.addr
status = mailer.send_message (self.mlr, msg.msg, frm, to)
if status:
raise MailerError (status)
def get_debug (self):
status, dbg = mailer.get_debug (self.mlr)
if status:
raise MailerError (status)
return debug.Debug (dbg)
#
# GNU Mailutils -- a suite of utilities for electronic mail
# Copyright (C) 2009 Free Software Foundation, Inc.
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 3 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General
# Public License along with this library; if not, write to the
# Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
# Boston, MA 02110-1301 USA
#
from mailutils.c_api import message
from mailutils import envelope
from mailutils import header
from mailutils import body
from mailutils import attribute
from mailutils.error import MessageError
class Message:
__owner = False
def __init__ (self, msg = None):
if msg == None:
self.msg = message.MessageType ()
self.__owner = True
status = message.create (self.msg)
if status:
raise MessageError (status)
else:
self.msg = msg
def __del__ (self):
if self.__owner:
message.destroy (self.msg)
del self.msg
def __getattr__ (self, name):
if name == 'header':
return self.get_header ()
elif name == 'body':
return self.get_body ()
elif name == 'envelope':
return self.get_envelope ()
elif name == 'attribute':
return self.get_attribute ()
elif name == 'size':
return self.get_size ()
elif name == 'lines':
return self.get_lines ()
else:
raise AttributeError, name
def __len__ (self):
return self.get_size ()
def is_multipart (self):
status, ismulti = message.is_multipart (self.msg)
if status:
raise MessageError (status)
return ismulti
def get_size (self):
status, size = message.size (self.msg)
if status:
raise MessageError (status)
return size
def get_lines (self):
status, lines = message.lines (self.msg)
if status:
raise MessageError (status)
return lines
def get_envelope (self):
status, env = message.get_envelope (self.msg)
if status:
raise MessageError (status)
return envelope.Envelope (env)
def get_header (self):
status, hdr = message.get_header (self.msg)
if status:
raise MessageError (status)
return header.Header (hdr)
def get_body (self):
status, bd = message.get_body (self.msg)
if status:
raise MessageError (status)
return body.Body (bd)
def get_attribute (self):
status, attr = message.get_attribute (self.msg)
if status:
raise MessageError (status)
return attribute.Attribute (attr)
def get_num_parts (self):
status, num_parts = message.get_num_parts (self.msg)
if status:
raise MessageError (status)
return num_parts
def get_part (self, npart):
status, part = message.get_part (self.msg, npart)
if status:
raise MessageError (status)
return Message (part)
def get_uid (self):
status, uid = message.get_uid (self.msg)
if status:
raise MessageError (status)
return uid
def get_uidl (self):
status, uidl = message.get_uidl (self.msg)
if status:
raise MessageError (status)
return uidl
def get_attachment_name (self):
status, name = message.get_attachment_name (self.msg)
if status:
raise MessageError (status)
return name
def save_attachment (self, filename = ''):
status = message.save_attachment (self.msg, filename)
if status:
raise MessageError (status)
def unencapsulate (self):
status, msg = message.unencapsulate (self.msg)
if status:
raise MessageError (status)
return Message (msg)
def set_stream (self, stream):
status = message.set_stream (self.msg, stream.stm)
if status:
raise MessageError (status)
#
# GNU Mailutils -- a suite of utilities for electronic mail
# Copyright (C) 2009 Free Software Foundation, Inc.
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 3 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General
# Public License along with this library; if not, write to the
# Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
# Boston, MA 02110-1301 USA
#
from mailutils.c_api import mime
from mailutils import message
from mailutils.error import MimeError
MU_MIME_MULTIPART_MIXED = 0x1
MU_MIME_MULTIPART_ALT = 0x2
class Mime:
def __init__ (self, msg, flags = 0):
self.mime = mime.MimeType ()
status = mime.create (self.mime, msg.msg, flags)
if status:
raise MimeError (status)
def __del__ (self):
mime.destroy (self.mime)
del self.mime
def is_multipart (self):
return mime.is_multipart (self.mime)
def get_num_parts (self):
status, nparts = mime.get_num_parts (self.mime)
if status:
raise MimeError (status)
return nparts
def get_part (self, npart):
status, msg = mime.get_part (self.mime, npart)
if status:
raise MimeError (status)
return message.Message (msg)
def add_part (self, name, msg):
status = mime.add_part (self.mime, msg.msg)
if status:
raise MimeError (status)
def get_message (self):
status, msg = mime.get_message (self.mime)
if status:
raise MimeError (status)
return message.Message (msg)
def rfc2047_decode (tocode, text):
return mime.rfc2047_decode (tocode, text)
def rfc2047_encode (charset, encoding, text):
return mime.rfc2047_encode (charset, encoding, text)
#
# GNU Mailutils -- a suite of utilities for electronic mail
# Copyright (C) 2009 Free Software Foundation, Inc.
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 3 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General
# Public License along with this library; if not, write to the
# Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
# Boston, MA 02110-1301 USA
#
import types
from mailutils.c_api import registrar
def register_format (name = None):
if name == None:
registrar.register_format ()
elif isinstance (name, types.TupleType) \
or isinstance (name, types.ListType):
for n in name:
registrar.register_format (n)
else:
registrar.register_format (name)
def set_default_format (name):
registrar.set_default_format (name)
#
# GNU Mailutils -- a suite of utilities for electronic mail
# Copyright (C) 2009 Free Software Foundation, Inc.
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 3 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General
# Public License along with this library; if not, write to the
# Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
# Boston, MA 02110-1301 USA
#
from mailutils.c_api import stream
from mailutils.error import StreamError
MU_STREAM_READ = 0x00000001
MU_STREAM_WRITE = 0x00000002
MU_STREAM_RDWR = 0x00000004
MU_STREAM_APPEND = 0x00000008
MU_STREAM_CREAT = 0x00000010
MU_STREAM_NONBLOCK = 0x00000020
MU_STREAM_NO_CHECK = 0x00000040
MU_STREAM_SEEKABLE = 0x00000080
MU_STREAM_NO_CLOSE = 0x00000100
MU_STREAM_ALLOW_LINKS = 0x00000200
MU_STREAM_NONLOCK = 0x00000400
MU_STREAM_QACCESS = 0x00000800
MU_STREAM_IRGRP = 0x00001000
MU_STREAM_IWGRP = 0x00002000
MU_STREAM_IROTH = 0x00004000
MU_STREAM_IWOTH = 0x00008000
MU_STREAM_IMASK = 0x0000F000
class Stream:
__refcount = 0
def __init__ (self, stm = None):
if isinstance (stm, stream.StreamType):
self.stm = stm
else:
self.stm = stream.StreamType ()
self.__reference ()
self.read_count = 0
self.write_count = 0
def __del__ (self):
if self.__dereference ():
stream.destroy (self.stm)
del self.stm
def __reference (self):
self.__refcount += 1
def __dereference (self):
self.__refcount -= 1
return self.__refcount == 0
def open (self):
status = stream.open (self.stm)
if status:
raise StreamError (status)
def close (self):
status = stream.close (self.stm)
if status:
raise StreamError (status)
def flush (self):
status = stream.flush (self.stm)
if status:
raise StreamError (status)
def wait (self, wflags):
status = stream.wait (self.stm, wflags)
if status:
raise StreamError (status)
def read (self, offset = 0):
status, rbuf, self.read_count = stream.read (self.stm, offset)
if status:
raise StreamError (status)
return rbuf
def write (self, wbuf, offset = 0):
status, self.write_count = stream.write (self.stm, wbuf, offset)
if status:
raise StreamError (status)
def readline (self, offset = 0):
status, rbuf, self.read_count = stream.readline (self.stm, offset)
if status:
raise StreamError (status)
return rbuf
def sequential_readline (self):
status, rbuf, self.read_count = stream.readline (self.stm)
if status:
raise StreamError (status)
return rbuf
def sequential_write (self, wbuf, size = None):
if size == None:
size = len (wbuf)
status = stream.sequential_write (self.stm, wbuf, size)
if status:
raise StreamError (status)
class TcpStream (Stream):
def __init__ (self, host, port, flags = MU_STREAM_READ):
Stream.__init__ (self)
status = stream.tcp_stream_create (self.stm, host, port, flags)
if status:
raise StreamError (status)
class FileStream (Stream):
def __init__ (self, filename, flags = MU_STREAM_READ):
Stream.__init__ (self)
status = stream.file_stream_create (self.stm, filename, flags)
if status:
raise StreamError (status)
class StdioStream (Stream):
def __init__ (self, file, flags = MU_STREAM_READ):
Stream.__init__ (self)
status = stream.stdio_stream_create (self.stm, file, flags)
if status:
raise StreamError (status)
class ProgStream (Stream):
def __init__ (self, progname, flags = MU_STREAM_READ):
Stream.__init__ (self)
status = stream.prog_stream_create (self.stm, progname, flags)
if status:
raise StreamError (status)
#
# GNU Mailutils -- a suite of utilities for electronic mail
# Copyright (C) 2009 Free Software Foundation, Inc.
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 3 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General
# Public License along with this library; if not, write to the
# Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
# Boston, MA 02110-1301 USA
#
from mailutils.c_api import url
from mailutils.error import *
class Url:
__owner = False
def __init__ (self, u):
if isinstance (u, url.UrlType):
self.url = u
else:
self.url = url.UrlType ()
self.__owner = True
status = url.create (self.url, u)
if status:
raise UrlError (status)
def __del__ (self):
if self.__owner:
url.destroy (self.url)
del self.url
def __str__ (self):
return url.to_string (self.url)
def parse (self):
"""Parses the url, after calling this the get functions
can be called."""
if self.__owner:
status = url.parse (self.url)
if status:
raise UrlError (status)
def get_port (self):
status, port = url.get_port (self.url)
if status:
raise UrlError (status)
return port
def get_scheme (self):
status, scheme = url.get_scheme (self.url)
if status == MU_ERR_NOENT:
return ''
elif status:
raise UrlError (status)
return scheme
def get_user (self):
status, user = url.get_user (self.url)
if status == MU_ERR_NOENT:
return ''
elif status:
raise UrlError (status)
return user
def get_passwd (self):
status, passwd = url.get_passwd (self.url)
if status == MU_ERR_NOENT:
return ''
elif status:
raise UrlError (status)
return passwd
def get_auth (self):
status, auth = url.get_auth (self.url)
if status == MU_ERR_NOENT:
return ''
elif status:
raise UrlError (status)
return auth
def get_host (self):
status, host = url.get_host (self.url)
if status == MU_ERR_NOENT:
return ''
elif status:
raise UrlError (status)
return host
def get_path (self):
status, path = url.get_path (self.url)
if status == MU_ERR_NOENT:
return ''
elif status:
raise UrlError (status)
return path
def get_query (self):
status, query = url.get_query (self.url)
if status == MU_ERR_NOENT:
return ''
elif status:
raise UrlError (status)
return query
#
# GNU Mailutils -- a suite of utilities for electronic mail
# Copyright (C) 2009 Free Software Foundation, Inc.
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 3 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General
# Public License along with this library; if not, write to the
# Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
# Boston, MA 02110-1301 USA
#
from mailutils.c_api import util
def get_user_email (name = None):
if name == None:
return util.get_user_email ()
else:
return util.get_user_email (name)
def set_user_email (email):
util.set_user_email (email)
def get_user_email_domain ():
status, domain = util.get_user_email_domain ()
return domain
def set_user_email_domain (domain):
util.set_user_email_domain (domain)
def tempname (tmpdir = None):
return util.tempname (tmpdir)
......@@ -11,5 +11,6 @@ ltmain.sh
mailutils.spec
mdate-sh
missing
py-compile
texinfo.tex
ylwrap
......