User Utilities

 < Free Open Study > 



qmail includes a few utilities that are useful in dot-qmail files and for managing mailboxes. The dot-qmail utilities are handy for constructing dot-qmail files that do conditional delivery and bounces. The mailbox utilities are geared toward making maildir mailboxes work in Unix's historically mbox-oriented environment.

bouncesaying

Usage: bouncesaying error-message [command]

Description: The bouncesaying command accepts an error message and an optional command to be run. If a command is supplied, it's run with the current message on standard input. If the command exits with a successful code (zero), or no command is supplied, bouncesaying prints the error message and exits with the code 100 (hard error), causing a bounce message to be generated and interrupting the processing of the dot-qmail file. If the command exits with the code 111 (soft error), bouncesaying also exits with 111 so the delivery will be retried later. If the command exits with any other code, bouncesaying exits with code 0 (zero) without printing the error message.

Caveats: If you create a .qmail file to use bouncesaying, you must also add a line to deliver messages to your mailbox because the default delivery instructions will no longer be used.

Examples: To unconditionally bounce all messages handled by a dot-qmail file:

 |bouncesaying "This mailbox has been deactivated." 

The bounce message generated as a result of delivering to this dot-qmail file will look like this:

 From MAILER-DAEMON Sun Apr 22 17:55:27 2001 Date: 22 Apr 2001 17:55:27 -0000 From: MAILER-DAEMON@sparge.example.com To: debbie@example.net Subject: failure notice Hi. This is the qmail-send program at sparge.example.com. I'm afraid I wasn't able to deliver your message to the following addresses. This is a permanent error; I've given up. Sorry it didn't work out. <bounce@sparge.example.com>: This address has been deactivated. —- Below this line is a copy of the message. Return-Path: <debbie@example.net> Received: (qmail 6863 invoked by uid 500); 22 Apr 2001 17:55:27 -0000 Message-ID: <20010422175527.6862.qmail@example.net> Date: Sun, 22 Apr 2001 13:55:27 -0400 From: debbie@example.net To: bounce@sparge.example.com 

To bounce only those messages containing the string Subject: MAKE MONEY FAST and deliver everything else to $HOME/Maildir:

 |bouncesaying "Go away." grep "^Subject: MAKE MONEY FAST" ./Maildir/ 

condredirect

Usage: condredirect address command

Description: The condredirect command accepts an e-mail address and a command to be run. The command is run with the current message on standard input. If the command exits with a successful code (zero), condredirect forwards the message to the supplied address and exits with the code 99, interrupting the processing of the dot-qmail file. If the command exits with the code 111 (soft error), condredirect also exits with 111 so the delivery will be retried later. If the command exits with any other code or doesn't exist, condredirect exits with code 0 (zero) without forwarding message.

Caveats: If you create a .qmail file to use condredirect, you must also add a line to deliver messages to your mailbox because the default delivery instructions will no longer be used.

Example: To forward messages containing the string

Project X to project-x@example.com and deliver everything else to $HOME/Mailbox:

 |condredirect project-x@example.com grep -i "project x" ./Mailbox 

datemail

Usage: Same as sendmail

Description: datemail is a simple shell script wrapper around the qmail sendmail command. It uses predate to insert a Date header field in the local time zone. This is useful when injecting messages via sendmail with an MUA that doesn't include a Date field. qmail-inject will add a Date field to messages lacking one, but it uses Greenwich Mean Time (GMT) instead of the local time zone, which can be confusing.

Caveats: datemail doesn't check to see if a message contains a Date field before adding one, so it should only be used to inject messages that don't already contain one.

Example: Sending a simple test message using the command:

 echo to: root | /var/qmail/bin/sendmail -t 

results in a message like this:

 Date: 23 Apr 2001 01:11:15 -0000 From: root@mash.example.com to: root@mash.example.com 

Using datemail, however:

 echo to: root | /var/qmail/bin/datemail -t 

results in a message like this:

 From: root@mash.example.com Date: 22 Apr 2001 21:11:30 -0400 to: root@mash.example.com 

Note that the Date field in the second test message contains -0400, which means the local time zone is four hours behind GMT, in this case it is Eastern Daylight Savings Time.

elq

Usage: MAILDIR=maildir MAIL=mbox MAILTMP=tempfile elq

