commit-mailutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[SCM] GNU Mailutils branch, master, updated. release-3.1.1-30-g51c5ad1


From: Sergey Poznyakoff
Subject: [SCM] GNU Mailutils branch, master, updated. release-3.1.1-30-g51c5ad1
Date: Sat, 14 Jan 2017 09:51:57 +0000 (UTC)

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=51c5ad1b37723b9c61d19a5a4dcff6fb28c7b836

The branch, master has been updated
       via  51c5ad1b37723b9c61d19a5a4dcff6fb28c7b836 (commit)
       via  2229fcdcea4cbd56de54afb70ebfca1cf352f9d0 (commit)
      from  eabddf8f5f18afddc13281a5fbaa562f75e76b5f (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 51c5ad1b37723b9c61d19a5a4dcff6fb28c7b836
Author: Sergey Poznyakoff <address@hidden>
Date:   Sat Jan 14 11:46:21 2017 +0200

    docs: improve the attachment section.
    
    * doc/texinfo/programs.texi: provide an example script illustrating
    how to use mail from another programs.

commit 2229fcdcea4cbd56de54afb70ebfca1cf352f9d0
Author: Sergey Poznyakoff <address@hidden>
Date:   Sat Jan 14 11:44:47 2017 +0200

    Re-introduce the --HANG hidden option.
    
    * libmailutils/cli/cli.c (mu_common_options): Declare the --HANG
    option.
    (hangproc): New function.

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

Summary of changes:
 doc/texinfo/programs.texi |  111 ++++++++++++++++++++++++++++++++++++++++-----
 libmailutils/cli/cli.c    |   20 +++++++-
 2 files changed, 118 insertions(+), 13 deletions(-)

diff --git a/doc/texinfo/programs.texi b/doc/texinfo/programs.texi
index 7d1a6ec..ec10d86 100644
--- a/doc/texinfo/programs.texi
+++ b/doc/texinfo/programs.texi
@@ -3510,9 +3510,9 @@ $ mail -E 'set nonullbodymsg' --attach=archive.tar < 
/dev/null
 @end example
 
 The option @option{--attach=-} forces @command{mail} to read the file
-to be attached from the standard input stream.  This option implies
-disables the interactive mode and sets @samp{nonullbodymsg}
-implicitly, so that the above example can be rewritten as:
+to be attached from the standard input stream.  This option disables
+the interactive mode and sets @samp{nonullbodymsg} implicitly, so that
+the above example can be rewritten as:
 
 @example
 $ mail --attach=- < archive.tar
@@ -3527,20 +3527,109 @@ above example is equivalent to:
 $ mail --attach-fd=0 < archive.tar
 @end example
 
-Attachments created using this option have neither filename not
+Attachments created with this option have neither filename nor 
 description set, so normally the use of @option{--content-name} and/or
 @option{--content-filename} is advised.
 
+The following Perl program serves as an example of using
address@hidden from a script to construct a MIME message on the fly.
+It scans all mounted file systems for executable files that have
+setuid or setgid bits set and reports the names of those files in
+separate attachments.  Each attachment is named after the mountpoint
+it describes.
+
+The script begins with the usual prologue stating the modules that
+will be used:
+
address@hidden
+#!/usr/bin/perl
+
+use strict;
+use autodie;
address@hidden example
+
+Then global variables are declared.  The @samp{@@rcpt} array contains
+the email addresses of the recipients:
+
address@hidden
+my @@rcpt= 'root@@example.com';
address@hidden example
+
+The @samp{@@cmd} variable holds the @command{mail} command line.  It
+will be augmented for each file system.  The initial value is set as
+follows:
+
 @example
-$ mail --subject 'mail(1)' \
-       --content-name="The mail(1) binary" --content-filename="mail" \
-       --attach-fd 5 \
-       --encoding=binary --content-type=text/plain \
-       --content-name="mail.c source file" --content-filename=mail.c \
-       --attach-fd 6 gray@@example.org 5</usr/bin/mail \
-       6<mailutils/mail/mail.c
+my @@cmd = ('mail',
+           '-E set nonullbodymsg',
+           '--content-type=text/plain');
 @end example
 
+The @command{find} utility will be used to locate the files.  The
+script will start as many instances as there are mountpoints.  Those
+instances will be run in parallel and their standard output streams
+will be connected to file descriptors passed to @command{mail}
+invocation in @option{--attach-fd} options.
+
+The descriptors will be held in @samp{@@fds} array.  This will prevent
+them from being wiped out by the garbage collector.  Furthermore, care
+should be taken to ensure that the @code{O_CLOECEC} flag be not set
+for these descriptors.  This sample script takes a simplistic approach:
+it instructs Perl to not close first 255 descriptors when executing
+another programs:
+
address@hidden
+my @@fds;
+$^F = 255;
address@hidden example
+
+The following code obtains the list of mount points:
+
address@hidden
+open(my $in, '-|', 'mount -t nonfs,noproc,nosysfs,notmpfs');
+while (<$in>) @{
+    chomp;
+    if (/^\S+ on (?<mpoint>.+) type (?<fstype>.+) /) @{
address@hidden example
+
+For each mountpoint, the @command{find} command line is constructed
+and launched.  The file descriptor is pushed to the @samp{@@fds} array
+to prevent it from being collected by the garbage collector:
+
address@hidden
+       open(my $fd, '-|',
+            "find address@hidden@} -xdev -type f"
+             . " \\( -perm -u+x -o -perm -g+x -o -perm -o+x \\)"
+             . " \\( -perm -u+s -o -perm -g+s \\) -print");
+       push @@fds, $fd;
address@hidden example
+
+Now, the @command{mail} command is instructed to create next
+attachment from that file descriptor:
+
address@hidden
+       my $mpname = address@hidden@};
+       $mpname =~ address@hidden/@address@hidden@}; 
+       push @@cmd,
+             "--content-name=Set[ug]id files on address@hidden@} (type 
address@hidden@})",
+            "--content-filename=$mpname.list",
+            '--attach-fd=' . fileno($fd);
+    @}
address@hidden
+close $in;
address@hidden example
+
+Finally, the emails of the recipients are added to the command line,
+the standard input is closed to make sure @command{mail} won't enter
+the interactive mode and the constructed command is executed:
+
address@hidden
+push @@cmd, @@rcpt;
+close STDIN;
+system(@@cmd);
address@hidden example
+
+
 @c *********************************************************************
 
 @node Reading Mail
