home | help
MBAR(1) 		     General Commands Manual			 MBAR(1)

NAME
     mbar - mailbox archiver

SYNOPSIS
     mbar [-DVciknstvx?] [-a DATE] [-b DATE] [-f FILE] [-I DIR] [-L DIR] [-m
     NUM] [-p PAT] [-r MODULE] [-x PAT] [--after-date=DATE] [--before-date=DATE]
     [--clear-include-path] [--clear-library-path] [--clearpath]
     [--compile-only] [--config-file=FILE] [--config-help] [--config-lint]
     [--config-verbose] [--debug-level=LEVEL] [--debug-line-info] [--dry-run]
     [--dump] [--environment=NAME=VALUE] [--exclude=PAT] [--help]
     [--includedir=DIR] [--instructions] [--keep] [--libdir=DIR]
     [--libdir-prefix=DIR] [--locus] [--log-facility=FACILITY]
     [--mailbox-type=TYPE] [--maxdepth=NUM] [--no-config] [--no-site-config]
     [--no-user-config] [--pattern=PAT] [--pattern-type=glob|imap|regex]
     [--require=MODULE] [--set=PARAM=VALUE] [--show-config-options]
     [--statistics] [--template-file=FILE] [--trace] [--usage]
     [--variable=NAME=VALUE] [--verbose] [--version] DIR DEST [EXPR]