Description: elq is simple shell script wrapper that runs maildir2mbox before invoking the elm MUA. The elq wrapper allows one to use maildir delivery with elm, which doesn't support maildir mailboxes.

Caveats: Because the maildir mailbox is only converted to mbox format before elm is invoked, messages that arrive while the user is in elq won't be seen. Because elq runs maildir2mbox, the MAILDIR, MAIL, and MAILTMP environment variables must be set appropriately before running elq. See the "maildir2mbox" section for details.

except

Usage: except command

Description: except runs command and converts the exit code in a manner that reverses success and failure as bouncesaying and condredirect define them. If the command exits with code zero, except exits with code 100. If the command exits with code 111, except also exits with code 111. In all other cases, except exits with code zero.

Caveats: If you create a .qmail file to use except, you must also add a line to deliver messages to your mailbox because the default delivery instructions will no longer be used.

Example: Say you want to bounce all messages that don't contain a certain header field and you want messages that do contain the header field to be filed in $HOME/Maildir:

 |bouncesaying "Permission denied." except grep "^Password: nauseous ossifrage$" ./Maildir/ 

forward

Usage: forward addresses

Description: forward reads a message on standard input and forwards a copy to each address. forward is handy because the addresses specified can be constructed at the time of delivery, whereas forward deliveries in dot-qmail files are static.

Caveats: If you create a .qmail file to use forward, and you want to keep a copy of the forwarded message, you must also add a line to deliver messages to your mailbox because the default delivery instructions will no longer be used.

Example: To forward all undeliverable local mail to a local mail server, put the following in /var/qmail/alias/.qmail-default, the system-wide catchall alias:

 |forward "$LOCAL@mailhub.example.com" 

Tip 

Although it's not documented in the man page, forward uses the NEWSENDER and DTLINE qmail-command environment variables. Setting these variables before calling forward could be useful in configurations that masquerade users or hosts.

maildir2mbox

Usage: MAILDIR=maildir MAIL=mbox MAILTMP=tempfile maildir2mbox

Description: maildir2mbox moves mail messages from the specified maildir to the specified mbox using the specified temporary file. Note that the three arguments to maildir2mbox are passed through environment variables, not command line arguments.

