From MAILER-DAEMON Fri Jan 07 17:44:37 2011
Received: from mailman by lists.gnu.org with archive (Exim 4.43)
	id 1PbL2z-0002CJ-IY
	for mharc-commit-mailutils@gnu.org; Fri, 07 Jan 2011 17:44:37 -0500
Received: from [140.186.70.92] (port=48765 helo=eggs.gnu.org)
	by lists.gnu.org with esmtp (Exim 4.43) id 1PbL2w-0001ha-5u
	for commit-mailutils@gnu.org; Fri, 07 Jan 2011 17:44:36 -0500
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1PbL2r-0003UY-4C
	for commit-mailutils@gnu.org; Fri, 07 Jan 2011 17:44:31 -0500
Received: from colonialone.fsf.org ([140.186.70.51]:35644
	helo=internal.in.savannah.gnu.org)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1PbL2r-0003US-1f
	for commit-mailutils@gnu.org; Fri, 07 Jan 2011 17:44:29 -0500
Received: from [10.1.0.108] (helo=vcs-noshell.in.savannah.gnu.org)
	by internal.in.savannah.gnu.org with esmtp (Exim 4.69)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1PbL3r-0008OO-4U
	for commit-mailutils@gnu.org; Fri, 07 Jan 2011 22:45:31 +0000
Received: from gray by vcs-noshell.in.savannah.gnu.org with local (Exim 4.69)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1PbL3h-0004pC-92
	for commit-mailutils@gnu.org; Fri, 07 Jan 2011 22:45:23 +0000
From: "Sergey Poznyakoff" <gray@gnu.org.ua>
To: commit-mailutils@gnu.org
X-Git-Refname: refs/heads/master
X-Git-Reftype: branch
X-Git-Oldrev: 284d8c5a28972234c51c8fa4a299e7f64b490d10
X-Git-Newrev: eb838fece8d5c38fb6fd4ea2b33d3982607acfff
Message-Id: <E1PbL3h-0004pC-92@vcs-noshell.in.savannah.gnu.org>
Date: Fri, 07 Jan 2011 22:45:22 +0000
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2)
Subject: [SCM] GNU Mailutils branch, master,
	updated. release-2.2-341-geb838fe
X-BeenThere: commit-mailutils@gnu.org
X-Mailman-Version: 2.1.5
Precedence: list
List-Id: Commit notices for GNU mailutils <commit-mailutils.gnu.org>
List-Unsubscribe: <http://lists.gnu.org/mailman/listinfo/commit-mailutils>,
	<mailto:commit-mailutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/commit-mailutils>
List-Post: <mailto:commit-mailutils@gnu.org>
List-Help: <mailto:commit-mailutils-request@gnu.org?subject=help>
List-Subscribe: <http://lists.gnu.org/mailman/listinfo/commit-mailutils>,
	<mailto:commit-mailutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Fri, 07 Jan 2011 22:44:36 -0000

This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "GNU Mailutils".

http://git.savannah.gnu.org/cgit/mailutils.git/commit/?id=eb838fece8d5c38fb6fd4ea2b33d3982607acfff

The branch, master has been updated
       via  eb838fece8d5c38fb6fd4ea2b33d3982607acfff (commit)
       via  273e66dcf41df1fc262629b85b4cde983681d6c4 (commit)
       via  91022df9ce5b2ffafaf1b602f028922dc77e35e4 (commit)
      from  284d8c5a28972234c51c8fa4a299e7f64b490d10 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit eb838fece8d5c38fb6fd4ea2b33d3982607acfff
Author: Sergey Poznyakoff <gray@gnu.org.ua>
Date:   Fri Jan 7 17:48:09 2011 +0200

    guimb: further improvements
    
    * libmu_scm/mu_body.c (mu-body?): New function.
    * libmu_scm/mu_mailbox.c (mu-mailbox?): New function.
    * libmu_scm/mu_message.c (mu-message?): New function.
    * libmu_scm/mu_mime.c (mu-mime?): New function.
    * scheme/guimb.scmi (guimb-process-mailbox): guimb-message returns
    a message to be appended to the output mailbox.

commit 273e66dcf41df1fc262629b85b4cde983681d6c4
Author: Sergey Poznyakoff <gray@gnu.org.ua>
Date:   Fri Jan 7 14:43:04 2011 +0200

    Reincarnate guimb as a pure Scheme program.
    
    * libmu_scm/mailutils.scm.in: Move to libmu_scm/mailutils/mailutils.scm.in.
    Use the MAILUTILS_SCM_LIBRARY_ROOT environment variable to load
    libraries from the specified location (to be used in tests).
    
    * libmu_scm/mailutils/.gitignore: New file.
    * libmu_scm/mailutils/Makefile.am: New file.
    * libmu_scm/Makefile.am (SUBDIRS): Add mailutils
    (mailutils.scm): Remove goal and associated variables.
    
    * scheme/guimb.scmi: New file. Reincarnation of guimb.
    * scheme/Makefile.am: Build guimb from guimb.scmi.
    * scheme/sieve2scm.scmi (sieve-version): Use mu-package
    and mu-version global variables.
    
    * configure.ac (AC_CONFIG_FILES): Add libmu_scm/mailutils/Makefile.

commit 91022df9ce5b2ffafaf1b602f028922dc77e35e4
Author: Sergey Poznyakoff <gray@gnu.org.ua>
Date:   Thu Jan 6 17:01:10 2011 +0200

    Minor changes in scheme-related code.
    
    * libmu_scm/mu_scm.c (_mu_scm_bugreport, mu-bugreport): New variable.
    (format_table): Add pops and imaps.
    * scheme/reject.scm: Minor changes.
    * scheme/sieve2scm.scmi: Minor changes.

-----------------------------------------------------------------------

Summary of changes:
 configure.ac                                 |    1 +
 libmu_scm/Makefile.am                        |   16 +-
 libmu_scm/mailutils/.gitignore               |    1 +
 {readmsg => libmu_scm/mailutils}/Makefile.am |   29 +--
 libmu_scm/{ => mailutils}/mailutils.scm.in   |   39 +++--
 libmu_scm/mu_body.c                          |    9 +
 libmu_scm/mu_mailbox.c                       |    9 +
 libmu_scm/mu_message.c                       |    9 +
 libmu_scm/mu_mime.c                          |    9 +
 libmu_scm/mu_scm.c                           |   10 +-
 scheme/Makefile.am                           |   28 ++-
 scheme/guimb.scmi                            |  289 ++++++++++++++++++++++++++
 scheme/reject.scm                            |    2 +-
 scheme/sieve2scm.scmi                        |    3 +-
 14 files changed, 396 insertions(+), 58 deletions(-)
 create mode 100644 libmu_scm/mailutils/.gitignore
 copy {readmsg => libmu_scm/mailutils}/Makefile.am (63%)
 rename libmu_scm/{ => mailutils}/mailutils.scm.in (56%)
 create mode 100644 scheme/guimb.scmi