DESCRIPTION
     Scans  directory  DIR  for mailboxes matching pattern (by default - *, i.e.
     all mailboxes).  For each mailbox, messages matching the supplied	criteria
     are picked and moved to the mailbox of the same name, located under the di-
     rectory DEST.  If the destination mailbox doesn't exist, it will be created
     with  the	necessary  intermediate directories, so that directory hierarchy
     under DEST is identical to that under DIR.

     When no selection criteria are supplied, mbar moves all  messages	in  each
     mailbox.

     The  -b  (--before-date) option instructs mbar to archive only messages re-
     ceived before the date indicated by its argument.	 The  option  -a  (--af-
     ter-date)	is  similar,  except that it selects messages received after the
     given date.  The two options can be used together to define a time range.

     A wide variety of date formats are understood.  For a  detailed  discussion
     of   them,   see	http://mailutils.org/manual/html_section/Date-Input-For-
     mats.html.

     For example, the following example will archive messages received more than
     one year ago:

     mbar -b '1 year ago' /var/mail /var/backups/mail

     More complex criteria can be provided using  the  EXPR  optional  argument.
     The  value of this argument must be a valid Sieve conditional, suitable for
     use in the if statement.

     For example, the -b DATE option described above is a shortcut for	specify-
     ing the following as EXPR:

     timestamp :before "Date" "DATE"

     The  utility  works by creating a Sieve script using the supplied criterion
     as a condition and by executing this script on each mailbox encountered.

     The script is built by preprocessing a template text.   During  preprocess-
     ing,  references  to macro variables in form $VAR or ${VAR} are expanded to
     the actual value of the corresponding macro variable.

     Apart from these basic forms, all forms supported by POSIX shell  are  also
     allowed, e.g. ${VAR:-default}, ${VAR##prefix}, etc.

     The following macro variables are defined:

     cond   Expands to the condition expression

     requires
	    Expands  to a comma-separated list of additional requires needed for
	    successful compilation of the Sieve  script.   Such  additional  re-
	    quires  are supplied via the -r (--require) command line option. No-
	    tice, that unless the list	is  empty,  the  expansion  of	requires
	    starts with a comma.

     keep   Expands  to 1 if the -k (--keep) option is given and to empty string
	    otherwise.

     The template can refer also to Sieve variables (RFC 5229).  Such references
     must be preceded with backslashes to prevent them from  being  expanded  as
     macro variables.  The following Sieve variables are always defined:

     source
	    Pathname of the source mailbox, relative to DIR.

     dest   Pathname of the destination mailbox, relative to DEST.

     The  user	can  define  any  number  of  Sieve  variables using the --vari-
     able=NAME=VALUE command line option.

     The default template script is:

     require ["fileinto"${requires}];
     if ${cond} {
	 fileinto "\${dest}";${keep:+keep;}
     }

OPTIONS
     -a, --after-date=DATE
	    Archive messages received after DATE.

     -b, --before-date=DATE
	    Archive messages received before DATE.

     -c, --compile-only
	    Compile Sieve script and exit.  Use this to check the script syntax,
	    if you supply EXPR explicitly and/or provide your own template file.

	    Using this option together with -v shows additionally output of  the
	    template preprocessing phase.

     -D, --dump
	    Compile script, dump disassembled sieve code to terminal and exit.

     --environment=NAME=VALUE
	    Set sieve environment value (RFC 5183).

     -f, --template-file=FILE
	    Read template from FILE, instead of using built-in template.

     -i, --instructions
	    Show sieve instruction trace.

     -k, --keep
	    Don't remove messages after archiving.

     --locus
	    Show action locations with verbose output.

     -m, --maxdepth=NUM
	    Limit directory scanning to the nesting depth NUM.

     --mailbox-type=TYPE
	    Set type of destination mailboxes.

     -n, --dry-run
	    Don't do anything: print what would have been done.

     -p, --pattern=PAT
	    Archive  mailboxes	matching  pattern  PAT.   The pattern is matched
	    against mailbox name relative to DIR.   Unless  indicated  otherwise
	    (see --pattern-type below), PAT is treated as in glob(7).

	    If	this  option is used multiple times, mailboxes that match any of
	    the supplied patterns will be archived.

	    If PAT starts with the character @, remaining characters are treated
	    as the name of the file from  which  to  read  patterns.   The  file
	    should list each pattern on a separate line.  Additional leading and
	    trailing  whitespace  is  allowed.	Empty lines are ignored.  A line
	    starting with # is a comment and is ignored as well.  To start  pat-
	    tern  with	a  sharp, precede it with a backslash.	This is the only
	    case where backslash has a special meaning, otherwise it is  treated
	    as a regular character.

     -T, --pattern-type=TYPE
	    Set  type  of the pattern used with -e and -p options.  Valid values
	    for TYPE are:

	    glob   Globbing pattern (glob(7)).	This is the default.

	    imap   IMAP pattern.  Two wildcards are  allowed:  *,  that  matches
		   zero  or  more  characters,	and %, that is similar to *, but
		   doesn't match hierarchy delimiter (/).

	    regex  POSIX extended regular expression.

     -r, --require=MODULE
	    Require MODULE in the produced Sieve script.  Notice that  variables
	    are  always  required, and fileinto is required by the built-in tem-
	    plate.

	    Technically, this option appends ,MODULE to  the  value  of  require
	    meta-variable (see above).

     -s, --statistics
	    Collect  additional  statistics about messages processed and display
	    it at the end of the run.  The statistics includes	number	of  mes-
	    sages  and size of the data archived and processed.  This option im-
	    plies first level of verbosity (i.e. -v).  Example output:

	    scanned 9 mailboxes in 16 folders
	    messages: 1879/13085
	    size: 6505/4670425

     -t, --trace
	    Enable sieve trace.

     --variable=NAME=VALUE
	    Define Sieve variable NAME (RFC 5229).

     -v, --verbose
	    Verbosely print what is being done.  This option is incremental.  In
	    normal mode (i.e. without -c option), the effect is as follows:

	    -v	   Print a one-line description of each mailbox being archived.

	    -vv    Print  a  one-line  description  of	each  mailbox	(whether
		   archived or not) and each directory descended into.

		   The	description consists of three columns, separated by sin-
		   gle horizontal spaces.  Column one consists of three  charac-
		   ters,  in this order: d for directories, m for mailboxes, and
		   + for archived mailboxes.  A - is placed instead of each let-
		   ter that doesn't apply.

		   Column two is the nesting level,  and  column  three  is  the
		   pathname.  These two are computed relative to DIR.

		   An example of this output:

		   d--	  0 mail
		   d--	  1 mail/others
		   dm-	  2 mail/others/drafts
		   dm+	  1 mail/inbox

	    -vvv   Additionally output the preprocessed Sieve script listing.

	    -vvvv  Additionally  enables  Sieve action tracing.  This can be en-
		   abled separately, using the -t option, which see.

	    When used together with -c (--compile-only), one -v  option  outputs
	    the  preprocessed  Sieve  script template with line numbers.  Two -v
	    options output additionally the disassembled script.

     -x, --exclude=PAT
	    Exclude from archiving mailboxes that match the  pattern  PAT.   See
	    the description of -p (--pattern) above, for a discussion of PAT and
	    its possible forms.

	    Multiple options are allowed.

	    If	both --pattern and --exclude are used, the latter has precedence
	    over the former, i.e. a mailbox will be archived only if it  matches
	    at	least  one of --pattern options and does not match any --exclude
	    option.

STANDARD MAILUTILS OPTIONS
   Global debugging settings
     --debug-level=LEVEL
	    Set Mailutils debugging level. This is especially  useful  with  the
	    following sieve levels:

	    trace1
		   Print parse tree before optimization.

	    trace2
		   Print parse tree after optimization.

	    trace3
		   Print parser traces.

	    trace4
		   Print  tests and actions being executed.  This is the same as
		   --trace.

	    trace9
		   Print each Sieve instruction being executed.

	    Remember, that by default each trace level includes all levels  pre-
	    ceding  it.  To get the output of that level only, prefix it with an
	    equals sign.  For example, to get a step-by-step trace, use:

	    --debug-level=sieve.=trace9

     --debug-line-info
	    Show source info with debugging messages.

     --log-facility=FACILITY
	    Output logs to this syslog facility.

   Sieve options
     --clear-include-path
	    Clear Sieve include path.

     --clear-library-path, --clearpath
	    Clear Sieve library path.

     -I, --includedir=DIR
	    Append DIR to the list of directories searched for include files.

     -L, --libdir=DIR
	    Append DIR to the list of directories searched for library files.

     --libdir-prefix=DIR
	    Add DIR to the beginning of the list of directories searched for li-
	    brary files.

   Configuration handling
     --config-file=FILE
	    Load this configuration file; implies --no-config.

     --config-lint
	    Check configuration file syntax and exit.

     --config-verbose
	    Verbosely log parsing of the configuration files.

     --no-config
	    Don't load site and user configuration files.

     --no-site-config
	    Don't load site-wide configuration file.

     --no-user-config
	    Don't load user-specific configuration file.

     --set=PARAM=VALUE
	    Set configuration parameter.

   Informational options
     --config-help
	    Show configuration file summary.

     --show-config-options
	    Show compilation options.

     -?, --help
	    Give a short command line help summary.

     --usage
	    Output a short usage message.

     -V, --version
	    Print program version.

EXIT CODES
     The exit codes conform with /usr/include/sysexits.h:

     0	    Success.

     64 (EX_USAGE)
	    Command line usage error.

     69 (EX_UNAVAILABLE)
	    Unable to create mailbox or intermediate directories.

     70 (EX_SOFTWARE)
	    Internal software error.  Please report if you ever  encounter  this
	    exit code.

     71 (EX_OSERR)
	    System error (can't change effective UID, allocate memory, etc.)

     78 (EX_CONFIG)
	    Error in Sieve script template.

SEE ALSO
     http://mailutils.org/manual/html_chapter/Sieve-Language.html.	glob(7),
     regex(7).

AUTHORS
     Sergey Poznyakoff

BUG REPORTS
     Report bugs to <gray@gnu.org>.

COPYRIGHT
     Copyright (C) 2016, 2019, 2025 Sergey Poznyakoff
     License GPLv3+: GNU GPL version 3 or later <http://gnu.org/li-
     censes/gpl.html>
     This is free software: you are free to change and redistribute  it.   There
     is NO WARRANTY, to the extent permitted by law.

MBAR				October 17, 2025			 MBAR(1)

home | help