Bugfix: "sendmail -t" broke with unrecognized message headers.
+20030419
+
+ Feature: "postcat -q" searches the queue for the named file.
+
+ Cleanup: made postcat "record names" output more consistent.
+
Open problems:
Low: smtp-source may block when sending large test messages.
postcat - show Postfix queue file contents
<b>SYNOPSIS</b>
- <b>postcat</b> [<b>-v</b>] [<i>files</i>...]
+ <b>postcat</b> [<b>-vq</b>] [<b>-c</b> <i>config_dir</i>] [<i>files</i>...]
<b>DESCRIPTION</b>
- The <b>postcat</b> command prints the contents of the named Post-
- fix queue <i>files</i> in human-readable form. If no <i>files</i> are
- specified on the command line, the program reads from
- standard input.
+ The <b>postcat</b> command prints the contents of the named <i>files</i>
+ in human-readable form. The files are expected to be in
+ Postfix queue file format. If no <i>files</i> are specified on
+ the command line, the program reads from standard input.
Options:
+ <b>-c</b> <i>config_dir</i>
+ The <b>main.cf</b> configuration file is in the named
+ directory instead of the default configuration
+ directory.
+
+ <b>-q</b> Search the Postfix queue for <i>files</i>. By default,
+ file names are taken literally.
+
<b>-v</b> Enable verbose logging for debugging purposes. Mul-
- tiple <b>-v</b> options make the software increasingly
+ tiple <b>-v</b> options make the software increasingly
verbose.
<b>DIAGNOSTICS</b>
Problems are reported to the standard error stream.
+<b>ENVIRONMENT</b>
+ <b>MAIL</b><i>_</i><b>CONFIG</b>
+ Directory with Postfix configuration files.
+
+<b>CONFIGURATION</b> <b>PARAMETERS</b>
+ See the Postfix <b>main.cf</b> file for syntax details and for
+ default values. Use the <b>postfix</b> <b>reload</b> command after a
+ configuration change.
+
+ <b>queue</b><i>_</i><b>directory</b>
+ Top-level directory of the Postfix queue. This is
+ also the root directory of Postfix daemons that run
+ chrooted.
+
<b>LICENSE</b>
- The Secure Mailer license must be distributed with this
+ The Secure Mailer license must be distributed with this
software.
<b>AUTHOR(S)</b>
The names of queues that are organized into multi-
ple levels of subdirectories.
+ <b>queue</b><i>_</i><b>directory</b>
+ Top-level directory of the Postfix queue. This is
+ also the root directory of Postfix daemons that run
+ chrooted.
+
<b>SEE</b> <b>ALSO</b>
<a href="sendmail.1.html">sendmail(1)</a> sendmail-compatible user interface
<a href="postqueue.1.html">postqueue(1)</a> unprivileged queue operations
.SH SYNOPSIS
.na
.nf
-\fBpostcat\fR [\fB-v\fR] [\fIfiles\fR...]
+\fBpostcat\fR [\fB-vq\fR] [\fB-c \fIconfig_dir\fR] [\fIfiles\fR...]
.SH DESCRIPTION
.ad
.fi
The \fBpostcat\fR command prints the contents of the named
-Postfix queue \fIfiles\fR in human-readable form. If no
+\fIfiles\fR in human-readable form. The files are expected
+to be in Postfix queue file format. If no
\fIfiles\fR are specified on the command line, the program
reads from standard input.
Options:
+.IP "\fB-c \fIconfig_dir\fR"
+The \fBmain.cf\fR configuration file is in the named directory
+instead of the default configuration directory.
+.IP \fB-q\fR
+Search the Postfix queue for \fIfiles\fR. By default,
+file names are taken literally.
.IP \fB-v\fR
Enable verbose logging for debugging purposes. Multiple \fB-v\fR
options make the software increasingly verbose.
.ad
.fi
Problems are reported to the standard error stream.
+.SH ENVIRONMENT
+.na
+.nf
+.ad
+.fi
+.IP \fBMAIL_CONFIG\fR
+Directory with Postfix configuration files.
+.SH CONFIGURATION PARAMETERS
+.na
+.nf
+.ad
+.fi
+See the Postfix \fBmain.cf\fR file for syntax details and for
+default values. Use the \fBpostfix reload\fR command after a
+configuration change.
+.IP \fBqueue_directory\fR
+Top-level directory of the Postfix queue. This is also the root
+directory of Postfix daemons that run chrooted.
.SH LICENSE
.na
.nf
.IP \fBhash_queue_names\fR
The names of queues that are organized into multiple levels of
subdirectories.
+.IP \fBqueue_directory\fR
+Top-level directory of the Postfix queue. This is also the root
+directory of Postfix daemons that run chrooted.
.SH SEE ALSO
.na
.nf
* Patches change the patchlevel and the release date. Snapshots change the
* release date only, unless they include the same bugfix as a patch release.
*/
-#define MAIL_RELEASE_DATE "20030418"
+#define MAIL_RELEASE_DATE "20030419"
#define VAR_MAIL_VERSION "mail_version"
#define DEF_MAIL_VERSION "2.0.9-" MAIL_RELEASE_DATE
REC_TYPE_EOF, "end-of-file", /* not Postfix-specific. */
REC_TYPE_ERROR, "error", /* not Postfix-specific. */
REC_TYPE_SIZE, "message_size",
- REC_TYPE_TIME, "time",
- REC_TYPE_FULL, "fullname",
+ REC_TYPE_TIME, "message_arrival_time",
+ REC_TYPE_FULL, "sender_fullname",
REC_TYPE_INSP, "content_inspector",
REC_TYPE_FILT, "content_filter",
REC_TYPE_FROM, "sender",
- REC_TYPE_DONE, "done",
+ REC_TYPE_DONE, "done_recipient",
REC_TYPE_RCPT, "recipient",
- REC_TYPE_ORCP, "original recipient",
+ REC_TYPE_ORCP, "original_recipient",
REC_TYPE_WARN, "warning_message_time",
- REC_TYPE_ATTR, "named attribute",
+ REC_TYPE_ATTR, "named_attribute",
REC_TYPE_MESG, "message_content",
- REC_TYPE_CONT, "unterminated",
- REC_TYPE_NORM, "normal_data",
+ REC_TYPE_CONT, "unterminated_text",
+ REC_TYPE_NORM, "regular_text",
REC_TYPE_XTRA, "extracted_info",
REC_TYPE_RRTO, "return_receipt",
REC_TYPE_ERTO, "errors_to",
REC_TYPE_PRIO, "priority",
REC_TYPE_VERP, "verp_delimiters",
REC_TYPE_END, "message_end",
+ REC_TYPE_RDR, "redirect_to",
+ REC_TYPE_FLGS, "flags",
0, 0,
};
postcat.o: ../../include/vstring_vstream.h
postcat.o: ../../include/record.h
postcat.o: ../../include/rec_type.h
+postcat.o: ../../include/mail_queue.h
+postcat.o: ../../include/mail_conf.h
+postcat.o: ../../include/mail_params.h
/* SUMMARY
/* show Postfix queue file contents
/* SYNOPSIS
-/* \fBpostcat\fR [\fB-v\fR] [\fIfiles\fR...]
+/* \fBpostcat\fR [\fB-vq\fR] [\fB-c \fIconfig_dir\fR] [\fIfiles\fR...]
/* DESCRIPTION
/* The \fBpostcat\fR command prints the contents of the named
-/* Postfix queue \fIfiles\fR in human-readable form. If no
+/* \fIfiles\fR in human-readable form. The files are expected
+/* to be in Postfix queue file format. If no
/* \fIfiles\fR are specified on the command line, the program
/* reads from standard input.
/*
/* Options:
+/* .IP "\fB-c \fIconfig_dir\fR"
+/* The \fBmain.cf\fR configuration file is in the named directory
+/* instead of the default configuration directory.
+/* .IP \fB-q\fR
+/* Search the Postfix queue for \fIfiles\fR. By default,
+/* file names are taken literally.
/* .IP \fB-v\fR
/* Enable verbose logging for debugging purposes. Multiple \fB-v\fR
/* options make the software increasingly verbose.
/* DIAGNOSTICS
/* Problems are reported to the standard error stream.
+/* ENVIRONMENT
+/* .ad
+/* .fi
+/* .IP \fBMAIL_CONFIG\fR
+/* Directory with Postfix configuration files.
+/* CONFIGURATION PARAMETERS
+/* .ad
+/* .fi
+/* See the Postfix \fBmain.cf\fR file for syntax details and for
+/* default values. Use the \fBpostfix reload\fR command after a
+/* configuration change.
+/* .IP \fBqueue_directory\fR
+/* Top-level directory of the Postfix queue. This is also the root
+/* directory of Postfix daemons that run chrooted.
/* LICENSE
/* .ad
/* .fi
#include <record.h>
#include <rec_type.h>
+#include <mail_queue.h>
+#include <mail_conf.h>
+#include <mail_params.h>
/* Application-specific. */
+#define PC_FLAG_QUEUE (1<<0) /* search queue */
+
#define STR vstring_str
/* postcat - visualize Postfix queue file contents */
if (rec_type == REC_TYPE_ERROR)
msg_fatal("record read error");
if (rec_type == REC_TYPE_EOF)
- return;
+ break;
if (first == 1) {
vstream_printf("*** ENVELOPE RECORDS %s ***\n", VSTREAM_PATH(fp));
first = 0;
if (prev_type == REC_TYPE_CONT && !TEXT_RECORD(rec_type))
VSTREAM_PUTCHAR('\n');
switch (rec_type) {
- case REC_TYPE_SIZE:
- vstream_printf("message_size: %s\n", STR(buffer));
- break;
case REC_TYPE_TIME:
- time = atol(STR(buffer));
- vstream_printf("arrival_time: %s", asctime(localtime(&time)));
- break;
case REC_TYPE_WARN:
time = atol(STR(buffer));
- vstream_printf("defer_warn_time: %s", asctime(localtime(&time)));
+ vstream_printf("%s: %s", rec_type_name(rec_type),
+ asctime(localtime(&time)));
break;
case REC_TYPE_CONT:
if (msg_verbose)
- vstream_printf("non-final line fragment: %s\n", STR(buffer));
+ vstream_printf("%s: %s\n", rec_type_name(rec_type),
+ STR(buffer));
else
vstream_printf("%s", STR(buffer));
break;
case REC_TYPE_NORM:
if (msg_verbose)
- vstream_printf("final line fragment: %s\n", STR(buffer));
+ vstream_printf("%s: %s\n", rec_type_name(rec_type),
+ STR(buffer));
else
vstream_printf("%s\n", STR(buffer));
break;
break;
}
prev_type = rec_type;
- vstream_fflush(VSTREAM_OUT);
}
+ vstream_fflush(VSTREAM_OUT);
}
/* usage - explain and terminate */
static NORETURN usage(char *myname)
{
- msg_fatal("usage: %s [-v] [file(s)...]", myname);
+ msg_fatal("usage: %s [-c config_dir] [-q (access queue)] [-v] [file(s)...]",
+ myname);
}
int main(int argc, char **argv)
int ch;
int fd;
struct stat st;
+ int flags = 0;
+ static char *queue_names[] = {
+ MAIL_QUEUE_MAILDROP,
+ MAIL_QUEUE_INCOMING,
+ MAIL_QUEUE_ACTIVE,
+ MAIL_QUEUE_DEFERRED,
+ MAIL_QUEUE_HOLD,
+ 0,
+ };
+ char **cpp;
+ int tries;
/*
* To minimize confusion, make sure that the standard file descriptors
/*
* Parse JCL.
*/
- while ((ch = GETOPT(argc, argv, "v")) > 0) {
+ while ((ch = GETOPT(argc, argv, "c:qv")) > 0) {
switch (ch) {
+ case 'c':
+ if (setenv(CONF_ENV_PATH, optarg, 1) < 0)
+ msg_fatal("out of memory");
+ break;
+ case 'q':
+ flags |= PC_FLAG_QUEUE;
+ break;
case 'v':
msg_verbose++;
break;
}
}
+ /*
+ * Further initialization...
+ */
+ mail_conf_read();
+
/*
* Initialize.
*/
postcat(VSTREAM_IN, buffer);
}
+ /*
+ * Copy the named queue files in the specified order.
+ */
+ else if (flags & PC_FLAG_QUEUE) {
+ if (chdir(var_queue_dir))
+ msg_fatal("chdir %s: %m", var_queue_dir);
+ while (optind < argc) {
+ for (fp = 0, tries = 0; fp == 0 && tries < 2; tries++)
+ for (cpp = queue_names; fp == 0 && *cpp != 0; cpp++)
+ fp = mail_queue_open(*cpp, argv[optind], O_RDONLY, 0);
+ if (fp == 0)
+ msg_fatal("open queue file %s: %m", argv[optind]);
+ optind++;
+ }
+ }
+
/*
* Copy the named files in the specified order.
*/
optind++;
}
}
+
+ /*
+ * Clean up.
+ */
vstring_free(buffer);
exit(0);
}
/*
* Copy a bunch of configuration parameters into the environment for easy
- * access by the maintenance shell script. XXX There should be a postconf
- * utility that makes config parameters easily accessible for shell
- * scripts.
+ * access by the maintenance shell script.
*/
mail_conf_read();
get_mail_conf_str_table(str_table);
/* .IP \fBhash_queue_names\fR
/* The names of queues that are organized into multiple levels of
/* subdirectories.
+/* .IP \fBqueue_directory\fR
+/* Top-level directory of the Postfix queue. This is also the root
+/* directory of Postfix daemons that run chrooted.
/* SEE ALSO
/* sendmail(1) sendmail-compatible user interface
/* postqueue(1) unprivileged queue operations
}
/*
- * Finish up MIME processing.
+ * Finish MIME processing. We need a final mime_state_update() call in
+ * order to flush text that is still buffered. That can happen when the
+ * last line did not end in newline.
*/
if (mime_state) {
mime_errs = mime_state_update(mime_state, REC_TYPE_EOF, "", 0);