Caveats: MAILTMP and MAIL must reside on the same file system. If MAILTMP and MAIL contain relative path names (they don't start with a slash), they're relative to MAILDIR, not the current working directory at the time maildir2mbox is executed. maildir2mbox locks MAIL to prevent simultaneous access by MUAs, but other maildir2mbox processes are not locked out so you should be careful to run only one maildir2mbox at a time.

Example: User maryjane wants the messages in $HOME/Maildir moved to $HOME/Mailbox:

 $ MAILDIR=~/Maildir $ MAIL=~/Mailbox $ MAILTMP=~/mailtemp $ export MAILDIR MAIL MAILTMP $ ls Mailbox ls: Mailbox: No such file or directory $ maildir2mbox $ ls -l Mailbox -rw-------   1 maryjane maryjane    18719 Apr 22 22:45 Mailbox $ 

maildirmake

Usage: maildirmake dir

Description: maildirmake creates an empty maildir mailbox in the specified directory.

Caveats: maildirmake must be run as the user that owns the mailbox or qmail-local will defer deliveries.

Example: User dixie wants to create a maildir in $HOME/Maildir:

 $ maildirmake ~/Maildir $ ls -ld ~/Maildir drwx------    5 dixie    dixie       4096 May  9 19:54 Maildir $ ls -l ~/Maildir total 12 drwx------    2 dixie    dixie       4096 May  9 19:54 cur drwx------    2 dixie    dixie       4096 May  9 19:54 new drwx------    2 dixie    dixie       4096 May  9 19:54 tmp $ 

maildirwatch

Usage: MAILDIR=maildir maildirwatch

Description: Watches the maildir mailbox specified by the MAILDIR environment variable and prints a message when new mail arrives. maildirwatch is intended to be run in its own terminal window.

Caveats: maildirwatch uses VT100 escape sequences, so run it in a VT100-compatible terminal emulator such as xterm.

Example: A user wants to be notified when new mail is delivered to $HOME/Maildir:

 $ MAILDIR=$HOME/Maildir $ export MAILDIR $ maildirwatch screen clears FROM <george@turkey.example.com> TO <dixie@dog.example.com> From: "George" <george@turkey.example.com> Feeding time//Hey, when do they feed you?//-George// 

mailsubj

Usage: mailsubj subject recipients

Description: mailsubj creates a new message with the specified subject and the body read from standard input, and sends it to the listed recipients.

Caveats: None

Example: A user wants to send a quick message without using a full-featured MUA:

 $ mailsubj "Re: Feeding time" george@turkey.example.com Usually in the morning. -Dixie ^D $ 

pinq

Usage: MAILDIR=maildir MAIL=mbox MAILTMP=tempfile pinq

Description: pinq is simple shell script wrapper that runs maildir2mbox before invoking the pine MUA. The pinq wrapper allows one to use maildir delivery with pine, which doesn't support maildir mailboxes without patching.

Caveats: Because the maildir mailbox is only converted to mbox format before pine is invoked, messages that arrive while the user is in pinq won't be seen. Because pinq runs maildir2mbox, the MAILDIR, MAIL, and MAILTMP environment variables must be set appropriately before running pinq. See the maildir2mbox section for details.

predate

Usage: predate command

Description: predate outputs a date header field to standard output, copies standard input to standard output, and runs command. It's used to implement the datemail command.

Caveats: None

Example: To generate a date header field with the current time and date:

 $ predate cat </dev/null Date: 12 May 2001 08:01:24 -0400 $ 

In this example, predate is run with null input and the program it runs is cat, which simply echoes its input—the date field generated by predate.

preline

Usage: preline [-d] [-f] [-r] command

Description: The preline command reads a mail message on standard input, prepends one or more lines, and runs the supplied command with the expanded message on standard input. By default, an mbox-style From line, a Return-Path header field, and a Delivered-To header field are added to the message. The -d option suppresses the Delivered-To field, the -f suppresses the From line, and the -r suppresses the Return-Path field. preline is for running MDAs that expect From headers or aren't aware of the environment variables that qmail provides.

Caveats: Because it expects to be run from a dot-qmail file, preline requires the environment to contain the UFLINE, RPLINE, and DTLINE variables.

Example: User doug wants to run the procmail MDA from .qmail. Because procmail expects the messages it receives to start with a From line, preline is used:

 |preline procmail doug 

qail

Usage: MAILDIR=maildir MAIL=mbox MAILTMP=tempfile qail

Description: qail is simple shell script wrapper that runs maildir2mbox before invoking the mail MUA. The qail wrapper allows one to use maildir delivery with mail, which doesn't support maildir mailboxes.

Caveats: Because the maildir mailbox is only converted to mbox format before mail is invoked, messages that arrive while the user is in qail won't be seen. Because qail runs maildir2mbox, the MAILDIR, MAIL, and MAILTMP environment variables must be set appropriately before running qail. See the "maildir2mbox" section for details.

qreceipt

Usage: qreceipt myaddress

Description: The qreceipt command scans a message on standard input for a header field matching Notice-Requested-Upon-Delivery-To: myaddress. If a match is found, qreceipt sends a confirmation message to the envelope sender.

Caveats: If you create a .qmail file to enable qreceipt, you must also add a line to deliver messages to your mailbox because the default delivery instructions will no longer be used.

Examples: User ebony on host cat.example.com wants to set her .qmail file to confirm delivery of messages. Her mail is currently being delivered to $HOME/Maildir by default. She creates the following .qmail file:

 ./Maildir/ |qreceipt ebony@cat.example.com 

To test her change, she sends herself a message that looks like this:

 From: Ebony <ebony@cat.example.com> To: ebony@cat.example.com Subject: test Notice-Requested-Upon-Delivery-To: ebony@cat.example.com Testing qreceipt. 

Shortly after sending the message, she receives two messages: the test message above and a confirmation message from qreceipt:

 From: DELIVERY NOTICE SYSTEM <ebony@cat.example.com> To: <ebony@cat.example.com> Subject: success notice Hi! This is the qreceipt program. Your message was delivered to the following address: ebony@cat.example.com. Thanks for asking. Your Message-ID: <20010512131945.14882.qmail@cat.example.com> 



 < Free Open Study > 



The Qmail Handbook
The qmail Handbook
ISBN: 1893115402
EAN: 2147483647
Year: 2001
Pages: 186
Authors: Dave Sill

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net