diff --git a/libmailutils/cli/cli.c b/libmailutils/cli/cli.c
index 6e881f4..33bc417 100644
--- a/libmailutils/cli/cli.c
+++ b/libmailutils/cli/cli.c
@@ -160,7 +160,7 @@ config_verbose (struct mu_parseopt *po, struct mu_option 
*opt,
 
 static void
 config_lint (struct mu_parseopt *po, struct mu_option *opt,
-               char const *arg)
+            char const *arg)
 {
   struct app_data *dp = po->po_data;
   dp->lint = 1;
@@ -183,11 +183,27 @@ param_set (struct mu_parseopt *po, struct mu_option *opt, 
char const *arg)
   mu_cfg_tree_add_node (dp->append_tree, node);
 }
 
+static void
+hangproc (struct mu_parseopt *po, struct mu_option *opt, char const *arg)
+{
+  int n;
+  if (mu_str_to_c (arg, mu_c_int, &n, NULL))
+    {
+      mu_parseopt_error (po, _("%s: bad number"), arg);
+      exit (po->po_exit_error);
+    }
+  mu_wd (n);
+}
+
 struct mu_option mu_common_options[] = {
   /*  MU_OPTION_GROUP(N_("Common options")),*/
-  { "program-name",   0,  N_("NAME"),  MU_OPTION_IMMEDIATE|MU_OPTION_HIDDEN,
+  { "program-name",   0,  N_("NAME"),    MU_OPTION_IMMEDIATE|MU_OPTION_HIDDEN,
     N_("set program name"),
     mu_c_string, NULL, change_progname },
+  { "HANG",           0,  N_("SECONDS"),
+    MU_OPTION_IMMEDIATE|MU_OPTION_ARG_OPTIONAL|MU_OPTION_HIDDEN,
+    N_("wait this number of seconds before startup"),
+    mu_c_string, NULL, hangproc, "3600" },
   MU_OPTION_END
 };
 


hooks/post-receive
-- 
GNU Mailutils



reply via email to

[Prev in Thread] Current Thread [Next in Thread]