Commit fef67bbd fef67bbdc7399fb7b2820057431bd4d703686c73 by Wojciech Polak

Add new Python interface and example programs.

1 parent eb9e1ecf
Showing 77 changed files with 4854 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
*/
#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
*/
#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
*/
#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
*/
#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