diff --git a/configure.ac b/configure.ac
index 8650599..e03a4c3 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1364,6 +1364,7 @@ AC_CONFIG_FILES([
  libmu_cfg/Makefile
  libmu_cpp/Makefile
  libmu_scm/Makefile
+ libmu_scm/mailutils/Makefile
  libmu_sieve/Makefile
  libmu_sieve/extensions/Makefile
  libproto/Makefile
diff --git a/libmu_scm/Makefile.am b/libmu_scm/Makefile.am
index 0d3ff2f..b870486 100644
--- a/libmu_scm/Makefile.am
+++ b/libmu_scm/Makefile.am
@@ -15,6 +15,8 @@
 ## You should have received a copy of the GNU General Public License
 ## along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>.
 
+SUBDIRS = . mailutils
+
 INCLUDES = -I. @MU_LIB_COMMON_INCLUDES@ @GUILE_INCLUDES@
 
 lib_LTLIBRARIES=libmu_scm.la
@@ -48,8 +50,6 @@ libmu_scm_la_LIBADD = \
  ${MU_LIB_MAILUTILS}\
  @GUILE_LIBS@
 
-EXTRA_DIST=mailutils.scm mailutils.scm.in
-
 DOT_X_FILES=\
  mu_address.x\
  mu_body.x\
@@ -72,15 +72,9 @@ DOT_DOC_FILES=\
  mu_scm.doc\
  mu_util.doc 
 
+EXTRA_DIST=
 CLEANFILES=
-DISTCLEANFILES=\
- mailutils.scm
-
-mailutils.scm: mailutils.scm.in
-	$(AM_V_GEN)m4 -DVERSION=$(VERSION) -DLIBDIR=$(libdir) \
-	   -DSITEDIR=$(sitedir) \
-           -DBUILDDIR=$(top_builddir)/libmu_scm \
-            $(srcdir)/mailutils.scm.in > $@
+DISTCLEANFILES=
 
 install-data-hook:
 	 @here=`pwd`; \
@@ -93,7 +87,7 @@ install-data-hook:
 	 cd $$here
 
 sitedir   = @GUILE_SITE@/$(PACKAGE)
-site_DATA = mailutils.scm
+site_DATA =
 SUFFIXES=
 BUILT_SOURCES=
 include ../gint/gint.mk
diff --git a/libmu_scm/mailutils/.gitignore b/libmu_scm/mailutils/.gitignore
new file mode 100644
index 0000000..a3d6ed8
--- /dev/null
+++ b/libmu_scm/mailutils/.gitignore
@@ -0,0 +1 @@
+mailutils.scm
diff --git a/readmsg/Makefile.am b/libmu_scm/mailutils/Makefile.am
similarity index 63%
copy from readmsg/Makefile.am
copy to libmu_scm/mailutils/Makefile.am
index 2d9f392..9e46149 100644
--- a/readmsg/Makefile.am
+++ b/libmu_scm/mailutils/Makefile.am
@@ -1,5 +1,5 @@
 ## This file is part of GNU Mailutils.
-## Copyright (C) 2001, 2002, 2003, 2004, 2007, 2010, 2011 Free Software
+## Copyright (C) 2001, 2002, 2006, 2007, 2009, 2010, 2011 Free Software
 ## Foundation, Inc.
 ##
 ## GNU Mailutils is free software; you can redistribute it and/or
@@ -15,22 +15,17 @@
 ## You should have received a copy of the GNU General Public License
 ## along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>.
 
-INCLUDES = @MU_APP_COMMON_INCLUDES@ 
+EXTRA_DIST=mailutils.scm mailutils.scm.in
 
-SUBDIRS = . tests
+DISTCLEANFILES=\
+ mailutils.scm
 
-bin_PROGRAMS = readmsg
-readmsg_SOURCES = readmsg.c msglist.c readmsg.h
+sitedir   = @GUILE_SITE@/$(PACKAGE)
+site_DATA = mailutils.scm
+
+mailutils.scm: mailutils.scm.in
+	$(AM_V_GEN)m4 -DVERSION=$(VERSION) -DLIBDIR=$(libdir) \
+	   -DSITEDIR=$(sitedir) \
+           -DBUILDDIR=$(top_builddir)/libmu_scm \
+            $(srcdir)/mailutils.scm.in > $@
 
-readmsg_LDADD =\
- ${MU_APP_LIBRARIES}\
- ${MU_LIB_MBOX}\
- ${MU_LIB_IMAP}\
- ${MU_LIB_POP}\
- ${MU_LIB_NNTP}\
- ${MU_LIB_MH}\
- ${MU_LIB_MAILDIR}\
- ${MU_LIB_AUTH}\
- @MU_AUTHLIBS@\
- ${MU_LIB_MAILUTILS}\
- @MU_COMMON_LIBRARIES@
diff --git a/libmu_scm/mailutils.scm.in b/libmu_scm/mailutils/mailutils.scm.in
similarity index 56%
rename from libmu_scm/mailutils.scm.in
rename to libmu_scm/mailutils/mailutils.scm.in
index 3ee5bc7..6e955ed 100644
--- a/libmu_scm/mailutils.scm.in
+++ b/libmu_scm/mailutils/mailutils.scm.in
@@ -24,20 +24,31 @@ changequote([,])dnl
 (set! documentation-files (append documentation-files 
                                   (list "SITEDIR/guile-procedures.txt")))
 
-(define mu-libs (list "libmailutils"
-		      "libmu_auth"
-		      "libmu_mbox"
-		      "libmu_mh"
-		      "libmu_maildir"
-		      "libmu_pop"
-		      "libmu_imap"))
+(define mu-libs (list (cons "libmailutils"     "libmailutils")
+		      (cons "libmu_auth"       "libmu_auth")
+		      (cons "libproto/mbox"    "libmu_mbox")
+		      (cons "libproto/mh"      "libmu_mh")
+		      (cons "libproto/maildir" "libmu_maildir")
+		      (cons "libproto/pop"     "libmu_pop")
+		      (cons "libproto/imap"    "libmu_imap")))
 
-(let ((lib-path "LIBDIR/"))
-  (for-each
-   (lambda (lib)
-	   (dynamic-link (string-append lib-path lib)))
-   mu-libs)
-  (load-extension (string-append
-		   lib-path "libguile-mailutils-v-VERSION") "mu_scm_init"))
+(cond
+ ((getenv "MAILUTILS_SCM_LIBRARY_ROOT") =>
+  (lambda (root)
+    (for-each
+     (lambda (lib)
+       (dynamic-link (string-append root "/" (car lib) "/" (cdr lib))))
+     mu-libs)
+    (load-extension (string-append root "/libmu_scm/libmu_scm")
+		    "mu_scm_init")))
+ (else
+  (let ((lib-path "LIBDIR/"))
+    (for-each
+     (lambda (lib)
+       (dynamic-link (string-append lib-path (cdr lib))))
+     mu-libs)
+    (load-extension (string-append
+		     lib-path "libguile-mailutils-v-VERSION")
+		    "mu_scm_init"))))
 
 ;;;; End of mailutils.scm
diff --git a/libmu_scm/mu_body.c b/libmu_scm/mu_body.c
index 007040b..8dbe42c 100644
--- a/libmu_scm/mu_body.c
+++ b/libmu_scm/mu_body.c
@@ -95,6 +95,15 @@ mu_scm_body_create (SCM msg, mu_body_t body)
 /* ************************************************************************* */
 /* Guile primitives */
 
+SCM_DEFINE_PUBLIC (scm_mu_body_p, "mu-body?", 1, 0, 0,
+		   (SCM scm),
+"Return @code{true} if @var{scm} is a Mailutils message body object.\n")
+#define FUNC_NAME s_scm_mu_body_p
+{
+  return mu_scm_is_body (scm);
+}
+#undef FUNC_NAME
+
 SCM_DEFINE_PUBLIC (scm_mu_body_read_line, "mu-body-read-line", 1, 0, 0,
 	    (SCM body), 
 	    "Read next line from the @var{body}.")
diff --git a/libmu_scm/mu_mailbox.c b/libmu_scm/mu_mailbox.c
index 7703216..df1aa47 100644
--- a/libmu_scm/mu_mailbox.c
+++ b/libmu_scm/mu_mailbox.c
@@ -136,6 +136,15 @@ mu_scm_is_mailbox (SCM scm)
 /* ************************************************************************* */
 /* Guile primitives */
 
+SCM_DEFINE_PUBLIC (scm_mu_mailbox_p, "mu-mailbox?", 1, 0, 0,
+		   (SCM scm),
+"Return @code{true} if @var{scm} is a Mailutils mailbox.\n")
+#define FUNC_NAME s_scm_mu_mailbox_p
+{
+  return scm_from_bool (mu_scm_is_mailbox (scm));
+}
+#undef FUNC_NAME
+
 SCM_DEFINE_PUBLIC (scm_mu_mail_directory, "mu-mail-directory", 0, 1, 0,
 		   (SCM url), 
 "Do not use this function. Use mu-user-mailbox-url instead.")
diff --git a/libmu_scm/mu_message.c b/libmu_scm/mu_message.c
index 08bc1d1..4a99a8e 100644
--- a/libmu_scm/mu_message.c
+++ b/libmu_scm/mu_message.c
@@ -175,6 +175,15 @@ mu_scm_is_message (SCM scm)
 /* ************************************************************************* */
 /* Guile primitives */
 
+SCM_DEFINE_PUBLIC (scm_mu_message_p, "mu-message?", 1, 0, 0,
+		   (SCM scm),
+"Return @code{true} if @var{scm} is a Mailutils message.\n")
+#define FUNC_NAME s_scm_mu_message_p
+{
+  return scm_from_bool (mu_scm_is_message (scm));
+}
+#undef FUNC_NAME
+
 SCM_DEFINE_PUBLIC (scm_mu_message_create, "mu-message-create", 0, 0, 0,
 		   (),
 		   "Creates an empty message.\n")
diff --git a/libmu_scm/mu_mime.c b/libmu_scm/mu_mime.c
index aefc455..1d29498 100644
--- a/libmu_scm/mu_mime.c
+++ b/libmu_scm/mu_mime.c
@@ -88,6 +88,15 @@ mu_scm_is_mime (SCM scm)
 /* ************************************************************************* */
 /* Guile primitives */
 
+SCM_DEFINE_PUBLIC (scm_mu_mime_p, "mu-mime?", 1, 0, 0,
+		   (SCM scm),
+"Return @code{true} if @var{scm} is a Mailutils MIME object.\n")
+#define FUNC_NAME s_scm_mu_mime_p
+{
+  return scm_from_bool (mu_scm_is_mime (scm));
+}
+#undef FUNC_NAME
+
 SCM_DEFINE_PUBLIC (scm_mu_mime_create, "mu-mime-create", 0, 2, 0,
 		   (SCM flags, SCM mesg),
 "Creates a new @acronym{MIME} object.  Both arguments are optional.\n"
diff --git a/libmu_scm/mu_scm.c b/libmu_scm/mu_scm.c
index d9c4aee..9e43506 100644
--- a/libmu_scm/mu_scm.c
+++ b/libmu_scm/mu_scm.c
@@ -36,10 +36,12 @@ mu_scm_error (const char *func_name, int status,
 SCM _mu_scm_package_string; /* STRING: PACKAGE_STRING */
 SCM _mu_scm_package;        /* STRING: PACKAGE */
 SCM _mu_scm_version;        /* STRING: VERSION */
+SCM _mu_scm_bugreport;      /* STRING: PACKAGE_BUGREPORT */
 SCM _mu_scm_mailer;         /* STRING: Default mailer path. */
 SCM _mu_scm_debug;          /* NUM: Default debug level. */
 
-struct format_record {
+struct format_record
+{
   char *name;
   mu_record_t *record;
 };
@@ -49,7 +51,9 @@ static struct format_record format_table[] = {
   { "mh",   &mu_mh_record },
   { "maildir", &mu_maildir_record },
   { "pop",  &mu_pop_record },
+  { "pops",  &mu_pops_record },
   { "imap", &mu_imap_record },
+  { "imaps", &mu_imap_record },
   { "sendmail", &mu_sendmail_record },
   { "smtp", &mu_smtp_record },
   { NULL, NULL },
@@ -185,6 +189,10 @@ mu_scm_init ()
   _mu_scm_package_string = scm_from_locale_string (PACKAGE_STRING);
   scm_c_define ("mu-package-string", _mu_scm_package_string);
   scm_c_export ("mu-package-string", NULL);
+
+  _mu_scm_bugreport = scm_from_locale_string (PACKAGE_BUGREPORT);
+  scm_c_define ("mu-bugreport", _mu_scm_bugreport);
+  scm_c_export ("mu-bugreport", NULL);
   
   /* Create MU- attribute names */
   for (i = 0; attr_kw[i].name; i++)
diff --git a/scheme/Makefile.am b/scheme/Makefile.am
index c0e0023..c146dfb 100644
--- a/scheme/Makefile.am
+++ b/scheme/Makefile.am
@@ -15,8 +15,8 @@
 ## You should have received a copy of the GNU General Public License
 ## along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. 
 
-bin_SCRIPTS = sieve2scm
-EXTRA_SCRIPTS=sieve2scm
+bin_SCRIPTS = sieve2scm guimb
+
 # FIXME: Sieve2scm is temporarly exempted from installchecks because
 # it may fail starting during checks, if libguile-mailutils-v- library
 # has not been previously installed. The proper fix would be to alter
@@ -25,19 +25,23 @@ AM_INSTALLCHECK_STD_OPTIONS_EXEMPT=sieve2scm
 
 sievemoddir=@MU_GUILE_SIEVE_MOD_DIR@
 
-sieve2scm: sieve2scm.scmi sieve.sed
-	$(AM_V_GEN)sed -f sieve.sed $(srcdir)/sieve2scm.scmi > sieve2scm
+sieve2scm: sieve2scm.scmi package.sed
+	$(AM_V_GEN)sed -f package.sed $(srcdir)/sieve2scm.scmi > sieve2scm
 	$(AM_V_at)chmod +w sieve2scm
 
-sieve.sed: Makefile
-	$(AM_V_GEN)echo 's,%GUILE_BINDIR%,@GUILE_BINDIR@,g' > sieve.sed
-	$(AM_V_at)echo 's,%BINDIR%,$(bindir),g' >> sieve.sed
-	$(AM_V_at)echo 's,%GUILE_SITE%,$(GUILE_SITE),g' >> sieve.sed
-	$(AM_V_at)echo 's,%LIBDIR%,$(sievemoddir),g' >> sieve.sed
-	$(AM_V_at)echo 's,%PACKAGE%,$(PACKAGE),g' >> sieve.sed
-	$(AM_V_at)echo 's,%VERSION%,$(VERSION),g' >> sieve.sed
+guimb: guimb.scmi package.sed
+	$(AM_V_GEN)sed -f package.sed $(srcdir)/guimb.scmi > guimb
+	$(AM_V_at)chmod +w guimb
+
+package.sed: Makefile
+	$(AM_V_GEN)echo 's,%GUILE_BINDIR%,@GUILE_BINDIR@,g' > package.sed
+	$(AM_V_at)echo 's,%BINDIR%,$(bindir),g' >> package.sed
+	$(AM_V_at)echo 's,%GUILE_SITE%,$(GUILE_SITE),g' >> package.sed
+	$(AM_V_at)echo 's,%LIBDIR%,$(sievemoddir),g' >> package.sed
+	$(AM_V_at)echo 's,%PACKAGE%,$(PACKAGE),g' >> package.sed
+	$(AM_V_at)echo 's,%VERSION%,$(VERSION),g' >> package.sed
 
-CLEANFILES = sieve2scm sieve.sed
+CLEANFILES = sieve2scm guimb package.sed
 
 sitedir=@GUILE_SITE@/$(PACKAGE)
 site_DATA=sieve-core.scm
diff --git a/scheme/guimb.scmi b/scheme/guimb.scmi
new file mode 100644
index 0000000..dfee888
--- /dev/null
+++ b/scheme/guimb.scmi
@@ -0,0 +1,289 @@
+#! /bin/sh
+# aside from this initial boilerplate, this is actually -*- scheme -*- code
+main='(module-ref (resolve-module '\''(scheme guimb)) '\'main')'
+exec ${GUILE-guile} -l $0 -c "(apply $main (list (command-line)))" "$@"
+!#
+;;;; GNU Mailutils -- a suite of utilities for electronic mail
+;;;; Copyright (C) 1999, 2000, 2001, 2006, 2007, 2009, 2010, 2011 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, see <http://www.gnu.org/licenses/>.
+;;;;
+(if (not (member "%GUILE_SITE%" %load-path))
+    (set! %load-path (cons "%GUILE_SITE%" %load-path)))
+(define-module (scheme guimb)
+  :export (guimb))
+
+(use-modules (ice-9 getopt-long)
+	     (ice-9 rdelim)
+	     (srfi srfi-1)
+	     (mailutils mailutils))
+
+(define program-name "guimb")
+(define output-mailbox-name #f)
+(define output-mailbox-mode #f)
+(define source-file-name #f)
+(define source-expression #f)
+(define user-name #f)
+(define input-mailbox-names '())
+(define script-arguments '())
+
+(define output-mailbox #f)
+
+(define (guimb-version)
+  (format #t "guimb (~A) ~A~%" mu-package mu-version)
+  (exit 0))
+
+(define (guimb-help)
+  (format #t "usage: guimb [OPTIONS] [MAILBOX [MAILBOX...]]
+guimb applies a scheme function to each message from a set of input mailboxes
+
+The following options stop argument processing, and pass the remaining
+arguments to the guimb-getopt function, if it is defined in the module:
+
+  -c, --code=EXPR            execute given Scheme expression
+  -s, --source=MODNAME       load Scheme module MODNAME
+
+The following options have the same effect, but do not affect further
+options parsing:
+
+  -e, --expression=EXPR      execute given Scheme expression
+  -f, --file=MODNAME         load Scheme module MODNAME
+
+The module to be loaded is normally defined in a file named MODNAME.scm
+somewhere in your %load-path.
+
+Other options:
+
+  -M, --mailbox=NAME         set output mailbox name
+  -u, --user[=NAME]          direct output to the system mailbox of the
+                             user NAME (default - current user)
+  -r, --read-only            open mailbox in read-only mode
+
+Script arguments:
+
+  -g, --guile-arg=ARG        append ARG to the command line passed to script
+  -{ args... -}              append args to the command line passed to script
+  --lparen args... --rparen  likewise
+
+  -L, --load-path=PATH       append PATH to the beginning of the %load-path
+
+  -?, --help                 give this help list
+      --usage                give a short usage message
+  -V, --version              print program version
+
+Mandatory or optional arguments to long options are also mandatory or optional
+for any corresponding short options.
+
+")
+  (format #t "Report bugs to <~A>.~%" mu-bugreport)
+  (exit 0))
+
+(define (guimb-usage)
+  ; FIXME
+  (guimb-help))
+
+(define (error fmt . rest)
+  (with-output-to-port
+      (current-error-port)
+    (lambda ()
+      (format #t "~A: " program-name)
+      (apply format #t fmt rest)
+      (newline))))
+
+(define (extract-args arglist)
+  (let ((level 0))
+    (let ((result (filter
+		   (lambda (x)
+		     (cond
+		      ((or (string=? x "--lparen")
+			   (string=? x "-{"))
+		       (set! level (+ level 1))
+		       #f)
+		      ((or (string=? x "--rparen")
+			   (string=? x "-}"))
+		       (if (> level 0)
+			   (set! level (- level 1))
+			   (set! script-arguments (append script-arguments
+							  (list x))))
+		       #f)
+		      ((> level 0)
+		       (set! script-arguments (append script-arguments
+						      (list x)))
+		       #f)
+		      (else
+		       #t)))
+		   arglist)))
+      (if (> level 0)
+	  (error "missing closing -}"))
+      result)))
+		
+(define (parse-cmdline cmdline)
+  (let ((grammar `((source      (single-char #\s)
+				(value #t))
+		   (code        (single-char #\c)
+				(value #t))
+		   (file        (single-char #\f)
+				(value #t))
+		   (expression  (single-char #\e)
+				(value #t))
+		   (mailbox     (single-char #\M)
+				(value #t))
+		   (user        (single-char #\u)
+				(value optional))
+		   (read-only   (single-char #\r))
+		   (guile-arg   (single-char #\g)
+				(value #t))
+		   (load-path   (single-char #\L)
+				(value #t))
+		   (help        (single-char #\?))
+		   (usage)
+		   (version     (single-char #\V)))))
+    (do ((arglist (getopt-long (extract-args (command-line)) grammar)
+		  (cdr arglist)))
+	((null? arglist))
+      (let ((x (car arglist)))
+	(case (car x)
+	  ((mailbox)
+	   (set! output-mailbox-name (cdr x)))
+	  ((source file)
+	   (set! source-file-name (cdr x)))
+	  ((code expression)
+	   (set! source-expression (cdr x)))
+	  ((load-path)
+	   (set! %load-path (append
+			     (string-split (cdr x) #\:)
+			     %load-path)))
+	  ((user)
+	   (set! user-name (cdr x)))
+	  ((guile-arg)
+	   (set! script-arguments (append script-arguments (list (cdr x)))))
+	  ((version)
+	   (guimb-version))
+	  ((help)
+	   (guimb-help))
+	  ((usage)
+	   (guimb-usage))
+	  ((read-only)
+	   (set! output-mailbox-mode "r"))
+	  ('()
+	   (if (not (null? (cdr x)))
+	       (set! input-mailbox-names (append input-mailbox-names
+						 (cdr x))))))))))
+
+(define guimb-module #f)
+
+(define (get-module)
+    (if (not guimb-module)
+	(set! guimb-module (resolve-module '(scheme guimb))))
+    guimb-module)
+
+(define-macro (bound? name)
+  `(and (module-defined? guimb-module ',name)
+	(procedure? ,name)))
+
+(define (guimb-parse-command-line cmdline)
+  (let ((script-args '())
+	(argtail (find-tail
+		  (lambda (x)
+		    (or (string=? x "-c")
+			(string=? x "--code")
+			(string=? x "-s")
+			(string=? x "--source")
+			(string-prefix? "--code=" x)
+			(string-prefix? "--source=" x)))
+		  cmdline)))
+    (cond
+     (argtail
+      (if (let ((x (car argtail)))
+	    (not (or (string-prefix? "--code=" x)
+		     (string-prefix? "--source=" x))))
+	  (set! argtail (cdr argtail)))
+      (cond ((not (null? argtail))
+	     (set! script-args (cdr argtail))
+	     (set-cdr! argtail '())))))
+    (parse-cmdline cmdline)
+    (set! script-arguments (append script-arguments script-args))
+
+    (if (not output-mailbox-mode)
+	(set! output-mailbox-mode (if (null? input-mailbox-names) "wr" "a")))
+    
+    (cond
+     (user-name
+      (set! output-mailbox
+	    (mu-mailbox-open
+	     (if (string? user-name)
+		 (string-append "%" user-name)
+		 "")
+	     output-mailbox-mode)))
+     (output-mailbox-name
+      (set! output-mailbox (mu-mailbox-open output-mailbox-name
+					    output-mailbox-mode))))
+;    (write output-mailbox)(newline)
+
+    (if source-file-name
+	(module-use!
+	 (get-module)
+	 (resolve-interface (list (string->symbol source-file-name)))))
+    (if source-expression
+	(eval-string source-expression))
+
+    (if (bound? guimb-getopt)
+	(guimb-getopt script-arguments)) ))
+
+(define (guimb-single-mailbox mbox)
+  (let msg-loop ((msg (mu-mailbox-first-message mbox)))
+    (if (not (eof-object? msg))
+	(begin
+	  (guimb-message msg)
+	  (msg-loop (mu-mailbox-next-message mbox))))))
+  
+(define (guimb-process-mailbox mbox)
+  (if (not output-mailbox)
+      (guimb-single-mailbox mbox)
+      (let msg-loop ((msg (mu-mailbox-first-message mbox)))
+	(if (not (eof-object? msg))
+	    (let ((x (guimb-message msg)))
+	      (if (mu-message? x)
+		  (mu-mailbox-append-message output-mailbox x))
+	      (msg-loop (mu-mailbox-next-message mbox)))))))
+
+(define (guimb cmdline)
+  (mu-register-format)
+  (guimb-parse-command-line cmdline)
+  (if (null? input-mailbox-names)
+    (guimb-single-mailbox output-mailbox)
+    (for-each
+     (lambda (mbox-name)
+       (let ((current-mailbox (mu-mailbox-open mbox-name "r")))
+	 (guimb-process-mailbox current-mailbox)))
+     input-mailbox-names))
+  (if (bound? guimb-end)
+      (guimb-end)))
+
+(debug-enable 'debug)
+(debug-options '(show-file-name #t
+		 stack 20000
+		 debug
+		 backtrace
+		 depth 20
+		 maxdepth 1000
+		 frames 3
+		 indent 10
+		 width 79
+		 procnames))
+
+(define main guimb)
+
+;;;; End of guimb
diff --git a/scheme/reject.scm b/scheme/reject.scm
index a418d4b..117031f 100644
--- a/scheme/reject.scm
+++ b/scheme/reject.scm
@@ -50,7 +50,7 @@
 	    (port (mu-message-get-port mesg "w")))
        (mu-message-set-header mesg "Content-Type" "message/delivery-status")
        
-       (display (string-append "Reporting-UA: sieve; GNU "
+       (display (string-append "Reporting-UA: sieve; "
 			       mu-package-string "\n") port)
        (display (string-append "Arrival-Date: " datestr "\n") port)
        (newline port)
diff --git a/scheme/sieve2scm.scmi b/scheme/sieve2scm.scmi
index 5c9cf49..6d2c85d 100644
--- a/scheme/sieve2scm.scmi
+++ b/scheme/sieve2scm.scmi
@@ -995,8 +995,7 @@ exec ${GUILE-guile} -l $0 -c '(mailutils-main)'\n")
   (exit 0))
 
 (define (sieve-version)
-  (display "sieve.scm (GNU %PACKAGE% %VERSION%)")
-  (newline)
+  (format #t "sieve2scm (~A) ~A~%" mu-package mu-version)
   (exit 0))
 
 ;;; Parse command line 


hooks/post-receive
-- 
GNU Mailutils


From MAILER-DAEMON Sun Jan 09 06:24:12 2011
Received: from mailman by lists.gnu.org with archive (Exim 4.43)
	id 1PbtNc-0008Rg-SC
	for mharc-commit-mailutils@gnu.org; Sun, 09 Jan 2011 06:24:12 -0500
Received: from [140.186.70.92] (port=42276 helo=eggs.gnu.org)
	by lists.gnu.org with esmtp (Exim 4.43) id 1PbtNa-0008Rb-Kq
	for commit-mailutils@gnu.org; Sun, 09 Jan 2011 06:24:11 -0500
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1PbtNZ-0002w0-C6
	for commit-mailutils@gnu.org; Sun, 09 Jan 2011 06:24:10 -0500
Received: from colonialone.fsf.org ([140.186.70.51]:50316
	helo=internal.in.savannah.gnu.org)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1PbtNZ-0002vp-AX
	for commit-mailutils@gnu.org; Sun, 09 Jan 2011 06:24:09 -0500
Received: from [10.1.0.108] (helo=vcs-noshell.in.savannah.gnu.org)
	by internal.in.savannah.gnu.org with esmtp (Exim 4.69)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1PbtOd-0007Kw-Sj
	for commit-mailutils@gnu.org; Sun, 09 Jan 2011 11:25:16 +0000
Received: from gray by vcs-noshell.in.savannah.gnu.org with local (Exim 4.69)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1PbtOU-0006C6-QM
	for commit-mailutils@gnu.org; Sun, 09 Jan 2011 11:25:07 +0000
From: "Sergey Poznyakoff" <gray@gnu.org.ua>
To: commit-mailutils@gnu.org
X-Git-Refname: refs/heads/master
X-Git-Reftype: branch
X-Git-Oldrev: eb838fece8d5c38fb6fd4ea2b33d3982607acfff
X-Git-Newrev: 523bea73592f869effa7300b0c703219c66d7386
Message-Id: <E1PbtOU-0006C6-QM@vcs-noshell.in.savannah.gnu.org>
Date: Sun, 09 Jan 2011 11:25:07 +0000
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2)
Subject: [SCM] GNU Mailutils branch, master,
	updated. release-2.2-342-g523bea7
X-BeenThere: commit-mailutils@gnu.org
X-Mailman-Version: 2.1.5
Precedence: list
List-Id: Commit notices for GNU mailutils <commit-mailutils.gnu.org>
List-Unsubscribe: <http://lists.gnu.org/mailman/listinfo/commit-mailutils>,
	<mailto:commit-mailutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/commit-mailutils>
List-Post: <mailto:commit-mailutils@gnu.org>
List-Help: <mailto:commit-mailutils-request@gnu.org?subject=help>
List-Subscribe: <http://lists.gnu.org/mailman/listinfo/commit-mailutils>,
	<mailto:commit-mailutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Sun, 09 Jan 2011 11:24:11 -0000

This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "GNU Mailutils".

http://git.savannah.gnu.org/cgit/mailutils.git/commit/?id=523bea73592f869effa7300b0c703219c66d7386

The branch, master has been updated
       via  523bea73592f869effa7300b0c703219c66d7386 (commit)
      from  eb838fece8d5c38fb6fd4ea2b33d3982607acfff (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 523bea73592f869effa7300b0c703219c66d7386
Author: Sergey Poznyakoff <gray@gnu.org.ua>
Date:   Sun Jan 9 13:22:47 2011 +0200

    imap4d: complement 435f1918df.
    
    * imap4d/bye.c (imap4d_bye0): Set iostream to NULL, to avoid
    further delivery of the SIGPIPE.

-----------------------------------------------------------------------

Summary of changes:
 imap4d/bye.c |    8 ++++++++
 1 files changed, 8 insertions(+), 0 deletions(-)

diff --git a/imap4d/bye.c b/imap4d/bye.c
index 541aa0d..d5f4086 100644
--- a/imap4d/bye.c
+++ b/imap4d/bye.c
@@ -112,6 +112,14 @@ imap4d_bye0 (int reason, struct imap4d_command *command)
       mu_set_signals (sigpipe, sigtab, MU_ARRAY_SIZE (sigtab));
       if (setjmp (pipejmp) == 0)
 	io_completion_response (command, RESP_OK, "Completed");
+      else
+	/* Invalidate iostream. This creates a mild memory leak, as the
+	   stream is not destroyed by util_bye, but at least this avoids
+	   endless loop which would happen when mu_stream_flush would
+	   try to flush buffers on an already broken pipe.
+	   FIXME: There must be a special function for that, I guess.
+	   Something like mu_stream_invalidate. */
+	iostream = NULL;
     }
   
   util_bye ();


hooks/post-receive
-- 
GNU Mailutils


From MAILER-DAEMON Fri Jan 14 10:35:23 2011
Received: from mailman by lists.gnu.org with archive (Exim 4.43)
	id 1PdlgR-0002P1-4u
	for mharc-commit-mailutils@gnu.org; Fri, 14 Jan 2011 10:35:23 -0500
Received: from [140.186.70.92] (port=43221 helo=eggs.gnu.org)
	by lists.gnu.org with esmtp (Exim 4.43) id 1PdlgO-0002Oa-Ow
	for commit-mailutils@gnu.org; Fri, 14 Jan 2011 10:35:21 -0500
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1PdlgM-0001EG-Qk
	for commit-mailutils@gnu.org; Fri, 14 Jan 2011 10:35:20 -0500
Received: from colonialone.fsf.org ([140.186.70.51]:35941
	helo=internal.in.savannah.gnu.org)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1PdlgM-0001E5-P1
	for commit-mailutils@gnu.org; Fri, 14 Jan 2011 10:35:18 -0500
Received: from [10.1.0.108] (helo=vcs-noshell.in.savannah.gnu.org)
	by internal.in.savannah.gnu.org with esmtp (Exim 4.69)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1PdlgM-0007Zx-3P
	for commit-mailutils@gnu.org; Fri, 14 Jan 2011 15:35:18 +0000
Received: from gray by vcs-noshell.in.savannah.gnu.org with local (Exim 4.69)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1PdlgL-0001dK-7Y
	for commit-mailutils@gnu.org; Fri, 14 Jan 2011 15:35:17 +0000
From: "Sergey Poznyakoff" <gray@gnu.org.ua>
To: commit-mailutils@gnu.org
X-Git-Refname: refs/heads/master
X-Git-Reftype: branch
X-Git-Oldrev: 523bea73592f869effa7300b0c703219c66d7386
X-Git-Newrev: c7376cec212fc20f39388a216f29661975b109cf
Message-Id: <E1PdlgL-0001dK-7Y@vcs-noshell.in.savannah.gnu.org>
Date: Fri, 14 Jan 2011 15:35:17 +0000
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2)
Subject: [SCM] GNU Mailutils branch, master,
	updated. release-2.2-343-gc7376ce
X-BeenThere: commit-mailutils@gnu.org
X-Mailman-Version: 2.1.5
Precedence: list
List-Id: Commit notices for GNU mailutils <commit-mailutils.gnu.org>
List-Unsubscribe: <http://lists.gnu.org/mailman/listinfo/commit-mailutils>,
	<mailto:commit-mailutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/commit-mailutils>
List-Post: <mailto:commit-mailutils@gnu.org>
List-Help: <mailto:commit-mailutils-request@gnu.org?subject=help>
List-Subscribe: <http://lists.gnu.org/mailman/listinfo/commit-mailutils>,
	<mailto:commit-mailutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Fri, 14 Jan 2011 15:35:21 -0000

This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "GNU Mailutils".

http://git.savannah.gnu.org/cgit/mailutils.git/commit/?id=c7376cec212fc20f39388a216f29661975b109cf

The branch, master has been updated
       via  c7376cec212fc20f39388a216f29661975b109cf (commit)
      from  523bea73592f869effa7300b0c703219c66d7386 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit c7376cec212fc20f39388a216f29661975b109cf
Author: Sergey Poznyakoff <gray@gnu.org.ua>
Date:   Fri Jan 14 17:32:58 2011 +0200

    imap4d: don't issue spurious unsolicited responses after EXPUNGE.
    
    * imap4d/expunge.c (imap4d_expunge): Clear attribute table before
    resynching.
    * imap4d/imap4d.h (imap4d_sync_invalidate): New extern.
    * imap4d/sync.c (invalidate_attr_table): Rename to imap4d_sync_invalidate;
    make extern. All callers updated.

-----------------------------------------------------------------------

Summary of changes:
 imap4d/expunge.c |    1 +
 imap4d/imap4d.h  |    1 +
 imap4d/sync.c    |    8 ++++----
 3 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/imap4d/expunge.c b/imap4d/expunge.c
index 3893ffa..d9e5279 100644
--- a/imap4d/expunge.c
+++ b/imap4d/expunge.c
@@ -39,6 +39,7 @@ imap4d_expunge (struct imap4d_command *command, imap4d_tokbuf_t tok)
   /* FIXME: check for errors.  */
   mu_mailbox_expunge (mbox);
 
+  imap4d_sync_invalidate ();
   imap4d_sync ();
   return io_completion_response (command, RESP_OK, "Completed");
 }
diff --git a/imap4d/imap4d.h b/imap4d/imap4d.h
index fd60c59..61e0829 100644
--- a/imap4d/imap4d.h
+++ b/imap4d/imap4d.h
@@ -324,6 +324,7 @@ int make_interdir (const char *name, int delim, int perms);
 
 /* Synchronisation on simultaneous access.  */
 extern int imap4d_sync (void);
+extern void imap4d_sync_invalidate (void);
 extern int imap4d_sync_flags (size_t);
 extern size_t uid_to_msgno (size_t);
 extern void imap4d_set_observer (mu_mailbox_t mbox);
diff --git a/imap4d/sync.c b/imap4d/sync.c
index 8539efe..aac7ae1 100644
--- a/imap4d/sync.c
+++ b/imap4d/sync.c
@@ -39,8 +39,8 @@ realloc_attributes (size_t total)
   attr_table_count = total;
 }
 
-static void
-invalidate_attr_table ()
+void
+imap4d_sync_invalidate ()
 {
   attr_table_valid = 0;
   attr_table_count = 0;
@@ -191,7 +191,7 @@ imap4d_sync (void)
      It may be because of close or before select/examine a new mailbox.
      If it was a close we do not send any notification.  */
   if (mbox == NULL)
-    invalidate_attr_table ();
+    imap4d_sync_invalidate ();
   else if (!attr_table_valid || !mu_mailbox_is_updated (mbox))
     {
       if (mailbox_corrupt)
@@ -205,7 +205,7 @@ imap4d_sync (void)
 	  if (status)
 	    imap4d_bye (ERR_MAILBOX_CORRUPTED);
 	  imap4d_set_observer (mbox);
-	  invalidate_attr_table ();
+	  imap4d_sync_invalidate ();
 	  mailbox_corrupt = 0;
 	  io_untagged_response (RESP_NONE,
 		             "OK [ALERT] Mailbox modified by another program");


hooks/post-receive
-- 
GNU Mailutils


From MAILER-DAEMON Sat Jan 15 09:56:03 2011
Received: from mailman by lists.gnu.org with archive (Exim 4.43)
	id 1Pe7Xv-000797-P3
	for mharc-commit-mailutils@gnu.org; Sat, 15 Jan 2011 09:56:03 -0500
Received: from [140.186.70.92] (port=49099 helo=eggs.gnu.org)
	by lists.gnu.org with esmtp (Exim 4.43) id 1Pe7Xl-00070c-9V
	for commit-mailutils@gnu.org; Sat, 15 Jan 2011 09:56:03 -0500
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1Pe7Xc-00035o-WB
	for commit-mailutils@gnu.org; Sat, 15 Jan 2011 09:55:53 -0500
Received: from colonialone.fsf.org ([140.186.70.51]:53236
	helo=internal.in.savannah.gnu.org)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1Pe7Xc-00035a-Tq
	for commit-mailutils@gnu.org; Sat, 15 Jan 2011 09:55:44 -0500
Received: from [10.1.0.108] (helo=vcs-noshell.in.savannah.gnu.org)
	by internal.in.savannah.gnu.org with esmtp (Exim 4.69)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1Pe7Xc-0006uE-Gl
	for commit-mailutils@gnu.org; Sat, 15 Jan 2011 14:55:44 +0000
Received: from gray by vcs-noshell.in.savannah.gnu.org with local (Exim 4.69)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1Pe7XZ-0001Jg-6m
	for commit-mailutils@gnu.org; Sat, 15 Jan 2011 14:55:44 +0000
From: "Sergey Poznyakoff" <gray@gnu.org.ua>
To: commit-mailutils@gnu.org
X-Git-Refname: refs/heads/master
X-Git-Reftype: branch
X-Git-Oldrev: c7376cec212fc20f39388a216f29661975b109cf
X-Git-Newrev: ec0d5f94acb17be7357a6a819a706189b02cf2da
Message-Id: <E1Pe7XZ-0001Jg-6m@vcs-noshell.in.savannah.gnu.org>
Date: Sat, 15 Jan 2011 14:55:44 +0000
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2)
Subject: [SCM] GNU Mailutils branch, master,
	updated. release-2.2-345-gec0d5f9
X-BeenThere: commit-mailutils@gnu.org
X-Mailman-Version: 2.1.5
Precedence: list
List-Id: Commit notices for GNU mailutils <commit-mailutils.gnu.org>
List-Unsubscribe: <http://lists.gnu.org/mailman/listinfo/commit-mailutils>,
	<mailto:commit-mailutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/commit-mailutils>
List-Post: <mailto:commit-mailutils@gnu.org>
List-Help: <mailto:commit-mailutils-request@gnu.org?subject=help>
List-Subscribe: <http://lists.gnu.org/mailman/listinfo/commit-mailutils>,
	<mailto:commit-mailutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Sat, 15 Jan 2011 14:56:03 -0000

This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "GNU Mailutils".

http://git.savannah.gnu.org/cgit/mailutils.git/commit/?id=ec0d5f94acb17be7357a6a819a706189b02cf2da

The branch, master has been updated
       via  ec0d5f94acb17be7357a6a819a706189b02cf2da (commit)
       via  18de516a00c01a4262310f09a1ac8586e97f8a1a (commit)
      from  c7376cec212fc20f39388a216f29661975b109cf (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit ec0d5f94acb17be7357a6a819a706189b02cf2da
Author: Sergey Poznyakoff <gray@gnu.org.ua>
Date:   Sat Jan 15 15:44:06 2011 +0200

    libmailutils: bugfix
    
    * libmailutils/mime/attachment.c (_attachment_setup): Remove improper
    initialization of msg.
    (mu_message_encapsulate): Initialize info->msg.

commit 18de516a00c01a4262310f09a1ac8586e97f8a1a
Author: Sergey Poznyakoff <gray@gnu.org.ua>
Date:   Sat Jan 15 14:48:06 2011 +0200

    imap4d: redo signal handling
    
    Previously implemented way of signal handling was unsafe because of
    the use of unsafe functions in signal handlers. It also allowed for
    recursive invocations of MU calls not supposed to handle recursion
    (such as mu_mailbox_expunge, for example). This changeset fixes it.
    
    * imap4d/imap4d.c (imap4d_child_signal_setup): Change signal set.
    (imap4d_mainloop): Set a jump point for signal handling.
    Restore default handling for SIGILL, SIGBUS, SIGFPE, SIGSEGV, SIGSTOP.
    (master_jmp): New variable.
    (imap4d_master_signal): New function.
    (main): Redo signal handling.
    * imap4d/imap4d.h (child_jmp): New extern.
    (imap4d_enter_critical,imap4d_leave_critical): New protos.
    * imap4d/signal.c (imap4d_master_signal): Move to imap4d.c
    (imap4d_enter_critical,imap4d_leave_critical): New functions.
    (imap4d_child_signal): Rewrite.
    
    * imap4d/append.c: Protect critical sections.
    * imap4d/bye.c: Likewise.
    * imap4d/close.c: Likewise.
    * imap4d/copy.c: Likewise.
    * imap4d/delete.c: Likewise.
    * imap4d/expunge.c: Likewise.
    * imap4d/rename.c: Likewise.
    * imap4d/select.c: Likewise.
    * imap4d/status.c: Likewise.
    
    * scheme/Makefile.am (sievemod_DATA): Add guimb.scmi.

-----------------------------------------------------------------------

Summary of changes:
 imap4d/append.c                |    6 +-
 imap4d/bye.c                   |  170 +++++++++++++++++++++-------------------
 imap4d/close.c                 |    4 +
 imap4d/copy.c                  |    6 +-
 imap4d/delete.c                |    2 +
 imap4d/expunge.c               |    4 +-
 imap4d/imap4d.c                |   71 ++++++++++++++++-
 imap4d/imap4d.h                |    4 +
 imap4d/rename.c                |    5 +
 imap4d/select.c                |    2 +
 imap4d/signal.c                |   61 +++++----------
 imap4d/status.c                |    2 +
 libmailutils/mime/attachment.c |    6 +-
 scheme/Makefile.am             |    3 +-
 14 files changed, 212 insertions(+), 134 deletions(-)

diff --git a/imap4d/append.c b/imap4d/append.c
index 091602d..003d8be 100644
--- a/imap4d/append.c
+++ b/imap4d/append.c
@@ -124,7 +124,8 @@ imap4d_append0 (mu_mailbox_t mbox, int flags, char *date_time, char *text,
       mu_message_destroy (&msg, &tm);
       return 1;
     }
-  
+
+  imap4d_enter_critical ();
   rc = mu_mailbox_append_message (mbox, msg);
   if (rc == 0)
     {
@@ -140,7 +141,8 @@ imap4d_append0 (mu_mailbox_t mbox, int flags, char *date_time, char *text,
       /* FIXME: If not INBOX */
       quota_update (size);
     }
-
+  imap4d_leave_critical ();
+  
   mu_message_destroy (&msg, &tm);
   return rc;
 }
diff --git a/imap4d/bye.c b/imap4d/bye.c
index d5f4086..9b66a13 100644
--- a/imap4d/bye.c
+++ b/imap4d/bye.c
@@ -36,90 +36,102 @@ imap4d_bye0 (int reason, struct imap4d_command *command)
 {
   int status = EX_SOFTWARE;
 
-  if (mbox)
+  /* Some clients may close the connection immediately after sending
+     LOGOUT.  Do not treat this as error (RFC 2683).
+     To be on the safe side, ignore broken pipes for any command: at
+     this stage it is of no significance. */
+  static int sigtab[] = { SIGPIPE };
+  mu_set_signals (sigpipe, sigtab, MU_ARRAY_SIZE (sigtab));
+  if (setjmp (pipejmp))
     {
-      mu_mailbox_flush (mbox, 0);
-      mu_mailbox_close (mbox);
-      mu_mailbox_destroy (&mbox);
+      mu_set_signals (SIG_IGN, sigtab, MU_ARRAY_SIZE (sigtab));
+      /* Invalidate iostream. This creates a mild memory leak, as the
+	 stream is not destroyed by util_bye, but at least this avoids
+	 endless loop which would happen when mu_stream_flush would
+	 try to flush buffers on an already broken pipe.
+	 FIXME: There must be a special function for that, I guess.
+	 Something like mu_stream_invalidate. */
+      iostream = NULL;
     }
-
-  switch (reason)
+  else
     {
-    case ERR_NO_MEM:
-      io_untagged_response (RESP_BYE, "Server terminating: no more resources.");
-      mu_diag_output (MU_DIAG_ERROR, _("not enough memory"));
-      break;
-
-    case ERR_TERMINATE:
-      status = EX_OK;
-      io_untagged_response (RESP_BYE, "Server terminating on request.");
-      mu_diag_output (MU_DIAG_NOTICE, _("terminating on request"));
-      break;
-
-    case ERR_SIGNAL:
-      mu_diag_output (MU_DIAG_ERROR, _("quitting on signal"));
-      exit (status);
-
-    case ERR_TIMEOUT:
-      status = EX_TEMPFAIL;
-      io_untagged_response (RESP_BYE, "Session timed out");
-      if (state == STATE_NONAUTH)
-        mu_diag_output (MU_DIAG_INFO, _("session timed out for no user"));
-      else
-	mu_diag_output (MU_DIAG_INFO, _("session timed out for user: %s"), auth_data->name);
-      break;
-
-    case ERR_NO_OFILE:
-      status = EX_IOERR;
-      mu_diag_output (MU_DIAG_INFO, _("write error on control stream"));
-      break;
-
-    case ERR_NO_IFILE:
-      status = EX_IOERR;
-      mu_diag_output (MU_DIAG_INFO, _("read error on control stream"));
-      break;
-
-    case ERR_MAILBOX_CORRUPTED:
-      status = EX_OSERR;
-      mu_diag_output (MU_DIAG_ERROR, _("mailbox modified by third party"));
-      break;
-
-    case ERR_STREAM_CREATE:
-      status = EX_UNAVAILABLE;
-      mu_diag_output (MU_DIAG_ERROR, _("cannot create transport stream"));
-      break;
+      if (mbox)
+	{
+	  imap4d_enter_critical ();
+	  mu_mailbox_flush (mbox, 0);
+	  mu_mailbox_close (mbox);
+	  mu_mailbox_destroy (&mbox);
+	  imap4d_leave_critical ();
+	}
+
+      switch (reason)
+	{
+	case ERR_NO_MEM:
+	  io_untagged_response (RESP_BYE,
+				"Server terminating: no more resources.");
+	  mu_diag_output (MU_DIAG_ERROR, _("not enough memory"));
+	  break;
+	  
+	case ERR_TERMINATE:
+	  status = EX_OK;
+	  io_untagged_response (RESP_BYE, "Server terminating on request.");
+	  mu_diag_output (MU_DIAG_NOTICE, _("terminating on request"));
+	  break;
+
+	case ERR_SIGNAL:
+	  mu_diag_output (MU_DIAG_ERROR, _("quitting on signal"));
+	  exit (status);
+	  
+	case ERR_TIMEOUT:
+	  status = EX_TEMPFAIL;
+	  io_untagged_response (RESP_BYE, "Session timed out");
+	  if (state == STATE_NONAUTH)
+	    mu_diag_output (MU_DIAG_INFO, _("session timed out for no user"));
+	  else
+	    mu_diag_output (MU_DIAG_INFO, _("session timed out for user: %s"),
+			    auth_data->name);
+	  break;
+
+	case ERR_NO_OFILE:
+	  status = EX_IOERR;
+	  mu_diag_output (MU_DIAG_INFO, _("write error on control stream"));
+	  break;
+
+	case ERR_NO_IFILE:
+	  status = EX_IOERR;
+	  mu_diag_output (MU_DIAG_INFO, _("read error on control stream"));
+	  break;
+
+	case ERR_MAILBOX_CORRUPTED:
+	  status = EX_OSERR;
+	  mu_diag_output (MU_DIAG_ERROR, _("mailbox modified by third party"));
+	  break;
+	  
+	case ERR_STREAM_CREATE:
+	  status = EX_UNAVAILABLE;
+	  mu_diag_output (MU_DIAG_ERROR, _("cannot create transport stream"));
+	  break;
       
-    case OK:
-      status = EX_OK;
-      io_untagged_response (RESP_BYE, "Session terminating.");
-      if (state == STATE_NONAUTH)
-	mu_diag_output (MU_DIAG_INFO, _("session terminating"));
-      else
-	mu_diag_output (MU_DIAG_INFO, _("session terminating for user: %s"), auth_data->name);
-      break;
-
-    default:
-      io_untagged_response (RESP_BYE, "Quitting (reason unknown)");
-      mu_diag_output (MU_DIAG_ERROR, _("quitting (numeric reason %d)"), reason);
-      break;
-    }
-
-  if (status == EX_OK && command)
-    {
-      /* Some clients may close the connection immediately after sending
-	 LOGOUT.  Do not treat this as error (RFC 2683). */
-      static int sigtab[] = { SIGPIPE };
-      mu_set_signals (sigpipe, sigtab, MU_ARRAY_SIZE (sigtab));
-      if (setjmp (pipejmp) == 0)
+	case OK:
+	  status = EX_OK;
+	  io_untagged_response (RESP_BYE, "Session terminating.");
+	  if (state == STATE_NONAUTH)
+	    mu_diag_output (MU_DIAG_INFO, _("session terminating"));
+	  else
+	    mu_diag_output (MU_DIAG_INFO,
+			    _("session terminating for user: %s"),
+			    auth_data->name);
+	  break;
+
+	default:
+	  io_untagged_response (RESP_BYE, "Quitting (reason unknown)");
+	  mu_diag_output (MU_DIAG_ERROR, _("quitting (numeric reason %d)"),
+			  reason);
+	  break;
+	}
+      
+      if (status == EX_OK && command)
 	io_completion_response (command, RESP_OK, "Completed");
-      else
-	/* Invalidate iostream. This creates a mild memory leak, as the
-	   stream is not destroyed by util_bye, but at least this avoids
-	   endless loop which would happen when mu_stream_flush would
-	   try to flush buffers on an already broken pipe.
-	   FIXME: There must be a special function for that, I guess.
-	   Something like mu_stream_invalidate. */
-	iostream = NULL;
     }
   
   util_bye ();
diff --git a/imap4d/close.c b/imap4d/close.c
index a5303f5..0b4c020 100644
--- a/imap4d/close.c
+++ b/imap4d/close.c
@@ -30,7 +30,9 @@ imap4d_close0 (struct imap4d_command *command, imap4d_tokbuf_t tok,
   mu_mailbox_get_flags (mbox, &flags);
   if (flags & MU_STREAM_WRITE)
     {
+      imap4d_enter_critical ();
       status = mu_mailbox_flush (mbox, expunge);
+      imap4d_leave_critical ();
       if (status)
 	{
 	  mu_diag_funcall (MU_DIAG_ERROR, "mu_mailbox_flush", NULL, status);
@@ -40,7 +42,9 @@ imap4d_close0 (struct imap4d_command *command, imap4d_tokbuf_t tok,
   
   /* No messages are removed, and no error is given, if the mailbox is
      selected by an EXAMINE command or is otherwise selected read-only.  */
+  imap4d_enter_critical ();
   status = mu_mailbox_close (mbox);
+  imap4d_leave_critical ();
   if (status)
     {
       mu_diag_funcall (MU_DIAG_ERROR, "mu_mailbox_close", NULL, status);
diff --git a/imap4d/copy.c b/imap4d/copy.c
index dd03296..69715df 100644
--- a/imap4d/copy.c
+++ b/imap4d/copy.c
@@ -119,7 +119,9 @@ try_copy (mu_mailbox_t dst, mu_mailbox_t src, size_t n, size_t *set)
 	      return RESP_BAD;
 	    }
 
+	  imap4d_enter_critical ();
 	  status = mu_mailbox_append_message (dst, msg);
+	  imap4d_leave_critical ();
 	  if (status)
 	    {
 	      mu_diag_funcall (MU_DIAG_ERROR, "mu_mailbox_append_message",
@@ -185,8 +187,10 @@ safe_copy (mu_mailbox_t dst, mu_mailbox_t src, size_t n, size_t *set,
 	      mu_attribute_set_userflag (attr, MU_ATTRIBUTE_DELETED);
 	    }
 	}
-      
+
+      imap4d_enter_critical ();
       status = mu_mailbox_flush (dst, 1);
+      imap4d_leave_critical ();
       if (status)
 	{
 	  mu_url_t url = NULL;
diff --git a/imap4d/delete.c b/imap4d/delete.c
index b3ab729..1e516e2 100644
--- a/imap4d/delete.c
+++ b/imap4d/delete.c
@@ -56,7 +56,9 @@ imap4d_delete (struct imap4d_command *command, imap4d_tokbuf_t tok)
   rc = mu_mailbox_create (&tmpbox, name);
   if (rc == 0)
     {
+      imap4d_enter_critical ();
       rc = mu_mailbox_remove (tmpbox);
+      imap4d_leave_critical ();
       mu_mailbox_destroy (&tmpbox);
       if (rc)
 	mu_diag_funcall (MU_DIAG_ERROR, "mu_mailbox_remove", name, rc);
diff --git a/imap4d/expunge.c b/imap4d/expunge.c
index d9e5279..7a542bb 100644
--- a/imap4d/expunge.c
+++ b/imap4d/expunge.c
@@ -36,9 +36,11 @@ imap4d_expunge (struct imap4d_command *command, imap4d_tokbuf_t tok)
   if (imap4d_tokbuf_argc (tok) != 2)
     return io_completion_response (command, RESP_BAD, "Invalid arguments");
 
+  imap4d_enter_critical ();
   /* FIXME: check for errors.  */
   mu_mailbox_expunge (mbox);
-
+  imap4d_leave_critical ();
+  
   imap4d_sync_invalidate ();
   imap4d_sync ();
   return io_completion_response (command, RESP_OK, "Completed");
diff --git a/imap4d/imap4d.c b/imap4d/imap4d.c
index a20167d..3c56ef1 100644
--- a/imap4d/imap4d.c
+++ b/imap4d/imap4d.c
@@ -385,11 +385,12 @@ get_client_address (int fd, struct sockaddr_in *pcs)
   return 0;
 }
 
+
 void
 imap4d_child_signal_setup (RETSIGTYPE (*handler) (int signo))
 {
-  static int sigtab[] = { SIGILL, SIGBUS, SIGFPE, SIGSEGV, SIGSTOP, SIGPIPE,
-			  SIGABRT, SIGINT, SIGQUIT, SIGTERM, SIGHUP, SIGALRM };
+  static int sigtab[] = { SIGPIPE, SIGABRT, SIGINT, SIGQUIT,
+			  SIGTERM, SIGHUP, SIGALRM };
   mu_set_signals (handler, sigtab, MU_ARRAY_SIZE (sigtab));
 }
 
@@ -399,8 +400,40 @@ imap4d_mainloop (int ifd, int ofd)
   imap4d_tokbuf_t tokp;
   char *text;
   int debug_mode = isatty (ifd);
+  int signo;
 
-  imap4d_child_signal_setup (imap4d_child_signal);
+  if ((signo = setjmp (child_jmp)))
+    {
+      mu_diag_output (MU_DIAG_CRIT, _("got signal `%s'"), strsignal (signo));
+      switch (signo)
+	{
+	case SIGTERM:
+	case SIGHUP:
+	  signo = ERR_TERMINATE;
+	  break;
+      
+	case SIGALRM:
+	  signo = ERR_TIMEOUT;
+	  break;
+      
+	case SIGPIPE:
+	  signo = ERR_NO_OFILE;
+	  break;
+      
+	default:
+	  signo = ERR_SIGNAL;
+	}
+      imap4d_bye (signo);
+    }
+  else
+    {
+      /* Restore default handling for these signals: */
+      static int defsigtab[] = { SIGILL, SIGBUS, SIGFPE, SIGSEGV, SIGSTOP };
+      mu_set_signals (SIG_DFL, defsigtab, MU_ARRAY_SIZE (defsigtab));
+      /* Set child-specific signal handlers */
+      imap4d_child_signal_setup (imap4d_child_signal);
+    }
+  
   io_setio (ifd, ofd);
 
   if (imap4d_preauth_setup (ifd) == 0)
@@ -484,6 +517,17 @@ imap4d_check_home_dir (const char *dir, uid_t uid, gid_t gid)
   return 0;
 }
 
+
+jmp_buf master_jmp;
+
+RETSIGTYPE
+imap4d_master_signal (int signo)
+{
+  longjmp (master_jmp, signo);
+}
+
+
+
 int
 main (int argc, char **argv)
 {
@@ -578,6 +622,27 @@ main (int argc, char **argv)
     }
 
   /* Set the signal handlers.  */
+  if ((status = setjmp (master_jmp)))
+    {
+      int code;
+      mu_diag_output (MU_DIAG_CRIT, _("MASTER: exiting on signal (%s)"),
+		      strsignal (status));
+      switch (status)
+	{
+	case SIGTERM:
+	case SIGHUP:
+	case SIGQUIT:
+	case SIGINT:
+	  code = EX_OK;
+	  break;
+	  
+	default:
+	  code = EX_SOFTWARE;
+	  break;
+	}
+      
+      exit (code); 
+    }
   mu_set_signals (imap4d_master_signal, sigtab, MU_ARRAY_SIZE (sigtab));
 
   mu_stdstream_strerr_setup (mu_log_syslog ?
diff --git a/imap4d/imap4d.h b/imap4d/imap4d.h
index 61e0829..592d812 100644
--- a/imap4d/imap4d.h
+++ b/imap4d/imap4d.h
@@ -202,6 +202,7 @@ extern int imap4d_transcript;
 extern mu_list_t imap4d_id_list;
 extern int imap4d_argc;                 
 extern char **imap4d_argv;
+extern jmp_buf child_jmp;
 
 /* Input functions */
 extern mu_stream_t iostream;
@@ -334,6 +335,9 @@ extern RETSIGTYPE imap4d_master_signal (int);
 extern RETSIGTYPE imap4d_child_signal (int);
 extern int imap4d_bye (int);
 extern int imap4d_bye0 (int reason, struct imap4d_command *command);
+void imap4d_enter_critical (void);
+void imap4d_leave_critical (void);
+
 
 /* Namespace functions */
 extern mu_list_t namespace[NS_MAX];
diff --git a/imap4d/rename.c b/imap4d/rename.c
index f65b297..ccbfc2f 100644
--- a/imap4d/rename.c
+++ b/imap4d/rename.c
@@ -182,12 +182,17 @@ imap4d_rename (struct imap4d_command *command, imap4d_tokbuf_t tok)
 	      if (mu_mailbox_get_message (inbox, no, &message) == 0)
 		{
 		  mu_attribute_t attr = NULL;
+
+		  imap4d_enter_critical ();
 		  mu_mailbox_append_message (newmbox, message);
+		  imap4d_leave_critical ();
 		  mu_message_get_attribute (message, &attr);
 		  mu_attribute_set_deleted (attr);
 		}
 	    }
+	  imap4d_enter_critical ();
 	  mu_mailbox_expunge (inbox);
+	  imap4d_leave_critical ();
 	  mu_mailbox_close (inbox);
 	  mu_mailbox_destroy (&inbox);
 	}
diff --git a/imap4d/select.c b/imap4d/select.c
index 1ec75ab..c961e09 100644
--- a/imap4d/select.c
+++ b/imap4d/select.c
@@ -46,8 +46,10 @@ imap4d_select0 (struct imap4d_command *command, const char *mboxname,
      currently selected mailbox without doing an expunge.  */
   if (mbox)
     {
+      imap4d_enter_critical ();
       mu_mailbox_sync (mbox);
       mu_mailbox_close (mbox);
+      imap4d_leave_critical ();
       mu_mailbox_destroy (&mbox);
       /* Destroy the old uid table.  */
       imap4d_sync ();
diff --git a/imap4d/signal.c b/imap4d/signal.c
index 12d49a9..74c3cdc 100644
--- a/imap4d/signal.c
+++ b/imap4d/signal.c
@@ -15,57 +15,34 @@
    You should have received a copy of the GNU General Public License
    along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
-#define __USE_MISC
 #include "imap4d.h"
 
-/* Default signal handler to call the imap4d_bye() function */
+jmp_buf child_jmp;
+static int __critical_section;
+static int __got_signal;
 
-RETSIGTYPE
-imap4d_master_signal (int signo)
+void
+imap4d_enter_critical ()
 {
-  int code;
-
-  mu_diag_output (MU_DIAG_CRIT, _("MASTER: exiting on signal (%s)"),
-		  strsignal (signo));
-  switch (signo)
-    {
-    case SIGTERM:
-    case SIGHUP:
-    case SIGQUIT:
-    case SIGINT:
-      code = EX_OK;
-      break;
-
-    default:
-      code = EX_SOFTWARE;
-      break;
-    }
+  __critical_section = 1;
+  if (__got_signal)
+    __critical_section++;
+}
 
-  exit (code); 
+void
+imap4d_leave_critical ()
+{
+  if (__got_signal && __critical_section != 2)
+    longjmp (child_jmp, __got_signal);
+  __critical_section = 0;
 }
 
 RETSIGTYPE
 imap4d_child_signal (int signo)
 {
   imap4d_child_signal_setup (SIG_IGN);
-  mu_diag_output (MU_DIAG_CRIT, _("got signal `%s'"), strsignal (signo));
-  switch (signo)
-    {
-    case SIGTERM:
-    case SIGHUP:
-      signo = ERR_TERMINATE;
-      break;
-      
-    case SIGALRM:
-      signo = ERR_TIMEOUT;
-      break;
-      
-    case SIGPIPE:
-      signo = ERR_NO_OFILE;
-      break;
-      
-    default:
-      signo = ERR_SIGNAL;
-    }
-  imap4d_bye (signo);
+  if (__critical_section)
+    __got_signal = signo;
+  else
+    longjmp (child_jmp, signo);
 }
diff --git a/imap4d/status.c b/imap4d/status.c
index 9fa2ae8..3333898 100644
--- a/imap4d/status.c
+++ b/imap4d/status.c
@@ -88,7 +88,9 @@ imap4d_status (struct imap4d_command *command, imap4d_tokbuf_t tok)
 
   /* We may be opening the current mailbox, so make sure the attributes are
      preserved */
+  imap4d_enter_critical ();
   mu_mailbox_sync (mbox);
+  imap4d_leave_critical ();
   
   status = mu_mailbox_create_default (&smbox, mailbox_name);
   if (status == 0)
diff --git a/libmailutils/mime/attachment.c b/libmailutils/mime/attachment.c
index c302b58..d8207ec 100644
--- a/libmailutils/mime/attachment.c
+++ b/libmailutils/mime/attachment.c
@@ -208,9 +208,6 @@ _attachment_setup (mu_mime_io_buffer_t *pinfo, mu_message_t msg,
   if ((ret = mu_message_get_body (msg, &body)) != 0 ||
       (ret = mu_body_get_streamref (body, &stream)) != 0)
     return ret;
-  ret = mu_stream_seek (stream, 0, SEEK_SET, NULL);
-  if (ret)
-    return ret;
   *pstream = stream;
   if (*pinfo)
     {
@@ -224,7 +221,6 @@ _attachment_setup (mu_mime_io_buffer_t *pinfo, mu_message_t msg,
 	return ret;
     }
   
-  info->msg = msg;
   *pinfo = info;
   return 0;
 }
@@ -328,7 +324,7 @@ mu_message_encapsulate (mu_message_t msg, mu_message_t *newmsg,
       mu_message_destroy (&tmsg, NULL);
       return ret;
     }
-
+  info->msg = msg;
   if (ret == 0 && (ret = mu_message_get_streamref (msg, &istream)) == 0)
     {
       mu_stream_seek (istream, 0, MU_SEEK_SET, NULL);
diff --git a/scheme/Makefile.am b/scheme/Makefile.am
index c146dfb..cede42b 100644
--- a/scheme/Makefile.am
+++ b/scheme/Makefile.am
@@ -56,5 +56,6 @@ sievemod_DATA=\
 EXTRA_DIST=\
  $(sievemod_DATA)\
  sieve-core.scm\
- sieve2scm.scmi
+ sieve2scm.scmi\
+ guimb.scmi
 


hooks/post-receive
-- 
GNU Mailutils


From MAILER-DAEMON Sun Jan 16 10:54:58 2011
Received: from mailman by lists.gnu.org with archive (Exim 4.43)
	id 1PeUwU-0002mr-LD
	for mharc-commit-mailutils@gnu.org; Sun, 16 Jan 2011 10:54:58 -0500
Received: from [140.186.70.92] (port=37868 helo=eggs.gnu.org)
	by lists.gnu.org with esmtp (Exim 4.43) id 1PeUwS-0002mi-0J
	for commit-mailutils@gnu.org; Sun, 16 Jan 2011 10:54:57 -0500
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1PeUwQ-0003Vu-3H
	for commit-mailutils@gnu.org; Sun, 16 Jan 2011 10:54:55 -0500
Received: from colonialone.fsf.org ([140.186.70.51]:38476
	helo=internal.in.savannah.gnu.org)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1PeUwQ-0003Vq-00
	for commit-mailutils@gnu.org; Sun, 16 Jan 2011 10:54:54 -0500
Received: from [10.1.0.108] (helo=vcs-noshell.in.savannah.gnu.org)
	by internal.in.savannah.gnu.org with esmtp (Exim 4.69)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1PeUwP-0006xP-MH
	for commit-mailutils@gnu.org; Sun, 16 Jan 2011 15:54:53 +0000
Received: from gray by vcs-noshell.in.savannah.gnu.org with local (Exim 4.69)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1PeUwN-0007Zf-PP
	for commit-mailutils@gnu.org; Sun, 16 Jan 2011 15:54:53 +0000
From: "Sergey Poznyakoff" <gray@gnu.org.ua>
To: commit-mailutils@gnu.org
X-Git-Refname: refs/heads/master
X-Git-Reftype: branch
X-Git-Oldrev: ec0d5f94acb17be7357a6a819a706189b02cf2da
X-Git-Newrev: a8001bb2e4684d7144e9a2217704e8f6635c5603
Message-Id: <E1PeUwN-0007Zf-PP@vcs-noshell.in.savannah.gnu.org>
Date: Sun, 16 Jan 2011 15:54:52 +0000
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2)
Subject: [SCM] GNU Mailutils branch, master,
	updated. release-2.2-346-ga8001bb
X-BeenThere: commit-mailutils@gnu.org
X-Mailman-Version: 2.1.5
Precedence: list
List-Id: Commit notices for GNU mailutils <commit-mailutils.gnu.org>
List-Unsubscribe: <http://lists.gnu.org/mailman/listinfo/commit-mailutils>,
	<mailto:commit-mailutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/commit-mailutils>
List-Post: <mailto:commit-mailutils@gnu.org>
List-Help: <mailto:commit-mailutils-request@gnu.org?subject=help>
List-Subscribe: <http://lists.gnu.org/mailman/listinfo/commit-mailutils>,
	<mailto:commit-mailutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Sun, 16 Jan 2011 15:54:57 -0000

This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "GNU Mailutils".

http://git.savannah.gnu.org/cgit/mailutils.git/commit/?id=a8001bb2e4684d7144e9a2217704e8f6635c5603

The branch, master has been updated
       via  a8001bb2e4684d7144e9a2217704e8f6635c5603 (commit)
      from  ec0d5f94acb17be7357a6a819a706189b02cf2da (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit a8001bb2e4684d7144e9a2217704e8f6635c5603
Author: Sergey Poznyakoff <gray@gnu.org.ua>
Date:   Sun Jan 16 17:49:34 2011 +0200

    Add useful debugging hooks.
    
    * libmailutils/diag/bt.c: New file.
    * libmailutils/diag/wd.c: New file.
    * libmailutils/diag/Makefile.am (libdiag_la_SOURCES): Add bt.c and wd.c
    
    * include/mailutils/debug.h (mu_gdb_bt, mu_wd): New protos.
    * include/mailutils/util.h (mu_getmaxfd): New protos.
    * libmailutils/base/getmaxfd.c: New file.
    * libmailutils/base/Makefile.am (libbase_la_SOURCES): Add getmaxfd.c
    
    * libmailutils/server/acl.c: Use mu_getmaxfd.
    * libmailutils/stream/prog_stream.c: Likewise.
    * mh/mh_whatnow.c: Likewise.
    
    * libmu_scm/mu_body.c (mu-body?): Bugfix.

-----------------------------------------------------------------------

Summary of changes:
 include/mailutils/debug.h                    |    9 ++-
 include/mailutils/util.h                     |    1 +
 libmailutils/base/Makefile.am                |    1 +
 libmailutils/{url/flag.c => base/getmaxfd.c} |   30 +++++-----
 libmailutils/diag/Makefile.am                |    4 +-
 libmailutils/diag/bt.c                       |   87 ++++++++++++++++++++++++++
 libmailutils/diag/wd.c                       |   69 ++++++++++++++++++++
 libmailutils/server/acl.c                    |   11 +---
 libmailutils/stream/prog_stream.c            |   10 +---
 libmu_scm/mu_body.c                          |    2 +-
 mh/mh_whatnow.c                              |   10 +---
 11 files changed, 188 insertions(+), 46 deletions(-)
 copy libmailutils/{url/flag.c => base/getmaxfd.c} (66%)
 create mode 100644 libmailutils/diag/bt.c
 create mode 100644 libmailutils/diag/wd.c

diff --git a/include/mailutils/debug.h b/include/mailutils/debug.h
index 1b18c8d..4c7b930 100644
--- a/include/mailutils/debug.h
+++ b/include/mailutils/debug.h
@@ -83,7 +83,6 @@ void mu_debug_log_begin (const char *fmt, ...) MU_PRINTFLIKE(1,2);
 void mu_debug_log_cont (const char *fmt, ...) MU_PRINTFLIKE(1,2);
 void mu_debug_log_end (const char *fmt, ...) MU_PRINTFLIKE(1,2);
 void mu_debug_log_nl (void);
-
   
   
 #define MU_ASSERT(expr)						\
@@ -115,7 +114,13 @@ void mu_debug_log_nl (void);
 	  mu_debug_log s;						 \
       }                                                                  \
   while (0)
- 
+
+  /* Debugging hooks. */
+  /* Dump a stack trace and terminate the program. */
+void mu_gdb_bt (void);
+  /* Sleep till attached to by gdb. */
+void mu_wd (unsigned to);
+  
 #ifdef __cplusplus
 }
 #endif
diff --git a/include/mailutils/util.h b/include/mailutils/util.h
index b8027bc..3ea257f 100644
--- a/include/mailutils/util.h
+++ b/include/mailutils/util.h
@@ -177,6 +177,7 @@ int mu_getpass (mu_stream_t in, mu_stream_t out, const char *prompt,
   /* ----------------------- */
   /* Assorted functions.     */
   /* ----------------------- */
+int mu_getmaxfd (void);
 /* Get the host name, doing a gethostbyname() if possible. */
 int mu_get_host_name (char **host);
 int mu_spawnvp (const char *prog, char *av[], int *stat);
diff --git a/libmailutils/base/Makefile.am b/libmailutils/base/Makefile.am
index acb6b62..592eb7c 100644
--- a/libmailutils/base/Makefile.am
+++ b/libmailutils/base/Makefile.am
@@ -31,6 +31,7 @@ libbase_la_SOURCES = \
  filename.c\
  freeitem.c\
  getcwd.c\
+ getmaxfd.c\
  getpass.c\
  hostname.c\
  iterator.c\
diff --git a/libmailutils/url/flag.c b/libmailutils/base/getmaxfd.c
similarity index 66%
copy from libmailutils/url/flag.c
copy to libmailutils/base/getmaxfd.c
index 586c881..b905ac8 100644
--- a/libmailutils/url/flag.c
+++ b/libmailutils/base/getmaxfd.c
@@ -1,5 +1,5 @@
 /* GNU Mailutils -- a suite of utilities for electronic mail
-   Copyright (C) 2010, 2011 Free Software Foundation, Inc.
+   Copyright (C) 2011 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
@@ -19,22 +19,22 @@
 # include <config.h>
 #endif
 
-#include <errno.h>
-#include <mailutils/sys/url.h>
+#include <unistd.h>
+#include <limits.h>
 
-int
-mu_url_get_flags (mu_url_t url, int *pf)
-{
-  if (!url || !pf)
-    return EINVAL;
-  *pf = url->flags;
-  return 0;
-}
+#if defined (HAVE_SYSCONF) && defined (_SC_OPEN_MAX)
+# define __getmaxfd() sysconf (_SC_OPEN_MAX)
+#elif defined (HAVE_GETDTABLESIZE)
+# define __getmaxfd() getdtablesize ()
+#elif defined OPEN_MAX
+# define __getmaxfd() OPEN_MAX
+#else
+# define __getmaxfd() 256
+#endif
 
 int
-mu_url_has_flag (mu_url_t url, int flags)
+mu_getmaxfd ()
 {
-  if (!url)
-    return 0;
-  return url->flags & flags;
+  return __getmaxfd ();
 }
+
diff --git a/libmailutils/diag/Makefile.am b/libmailutils/diag/Makefile.am
index 93c1fce..ba5a715 100644
--- a/libmailutils/diag/Makefile.am
+++ b/libmailutils/diag/Makefile.am
@@ -18,11 +18,13 @@
 noinst_LTLIBRARIES = libdiag.la
 
 libdiag_la_SOURCES = \
+ bt.c\
  debug.c\
  diag.c\
  muerror.c\
  muerrno.c\
- syslog.c
+ syslog.c\
+ wd.c
 
 INCLUDES = @MU_LIB_COMMON_INCLUDES@ -I/libmailutils
 
diff --git a/libmailutils/diag/bt.c b/libmailutils/diag/bt.c
new file mode 100644
index 0000000..6bdae8b
--- /dev/null
+++ b/libmailutils/diag/bt.c
@@ -0,0 +1,87 @@
+/* GNU Mailutils -- a suite of utilities for electronic mail
+   Copyright (C) 2011 Free Software Foundation, Inc.
+
+   This library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 3 of the License, or (at your option) any later version.
+
+   This library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General
+   Public License along with this library.  If not, see 
+   <http://www.gnu.org/licenses/>. */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <sys/types.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <string.h>
+#include <argp.h>
+#include <mailutils/util.h>
+
+/* Dump a stack trace and terminate current program.
+
+   The trace is written to file /tmp/mailutils.PROG.PID, where PROG
+   is the file name of the program, and PID its PID. */
+   
+void
+mu_gdb_bt ()
+{
+  int i;
+  pid_t master_pid = getpid ();
+  pid_t pid;
+  static char buf[1024];
+  static char fname[1024];
+  char *p;
+  int fd;
+  char *argv[8];
+  
+  p = strrchr (program_invocation_name, '/');
+  if (p)
+    p++;
+  else
+    p = program_invocation_name;
+  sprintf (fname, "/tmp/mailutils.%s.%lu", p, (unsigned long) master_pid);
+  
+  pid = fork ();
+  if (pid == (pid_t)-1)
+    abort ();
+  if (pid)
+    {
+      sleep (10);
+      abort ();
+    }
+
+  for (i = mu_getmaxfd (); i >= 0; i--)
+    close (i);
+
+  fd = open (fname, O_WRONLY|O_CREAT, 0600);
+  if (fd == -1)
+    abort ();
+
+  dup2 (fd, 1);
+  dup2 (fd, 2);
+  close (fd);
+  
+  argv[0] = "/usr/bin/gdb";
+  argv[1] = program_invocation_name;
+  sprintf (buf, "%lu", (unsigned long) master_pid);
+  argv[2] = buf;
+  argv[3] = "-ex";
+  argv[4] = "bt";
+  argv[5] = "-ex";
+  argv[6] = "kill";
+  argv[7] = NULL;
+
+  execvp (argv[0], argv);
+  abort ();
+}
+
diff --git a/libmailutils/diag/wd.c b/libmailutils/diag/wd.c
new file mode 100644
index 0000000..9b78c12
--- /dev/null
+++ b/libmailutils/diag/wd.c
@@ -0,0 +1,69 @@
+/* GNU Mailutils -- a suite of utilities for electronic mail
+   Copyright (C) 2011 Free Software Foundation, Inc.
+
+   This library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 3 of the License, or (at your option) any later version.
+
+   This library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General
+   Public License along with this library.  If not, see 
+   <http://www.gnu.org/licenses/>. */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <unistd.h>
+#include <argp.h>
+#include <mailutils/diag.h>
+
+/* A debugging hook.
+
+   Suspend execution to let the developer to attach to the current process
+   using gdb.
+
+   Wait at most TO seconds.  If TO is 0, wait forever. */
+
+void
+mu_wd (unsigned to)
+{
+  unsigned volatile _count_down;
+  pid_t pid = getpid ();
+
+  if (to)
+    mu_diag_output (MU_DIAG_CRIT,
+		    "process %lu is waiting for debug (%u seconds left)",
+		    (unsigned long) pid, to);
+  else
+    mu_diag_output (MU_DIAG_CRIT,
+		    "process %lu is waiting for debug",
+		    (unsigned long) pid);
+  mu_diag_output (MU_DIAG_CRIT,
+		  "to attach: gdb -ex 'set variable mu_wd::_count_down=0' %s %lu",
+		  program_invocation_name, (unsigned long) pid);
+  if (to)
+    {
+      _count_down = to;
+      while (_count_down)
+	{
+	  sleep (1);
+	  _count_down--;
+	}
+    }
+  else
+    {
+      _count_down = 1;
+      while (_count_down)
+	{
+	  sleep (1);
+	}
+    }
+  mu_diag_output (MU_DIAG_CRIT, "process %lu finished waiting",
+		  (unsigned long) pid);
+}
diff --git a/libmailutils/server/acl.c b/libmailutils/server/acl.c
index 1b6b01b..b7f508a 100644
--- a/libmailutils/server/acl.c
+++ b/libmailutils/server/acl.c
@@ -39,6 +39,7 @@
 #include <mailutils/errno.h>
 #include <mailutils/kwd.h>
 #include <mailutils/io.h>
+#include <mailutils/util.h>
 
 struct _mu_acl_entry
 {
@@ -473,14 +474,6 @@ struct run_closure
   mu_acl_result_t *result;
 };
 
-#if defined (HAVE_SYSCONF) && defined (_SC_OPEN_MAX)
-# define getmaxfd() sysconf (_SC_OPEN_MAX)
-#elif defined (HAVE_GETDTABLESIZE)
-# define getmaxfd() getdtablesize ()
-#else
-# define getmaxfd() 64
-#endif
-
 #define SEQ(s, n, l) \
   (((l) == (sizeof(s) - 1)) && memcmp (s, n, l) == 0)
 
@@ -604,7 +597,7 @@ spawn_prog (const char *cmdline, int *pstatus, struct run_closure *rp)
 	  _exit (127);
 	}
       
-      for (i = getmaxfd (); i > 2; i--)
+      for (i = mu_getmaxfd (); i > 2; i--)
 	close (i);
       execvp (ws.ws_wordv[0], ws.ws_wordv);
       _exit (127);
diff --git a/libmailutils/stream/prog_stream.c b/libmailutils/stream/prog_stream.c
index 2718be6..2f4e94a 100644
--- a/libmailutils/stream/prog_stream.c
+++ b/libmailutils/stream/prog_stream.c
@@ -60,14 +60,6 @@ _prog_stream_unregister (struct _mu_prog_stream *stream)
 
 
 
-#if defined (HAVE_SYSCONF) && defined (_SC_OPEN_MAX)
-# define getmaxfd() sysconf (_SC_OPEN_MAX)
-#elif defined (HAVE_GETDTABLESIZE)
-# define getmaxfd() getdtablesize ()
-#else
-# define getmaxfd() 64
-#endif
-
 #define REDIRECT_STDIN_P(f) ((f) & MU_STREAM_WRITE)
 #define REDIRECT_STDOUT_P(f) ((f) & MU_STREAM_READ)
 
@@ -260,7 +252,7 @@ start_program_filter (int *p, struct _mu_prog_stream *fs, int flags)
 	}
        
       /* Close unneded descripitors */
-      for (i = getmaxfd (); i > 2; i--)
+      for (i = mu_getmaxfd (); i > 2; i--)
 	close (i);
 
       /*FIXME: Switch to other uid/gid if desired */
diff --git a/libmu_scm/mu_body.c b/libmu_scm/mu_body.c
index 8dbe42c..8add9b5 100644
--- a/libmu_scm/mu_body.c
+++ b/libmu_scm/mu_body.c
@@ -100,7 +100,7 @@ SCM_DEFINE_PUBLIC (scm_mu_body_p, "mu-body?", 1, 0, 0,
 "Return @code{true} if @var{scm} is a Mailutils message body object.\n")
 #define FUNC_NAME s_scm_mu_body_p
 {
-  return mu_scm_is_body (scm);
+  return scm_from_bool (mu_scm_is_body (scm));
 }
 #undef FUNC_NAME
 
diff --git a/mh/mh_whatnow.c b/mh/mh_whatnow.c
index ca9bbdc..85a13d6 100644
--- a/mh/mh_whatnow.c
+++ b/mh/mh_whatnow.c
@@ -17,14 +17,6 @@
 
 #include <mh.h>
 
-#if defined (HAVE_SYSCONF) && defined (_SC_OPEN_MAX)
-# define getmaxfd() sysconf (_SC_OPEN_MAX)
-#elif defined (HAVE_GETDTABLESIZE)
-# define getmaxfd() getdtablesize ()
-#else
-# define getmaxfd() 64
-#endif
-
 typedef int (*handler_fp) (struct mh_whatnow_env *wh,
 			   int argc, char **argv,
 			   int *status);
@@ -620,7 +612,7 @@ mh_whatnowproc (struct mh_whatnow_env *wh, int initial_edit, const char *prog)
       
       set_default_editor (wh);
       mh_whatnow_env_to_environ (wh);
-      for (i = getmaxfd (); i > 2; i--)
+      for (i = mu_getmaxfd (); i > 2; i--)
 	close (i);
       execvp (ws.ws_wordv[0], ws.ws_wordv);
       mu_diag_funcall (MU_DIAG_ERROR, "execvp", prog, errno);


hooks/post-receive
-- 
GNU Mailutils


From MAILER-DAEMON Wed Jan 19 06:13:55 2011
Received: from mailman by lists.gnu.org with archive (Exim 4.43)
	id 1PfVz9-0003Bw-K6
	for mharc-commit-mailutils@gnu.org; Wed, 19 Jan 2011 06:13:55 -0500
Received: from [140.186.70.92] (port=57771 helo=eggs.gnu.org)
	by lists.gnu.org with esmtp (Exim 4.43) id 1PfVz5-0003BZ-Bn
	for commit-mailutils@gnu.org; Wed, 19 Jan 2011 06:13:53 -0500
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1PfVz3-0007QK-TR
	for commit-mailutils@gnu.org; Wed, 19 Jan 2011 06:13:51 -0500
Received: from colonialone.fsf.org ([140.186.70.51]:58386
	helo=internal.in.savannah.gnu.org)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1PfVz3-0007QG-Re
	for commit-mailutils@gnu.org; Wed, 19 Jan 2011 06:13:49 -0500
Received: from [10.1.0.108] (helo=vcs-noshell.in.savannah.gnu.org)
	by internal.in.savannah.gnu.org with esmtp (Exim 4.69)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1PfVz3-0002Si-KJ
	for commit-mailutils@gnu.org; Wed, 19 Jan 2011 11:13:49 +0000
Received: from gray by vcs-noshell.in.savannah.gnu.org with local (Exim 4.69)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1PfVz2-00011h-UQ
	for commit-mailutils@gnu.org; Wed, 19 Jan 2011 11:13:49 +0000
From: "Sergey Poznyakoff" <gray@gnu.org.ua>
To: commit-mailutils@gnu.org
X-Git-Refname: refs/heads/master
X-Git-Reftype: branch
X-Git-Oldrev: a8001bb2e4684d7144e9a2217704e8f6635c5603
X-Git-Newrev: d9044ffe99b447598e649b24f5ed49ccb110e15e
Message-Id: <E1PfVz2-00011h-UQ@vcs-noshell.in.savannah.gnu.org>
Date: Wed, 19 Jan 2011 11:13:49 +0000
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2)
Subject: [SCM] GNU Mailutils branch, master,
	updated. release-2.2-347-gd9044ff
X-BeenThere: commit-mailutils@gnu.org
X-Mailman-Version: 2.1.5
Precedence: list
List-Id: Commit notices for GNU mailutils <commit-mailutils.gnu.org>
List-Unsubscribe: <http://lists.gnu.org/mailman/listinfo/commit-mailutils>,
	<mailto:commit-mailutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/commit-mailutils>
List-Post: <mailto:commit-mailutils@gnu.org>
List-Help: <mailto:commit-mailutils-request@gnu.org?subject=help>
List-Subscribe: <http://lists.gnu.org/mailman/listinfo/commit-mailutils>,
	<mailto:commit-mailutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Wed, 19 Jan 2011 11:13:53 -0000

This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "GNU Mailutils".

http://git.savannah.gnu.org/cgit/mailutils.git/commit/?id=d9044ffe99b447598e649b24f5ed49ccb110e15e

The branch, master has been updated
       via  d9044ffe99b447598e649b24f5ed49ccb110e15e (commit)
      from  a8001bb2e4684d7144e9a2217704e8f6635c5603 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit d9044ffe99b447598e649b24f5ed49ccb110e15e
Author: Sergey Poznyakoff <gray@gnu.org.ua>
Date:   Wed Jan 19 13:11:56 2011 +0200

    Bugfix
    
    * libmailutils/base/amd.c: Add more debugging info.  Always check the
    return from amd_pool_open and amd_check_message (which returns int now)
    and act accordingly.

-----------------------------------------------------------------------

Summary of changes:
 imap4d/io.c             |    2 +-
 libmailutils/base/amd.c |  143 +++++++++++++++++++++++++++++++----------------
 2 files changed, 95 insertions(+), 50 deletions(-)

diff --git a/imap4d/io.c b/imap4d/io.c
index 6c185d8..49e4f2f 100644
--- a/imap4d/io.c
+++ b/imap4d/io.c
@@ -167,7 +167,7 @@ io_sendf (const char *format, ...)
 }
 
 /* Send NIL if empty string, change the quoted string to a literal if the
-   string contains: double quotes, CR, LF, and '/'.  CR, LF will be change
+   string contains: double quotes, CR, LF, and '/'.  CR, LF will be changed
    to spaces.  */
 int
 io_send_qstring (const char *buffer)
diff --git a/libmailutils/base/amd.c b/libmailutils/base/amd.c
index fc2fe2f..335ccd2 100644
--- a/libmailutils/base/amd.c
+++ b/libmailutils/base/amd.c
@@ -1458,53 +1458,69 @@ amd_scan_message (struct _amd_message *mhm)
   /* Check if the message was modified after the last scan */
   status = mhm->amd->cur_msg_file_name (mhm, &msg_name);
   if (status)
-    return status;
-
+    {
+      mu_debug (MU_DEBCAT_MAILBOX, MU_DEBUG_ERROR,
+		("amd_scan_message: cur_msg_file_name=%s",
+		 mu_strerror (status)));      
+      return status;
+    }
+  
   if (stat (msg_name, &st) == 0 && st.st_mtime == mhm->mtime)
     {
       /* Nothing to do */
       free (msg_name);
       return 0;
     }
-  free (msg_name);
 
   off = 0;
   status = mu_stream_seek (stream, 0, MU_SEEK_SET, NULL);
-  if (status == 0)
-    while ((status = mu_stream_readline (stream, buf, sizeof (buf), &n)) == 0
-	   && n != 0)
-      {
-	if (in_header)
-	  {
-	    if (buf[0] == '\n')
-	      {
-		in_header = 0;
-		body_start = off + 1;
-	      }
-	    if (buf[n - 1] == '\n')
-	      hlines++;
-	    
-	    /* Process particular attributes */
-	    if (mu_c_strncasecmp (buf, "status:", 7) == 0)
-	      {
-		int deleted = mhm->attr_flags & MU_ATTRIBUTE_DELETED;
-		mu_string_to_flags (buf, &mhm->attr_flags);
-		mhm->attr_flags |= deleted;
-	      }
-	    else if (mu_c_strncasecmp (buf, "x-imapbase:", 11) == 0)
-	      {
-		char *p;
-		mhm->amd->uidvalidity = strtoul (buf + 11, &p, 10);
-		/* second number is next uid. Ignored */
-	      }
-	  }
-	else
-	  {
-	    if (buf[n - 1] == '\n')
-	      blines++;
-	  }
-	off += n;
-      }
+  if (status)
+    mu_debug (MU_DEBCAT_MAILBOX, MU_DEBUG_ERROR,
+	      ("amd_scan_message(%s): mu_stream_seek=%s",
+	       msg_name, mu_strerror (status)));      
+  else
+    {
+      while ((status = mu_stream_readline (stream, buf, sizeof (buf), &n)) == 0
+	     && n != 0)
+	{
+	  if (in_header)
+	    {
+	      if (buf[0] == '\n')
+		{
+		  in_header = 0;
+		  body_start = off + 1;
+		}
+	      if (buf[n - 1] == '\n')
+		hlines++;
+	      
+	      /* Process particular attributes */
+	      if (mu_c_strncasecmp (buf, "status:", 7) == 0)
+		{
+		  int deleted = mhm->attr_flags & MU_ATTRIBUTE_DELETED;
+		  mu_string_to_flags (buf, &mhm->attr_flags);
+		  mhm->attr_flags |= deleted;
+		}
+	      else if (mu_c_strncasecmp (buf, "x-imapbase:", 11) == 0)
+		{
+		  char *p;
+		  mhm->amd->uidvalidity = strtoul (buf + 11, &p, 10);
+		  /* second number is next uid. Ignored */
+		}
+	    }
+	  else
+	    {
+	      if (buf[n - 1] == '\n')
+		blines++;
+	    }
+	  off += n;
+	}
+      if (status)
+	mu_debug (MU_DEBCAT_MAILBOX, MU_DEBUG_ERROR,
+		  ("amd_scan_message(%s): %s",
+		   msg_name, mu_strerror (status)));     
+    }
+
+  free (msg_name);
 
   if (status == 0)
     {
@@ -1606,14 +1622,19 @@ amd_pool_open (struct _amd_message *mhm)
   struct _amd_data *amd = mhm->amd;
   if (amd_pool_lookup (mhm))
     return 0;
-  if (amd_pool_open_count(amd) == MAX_OPEN_STREAMS-1)
+  if (amd_pool_open_count (amd) == MAX_OPEN_STREAMS-1)
     {
       amd_message_stream_close (amd->msg_pool[amd->pool_first++]);
       amd->pool_first %= MAX_OPEN_STREAMS;
     }
   status = amd_message_stream_open (mhm);
   if (status)
-    return status;
+    {
+      mu_debug (MU_DEBCAT_MAILBOX, MU_DEBUG_ERROR,
+		("amd_pool_open: amd_message_stream_open=%s",
+		 mu_strerror (status)));
+      return status;
+    }
   amd->msg_pool[amd->pool_last++] = mhm;
   amd->pool_last %= MAX_OPEN_STREAMS;
   return 0;
@@ -1646,14 +1667,23 @@ amd_message_stream_open (struct _amd_message *mhm)
 
   status = amd->cur_msg_file_name (mhm, &filename);
   if (status)
-    return status;
-
+    {
+      mu_debug (MU_DEBCAT_MAILBOX, MU_DEBUG_ERROR,
+		("amd_message_stream_open: cur_msg_file_name=%s",
+		 mu_strerror (status)));
+      return status;
+    }
+  
   /* The message should be at least readable */
   if (amd->mailbox->flags & (MU_STREAM_RDWR|MU_STREAM_WRITE|MU_STREAM_APPEND))
     flags |= MU_STREAM_RDWR;
   else 
     flags |= MU_STREAM_READ;
   status = mu_file_stream_create (&mhm->stream, filename, flags);
+  if (status)
+    mu_debug (MU_DEBCAT_MAILBOX, MU_DEBUG_ERROR,
+	      ("amd_message_stream_open: mu_file_stream_create(%s)=%s",
+	       filename, mu_strerror (status)));      
 
   free (filename);
 
@@ -1664,7 +1694,11 @@ amd_message_stream_open (struct _amd_message *mhm)
   mu_stream_set_buffer (mhm->stream, mu_buffer_full, 16384);
   
   status = amd_scan_message (mhm);
-
+  if (status)
+    mu_debug (MU_DEBCAT_MAILBOX, MU_DEBUG_ERROR,
+	      ("amd_message_stream_open: amd_scan_message=%s",
+	       mu_strerror (status)));
+  
   return status;
 }
 
@@ -1679,11 +1713,12 @@ amd_message_stream_close (struct _amd_message *mhm)
     }
 }
 
-void
+int
 amd_check_message (struct _amd_message *mhm)
 {
   if (mhm->body_end == 0)
-    amd_pool_open (mhm);
+    return amd_pool_open (mhm);
+  return 0;
 }
 
 /* Reading functions */
@@ -1699,7 +1734,9 @@ amd_body_stream_read (mu_stream_t is, char *buffer, size_t buflen,
   int status = 0;
   mu_off_t ln;
 
-  amd_pool_open (mhm);
+  status = amd_pool_open (mhm);
+  if (status)
+    return status;
 
   if (buffer == NULL || buflen == 0)
     {
@@ -1748,7 +1785,9 @@ amd_body_stream_readdelim (mu_stream_t is, char *buffer, size_t buflen,
   struct _amd_message *mhm = mu_message_get_owner (msg);
   int status = 0;
 
-  amd_pool_open (mhm);
+  status = amd_pool_open (mhm);
+  if (status)
+    return status;
 
   if (buffer == NULL || buflen == 0)
     {
@@ -1825,11 +1864,14 @@ amd_body_stream_size (mu_stream_t stream, mu_off_t *psize)
 static int
 amd_body_size (mu_body_t body, size_t *psize)
 {
+  int status;
   mu_message_t msg = mu_body_get_owner (body);
   struct _amd_message *mhm = mu_message_get_owner (msg);
   if (mhm == NULL)
     return EINVAL;
-  amd_check_message (mhm);
+  status = amd_check_message (mhm);
+  if (status)
+    return status;
   if (psize)
     *psize = mhm->body_end - mhm->body_start;
   return 0;
@@ -1838,11 +1880,14 @@ amd_body_size (mu_body_t body, size_t *psize)
 static int
 amd_body_lines (mu_body_t body, size_t *plines)
 {
+  int status;
   mu_message_t msg = mu_body_get_owner (body);
   struct _amd_message *mhm = mu_message_get_owner (msg);
   if (mhm == NULL)
     return EINVAL;
-  amd_check_message (mhm);
+  status = amd_check_message (mhm);
+  if (status)
+    return status;
   if (plines)
     *plines = mhm->body_lines;
   return 0;


hooks/post-receive
-- 
GNU Mailutils


From MAILER-DAEMON Fri Jan 21 10:31:25 2011
Received: from mailman by lists.gnu.org with archive (Exim 4.43)
	id 1PgIxR-0005pA-67
	for mharc-commit-mailutils@gnu.org; Fri, 21 Jan 2011 10:31:25 -0500
Received: from [140.186.70.92] (port=44137 helo=eggs.gnu.org)
	by lists.gnu.org with esmtp (Exim 4.43) id 1PgIxL-0005l3-66
	for commit-mailutils@gnu.org; Fri, 21 Jan 2011 10:31:23 -0500
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1PgIxA-00081g-FQ
	for commit-mailutils@gnu.org; Fri, 21 Jan 2011 10:31:12 -0500
Received: from colonialone.fsf.org ([140.186.70.51]:37917
	helo=internal.in.savannah.gnu.org)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1PgIxA-00081I-DK
	for commit-mailutils@gnu.org; Fri, 21 Jan 2011 10:31:08 -0500
Received: from [10.1.0.108] (helo=vcs-noshell.in.savannah.gnu.org)
	by internal.in.savannah.gnu.org with esmtp (Exim 4.69)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1PgIxA-0004rb-0S
	for commit-mailutils@gnu.org; Fri, 21 Jan 2011 15:31:08 +0000
Received: from gray by vcs-noshell.in.savannah.gnu.org with local (Exim 4.69)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1PgIx7-0000Sv-8k
	for commit-mailutils@gnu.org; Fri, 21 Jan 2011 15:31:07 +0000
From: "Sergey Poznyakoff" <gray@gnu.org.ua>
To: commit-mailutils@gnu.org
X-Git-Refname: refs/heads/master
X-Git-Reftype: branch
X-Git-Oldrev: d9044ffe99b447598e649b24f5ed49ccb110e15e
X-Git-Newrev: 45d49848cd34a99cc326be9997a4b5d7142898fe
Message-Id: <E1PgIx7-0000Sv-8k@vcs-noshell.in.savannah.gnu.org>
Date: Fri, 21 Jan 2011 15:31:06 +0000
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2)
Subject: [SCM] GNU Mailutils branch, master,
	updated. release-2.2-348-g45d4984
X-BeenThere: commit-mailutils@gnu.org
X-Mailman-Version: 2.1.5
Precedence: list
List-Id: Commit notices for GNU mailutils <commit-mailutils.gnu.org>
List-Unsubscribe: <http://lists.gnu.org/mailman/listinfo/commit-mailutils>,
	<mailto:commit-mailutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/commit-mailutils>
List-Post: <mailto:commit-mailutils@gnu.org>
List-Help: <mailto:commit-mailutils-request@gnu.org?subject=help>
List-Subscribe: <http://lists.gnu.org/mailman/listinfo/commit-mailutils>,
	<mailto:commit-mailutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Fri, 21 Jan 2011 15:31:23 -0000

This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "GNU Mailutils".

http://git.savannah.gnu.org/cgit/mailutils.git/commit/?id=45d49848cd34a99cc326be9997a4b5d7142898fe

The branch, master has been updated
       via  45d49848cd34a99cc326be9997a4b5d7142898fe (commit)
      from  d9044ffe99b447598e649b24f5ed49ccb110e15e (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 45d49848cd34a99cc326be9997a4b5d7142898fe
Author: Sergey Poznyakoff <gray@gnu.org.ua>
Date:   Fri Jan 21 17:29:15 2011 +0200

    Scheme: add primitives for manipulating the MU debug levels.
    
    * include/mailutils/debug.h (mu_debug_get_iterator): New proto.
    * libmailutils/diag/debug.c (mu_debug_get_iterator): New function.
    * libmu_scm/Makefile.am (lib_LTLIBRARIES): Add mu_debug.c.
    
    * include/mailutils/guile.h (mu_scm_debug_init): New proto.
    * libmu_scm/mu_scm.c (mu-register-format): Bugfix.
    (mu_scm_init): Call mu_scm_debug_init.

-----------------------------------------------------------------------

Summary of changes:
 include/mailutils/debug.h    |    4 +-
 include/mailutils/guile.h    |    1 +
 libmailutils/base/iterator.c |    2 +-
 libmailutils/diag/debug.c    |  172 ++++++++++++++++++++++++++++++++++++++++++
 libmu_scm/Makefile.am        |    1 +
 libmu_scm/mu_debug.c         |  134 ++++++++++++++++++++++++++++++++
 libmu_scm/mu_scm.c           |    5 +-
 7 files changed, 315 insertions(+), 4 deletions(-)
 create mode 100644 libmu_scm/mu_debug.c

diff --git a/include/mailutils/debug.h b/include/mailutils/debug.h
index 4c7b930..5072d51 100644
--- a/include/mailutils/debug.h
+++ b/include/mailutils/debug.h
@@ -83,7 +83,9 @@ void mu_debug_log_begin (const char *fmt, ...) MU_PRINTFLIKE(1,2);
 void mu_debug_log_cont (const char *fmt, ...) MU_PRINTFLIKE(1,2);
 void mu_debug_log_end (const char *fmt, ...) MU_PRINTFLIKE(1,2);
 void mu_debug_log_nl (void);
-  
+
+  int mu_debug_get_iterator (mu_iterator_t *piterator, int skipunset);
+
   
 #define MU_ASSERT(expr)						\
  do								\
diff --git a/include/mailutils/guile.h b/include/mailutils/guile.h
index 741d8cf..b990e19 100644
--- a/include/mailutils/guile.h
+++ b/include/mailutils/guile.h
@@ -72,6 +72,7 @@ extern void mu_scm_mutil_init (void);
 SCM mu_scm_make_debug_port (int level);
 void mu_scm_debug_port_init (void);
 
+extern void mu_scm_debug_init (void);
 
 extern void mu_guile_init (int debug);
 extern int mu_guile_load (const char *filename, int argc, char **argv);
diff --git a/libmailutils/base/iterator.c b/libmailutils/base/iterator.c
index 45cb10a..23e4edf 100644
--- a/libmailutils/base/iterator.c
+++ b/libmailutils/base/iterator.c
@@ -146,7 +146,7 @@ mu_iterator_dup (mu_iterator_t *piterator, mu_iterator_t orig)
   if (status)
     return status;
 
-  status = orig->dup(&iterator->owner, orig->owner);
+  status = orig->dup (&iterator->owner, orig->owner);
   if (status)
     {
       free (iterator);
diff --git a/libmailutils/diag/debug.c b/libmailutils/diag/debug.c
index 7bcbb13..124311b 100644
--- a/libmailutils/diag/debug.c
+++ b/libmailutils/diag/debug.c
@@ -32,6 +32,8 @@
 #include <mailutils/wordsplit.h>
 #include <mailutils/stream.h>
 #include <mailutils/stdstream.h>
+#include <mailutils/iterator.h>
+#include <mailutils/cstr.h>
 
 int mu_debug_line_info;          /* Debug messages include source locations */
 
@@ -496,6 +498,176 @@ mu_debug_format_spec (mu_stream_t str, const char *names, int showunset)
   return rc;
 }
 
+
+/* Iterator */
+
+static mu_iterator_t iterator_head;
+
+#define ITR_BACKWARDS 0x01
+#define ITR_SKIPUNSET 0x02
+#define ITR_FINISHED  0x04
+
+struct debug_iterator
+{
+  size_t pos;
+  int flags;
+};
+
+static int
+first (void *owner)
+{
+  struct debug_iterator *itr = owner;
+  itr->flags &= ~ITR_FINISHED;
+  if (itr->flags & ITR_BACKWARDS)
+    itr->pos = catcnt - 1;
+  else
+    itr->pos = 0;
+  return 0;
+}
+
+static int
+next (void *owner)
+{
+  struct debug_iterator *itr = owner;
+  itr->flags &= ~ITR_FINISHED;
+  do
+    {
+      if (itr->flags & ITR_BACKWARDS)
+	{
+	  if (itr->pos)
+	    itr->pos--;
+	  else
+	    itr->flags |= ITR_FINISHED;
+	}
+      else
+	{
+	  if (itr->pos < catcnt - 1)
+	    itr->pos++;
+	  else
+	    itr->flags |= ITR_FINISHED;
+	}
+    }
+  while ((itr->flags & ITR_SKIPUNSET) &&
+	 !(itr->flags & ITR_FINISHED) &&
+	 !cattab[itr->pos].isset);
+
+  return 0;
+}
+
+static int
+getitem (void *owner, void **pret, const void **pkey)
+{
+  struct debug_iterator *itr = owner;
+  *(mu_debug_level_t*) pret = cattab[itr->pos].level;
+  if (pkey)
+    *pkey = cattab[itr->pos].name;
+  return 0;
+}
+
+static int
+finished_p (void *owner)
+{
+  struct debug_iterator *itr = owner;
+  return itr->flags & ITR_FINISHED;
+}
+
+static int
+curitem_p (void *owner, void *item)
+{
+  struct debug_iterator *itr = owner;
+  return mu_c_strcasecmp (cattab[itr->pos].name, (char *) item) == 0;
+}
+
+static int
+list_data_dup (void **ptr, void *owner)
+{
+  *ptr = malloc (sizeof (struct debug_iterator));
+  if (*ptr == NULL)
+    return ENOMEM;
+  memcpy (*ptr, owner, sizeof (struct debug_iterator));
+  return 0;
+}
+
+static int
+list_itrctl (void *owner, enum mu_itrctl_req req, void *arg)
+{
+  struct debug_iterator *itr = owner;
+  
+  switch (req)
+    {
+    case mu_itrctl_tell:
+      /* Return current position in the object */
+      if (!arg)
+	return EINVAL;
+      *(size_t*)arg = itr->pos;
+      break;
+
+    case mu_itrctl_delete:
+    case mu_itrctl_delete_nd:
+      /* Delete current element */
+      cattab[itr->pos].level = 0;
+      cattab[itr->pos].isset = 0;
+      break;
+
+    case mu_itrctl_replace:
+    case mu_itrctl_replace_nd:
+      if (!arg)
+	return EINVAL;
+      cattab[itr->pos].level = *(mu_debug_level_t*)arg;
+      break;
+
+    case mu_itrctl_qry_direction:
+      if (!arg)
+	return EINVAL;
+      else
+	*(int*)arg = itr->flags & ITR_BACKWARDS;
+      break;
+
+    case mu_itrctl_set_direction:
+      if (!arg)
+	return EINVAL;
+      else
+	itr->flags |= ITR_BACKWARDS;
+      break;
+
+    default:
+      return ENOSYS;
+    }
+  return 0;
+}
+
+int
+mu_debug_get_iterator (mu_iterator_t *piterator, int skipunset)
+{
+  int status;
+  mu_iterator_t iterator;
+  struct debug_iterator *itr;
+  
+  itr = malloc (sizeof *itr);
+  if (!itr)
+    return ENOMEM;
+  itr->pos = 0;
+  itr->flags = skipunset ? ITR_SKIPUNSET : 0;
+  status = mu_iterator_create (&iterator, itr);
+  if (status)
+    {
+      free (itr);
+      return status;
+    }
+
+  mu_iterator_set_first (iterator, first);
+  mu_iterator_set_next (iterator, next);
+  mu_iterator_set_getitem (iterator, getitem);
+  mu_iterator_set_finished_p (iterator, finished_p);
+  mu_iterator_set_curitem_p (iterator, curitem_p);
+  mu_iterator_set_dup (iterator, list_data_dup);
+  mu_iterator_set_itrctl (iterator, list_itrctl);
+  
+  mu_iterator_attach (&iterator_head, iterator);
+
+  *piterator = iterator;
+  return 0;
+}
 
 
 void
diff --git a/libmu_scm/Makefile.am b/libmu_scm/Makefile.am
index b870486..de74c99 100644
--- a/libmu_scm/Makefile.am
+++ b/libmu_scm/Makefile.am
@@ -24,6 +24,7 @@ lib_LTLIBRARIES=libmu_scm.la
 C_SRCS=\
  mu_address.c\
  mu_body.c\
+ mu_debug.c\
  mu_dbgport.c\
  mu_guile.c\
  mu_mailbox.c\
diff --git a/libmu_scm/mu_debug.c b/libmu_scm/mu_debug.c
new file mode 100644
index 0000000..0dfcd5b
--- /dev/null
+++ b/libmu_scm/mu_debug.c
@@ -0,0 +1,134 @@
+/* GNU Mailutils -- a suite of utilities for electronic mail
+   Copyright (C) 2011 Free Software Foundation, Inc.
+
+   This library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 3 of the License, or (at your option) any later version.
+
+   This library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General
+   Public License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
+
+#include "mu_scm.h"
+#include <mailutils/iterator.h>
+#include <mailutils/stdstream.h>
+
+SCM_DEFINE_PUBLIC (scm_mu_debug_parse, "mu-debug-parse", 1, 0, 0,
+		   (SCM spec),
+"Parses @var{spec} and sets MU debugging level according to it.")
+#define FUNC_NAME s_scm_mu_debug_parse
+{
+  char *s;
+  
+  SCM_ASSERT (scm_is_string (spec), spec, SCM_ARG1, FUNC_NAME);
+  s = scm_to_locale_string (spec);
+  mu_debug_parse_spec (s);
+  free (s);
+  return SCM_UNSPECIFIED;
+}
+#undef FUNC_NAME
+
+static int
+string_member_p (SCM list, SCM x)
+{
+  return scm_member (x, list) != SCM_BOOL_F;
+} 
+
+SCM_DEFINE_PUBLIC (scm_mu_debug_set, "mu-debug-set", 1, 0, 0,
+		   (SCM catlist),
+"Sets MU debug level according to @var{catlist}, which is a list of\n"
+"conses: (cons category level)\n")  
+#define FUNC_NAME s_scm_mu_debug_set
+{
+  SCM_ASSERT (scm_is_pair (catlist), catlist, SCM_ARG1, FUNC_NAME);
+  for (; !scm_is_null (catlist); catlist = SCM_CDR (catlist))
+    {
+      SCM cell = SCM_CAR (catlist);
+      SCM x;
+      char *name;
+      mu_debug_level_t lev;
+
+      SCM_ASSERT (scm_is_pair (cell), cell, SCM_ARGn, FUNC_NAME);
+      x = scm_car (cell);
+      SCM_ASSERT (scm_is_string (x), x, SCM_ARGn, FUNC_NAME);
+      name = scm_to_locale_string (x);
+      x = scm_cdr (cell);
+      SCM_ASSERT (scm_is_integer (x), x, SCM_ARGn, FUNC_NAME);
+      lev = scm_to_int (x);
+      if (lev == 0)
+	mu_debug_disable_category (name, strlen (name));
+      else
+	mu_debug_enable_category (name, strlen (name), lev);
+      free (name);
+    }      
+  return SCM_UNSPECIFIED;
+}
+#undef FUNC_NAME
+
+SCM_DEFINE_PUBLIC (scm_mu_debug_get, "mu-debug-get", 0, 2, 0,
+		   (SCM catlist, SCM skipunset),
+"Returns a list of MU debugging categories with corresponding levels.\n"
+"If @var{catlist} is supplied, it is a list of category names.  In this case\n"
+"only categories from this list are returned")
+#define FUNC_NAME s_scm_mu_debug_get
+{
+  int skipunset_flag = 0;
+  mu_iterator_t itr;
+  SCM head = SCM_EOL, tail = SCM_EOL;
+  int (*member_p) (SCM list, SCM needle);
+
+  if (SCM_UNBNDP (catlist) || catlist == SCM_BOOL_F)
+    member_p = NULL;
+  else
+    {
+      SCM_ASSERT (scm_is_pair (catlist), catlist, SCM_ARG1, FUNC_NAME);
+      member_p = string_member_p;
+    }
+  
+  if (!SCM_UNBNDP (skipunset))
+    {
+      SCM_ASSERT (scm_is_bool (skipunset), skipunset, SCM_ARG2, FUNC_NAME);
+      skipunset_flag = skipunset == SCM_BOOL_T;
+    }
+
+  mu_debug_get_iterator (&itr, skipunset_flag);
+  for (mu_iterator_first (itr); !mu_iterator_is_done (itr);
+       mu_iterator_next (itr))
+    {
+      const char *name;
+      mu_debug_level_t level;
+      SCM scm_name;
+      
+      mu_iterator_current_kv (itr, (const void**) &name, (void**) &level);
+      scm_name = scm_from_locale_string (name);
+      if (!member_p || member_p (catlist, scm_name))
+	{
+	  SCM scm_new = scm_cons (scm_cons (scm_name,
+					    scm_from_uintmax (level)),
+				  SCM_EOL);
+
+	  if (scm_is_null (head))
+	    head = tail = scm_new;
+	  else
+	    {
+	      SCM_SETCDR (tail, scm_new);
+	      tail = scm_new;
+	    }
+	}
+    }
+  mu_iterator_destroy (&itr);
+  return head;
+}
+#undef FUNC_NAME
+
+void
+mu_scm_debug_init ()
+{
+#include "mu_debug.x"
+}
diff --git a/libmu_scm/mu_scm.c b/libmu_scm/mu_scm.c
index 9e43506..dc24b1e 100644
--- a/libmu_scm/mu_scm.c
+++ b/libmu_scm/mu_scm.c
@@ -128,7 +128,7 @@ SCM_DEFINE_PUBLIC (scm_mu_register_format, "mu-register-format", 0, 0, 1,
 	  SCM_ASSERT (scm_is_string (scm), scm, SCM_ARGn, FUNC_NAME);
 	  s = scm_to_locale_string (scm);
 	  status = register_format (s);
-	  free (scm);
+	  free (s);
 	  if (status)
 	    mu_scm_error (FUNC_NAME, status,
 			  "Cannot register format ~A",
@@ -210,9 +210,10 @@ mu_scm_init ()
   mu_scm_port_init ();
   mu_scm_mime_init ();
   mu_scm_debug_port_init ();
+  mu_scm_debug_init ();
   
 #include "mu_scm.x"
-
+  
   mu_registrar_record (MU_DEFAULT_RECORD);
   mu_registrar_set_default_record (MU_DEFAULT_RECORD);
 }


hooks/post-receive
-- 
GNU Mailutils


