Bluehost.com Web Hosting $6.95

PATCH: Long lines with postmap

This is a discussion on PATCH: Long lines with postmap within the mailing.postfix.users forums, part of the Mail Servers and Related category; --YZ5djTAD1cGYuMQK Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Monday, May ...


Go Back   Usenet Forums > Mail Servers and Related > mailing.postfix.users

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 05-10-2004
Magnus Bäck
 
Posts: n/a
Default PATCH: Long lines with postmap


--YZ5djTAD1cGYuMQK
Content-Type: text/plain; charset=iso-8859-1
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

On Monday, May 10, 2004 at 10:43 CEST,
Magnus B=E4ck <magnus@dsek.lth.se> wrote:

> In that case, I don't see a problem. I'll post a patch later today.


Well, for what it's worth, the patch is attached. I hope it can be
useful.

--=20
Magnus B=E4ck
magnus@dsek.lth.se

--YZ5djTAD1cGYuMQK
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="postmap-line-unfold.diff"

diff -cr /tmp/postfix-2.2-20040504/src/postmap/postmap.c ./src/postmap/postmap.c
*** /tmp/postfix-2.2-20040504/src/postmap/postmap.c Wed Apr 14 16:25:42 2004
--- ./src/postmap/postmap.c Mon May 10 23:29:09 2004
***************
*** 64,69 ****
--- 64,78 ----
/* Incremental mode. Read entries from standard input and do not
/* truncate an existing database. By default, \fBpostmap\fR creates
/* a new database from the entries in \fBfile_name\fR.
+ /* .IP \fB-l\fR
+ /* Unfold long lines that have been folded in accordance to RFC 2822.
+ /* When querying a table with "\fB-q -\fR" and feeding \fBpostmap\fR keys
+ /* via the standard input stream, an input line starting with a space
+ /* or a tab will be treated as a continuation of the previous line.
+ /* This is useful to make lookups of message headers, and mimics how
+ /* Postfix matches message headers against maps listed in the
+ /* header_checks, mime_header_checks, and nested_header_checks parameters.
+ /* Empty lines are ignored.
/* .IP \fB-N\fR
/* Include the terminating null character that terminates lookup keys
/* and values. By default, Postfix does whatever is the default for
***************
*** 222,234 ****
--- 231,247 ----
#include <mail_params.h>
#include <mkmap.h>
#include <mail_task.h>
+ #include <lex_822.h>

/* Application-specific. */

#define STR vstring_str
+ #define LEN(x) VSTRING_LEN(x)
+ #define END(x) vstring_end(x)

#define POSTMAP_FLAG_AS_OWNER (1<<0) /* open dest as owner of source */
#define POSTMAP_FLAG_SAVE_PERM (1<<1) /* copy access permission from source */
+ #define POSTMAP_FLAG_LONGLINES (1<<2) /* unfold long lines */

/* postmap - create or update mapping database */

***************
*** 338,346 ****
--- 351,409 ----
vstream_fclose(source_fp);
}

+ /* readhline - read a logical header line. Based on readlline. */
+
+ static int readhline(VSTRING *buf, VSTREAM *fp)
+ {
+ int ch;
+ int next;
+ int start;
+
+ VSTRING_RESET(buf);
+
+ /*
+ * Terminate at EOF or at the beginning of the next logical line.
+ */
+ for (;;) {
+ /* Read one line, possibly not newline terminated. */
+ start = LEN(buf);
+ while ((ch = VSTREAM_GETC(fp)) != VSTREAM_EOF && ch != '\n')
+ VSTRING_ADDCH(buf, ch);
+ /* Terminate at EOF or at the beginning of the next logical line. */
+ if (ch == VSTREAM_EOF)
+ break;
+ if (LEN(buf) > 0) {
+ if ((next = VSTREAM_GETC(fp)) != VSTREAM_EOF)
+ vstream_ungetc(fp, next);
+ if (!IS_SPACE_TAB(next) && next != '\n')
+ break;
+ }
+ }
+ VSTRING_TERMINATE(buf);
+
+ /*
+ * Invalid input: continuing text without preceding text. Allowing this
+ * would complicate "postconf -e", which implements its own multi-line
+ * parsing routine. Do not abort, just warn, so that critical programs
+ * like postmap do not leave behind a truncated table.
+ */
+ if (LEN(buf) > 0 && ISSPACE(*STR(buf))) {
+ msg_warn("%s: logical line must not start with whitespace: \"%.30s%s\"",
+ VSTREAM_PATH(fp), STR(buf),
+ LEN(buf) > 30 ? "..." : "");
+ return (readhline(buf, fp));
+ }
+
+ /*
+ * Done.
+ */
+ return ch;
+ }
+
/* postmap_queries - apply multiple requests from stdin */

static int postmap_queries(VSTREAM *in, char **maps, const int map_count,
+ const int postmap_flags,
const int dict_flags)
{
int found = 0;
***************
*** 367,373 ****
* Perform all queries. Open maps on the fly, to avoid opening unecessary
* maps.
*/
! while (vstring_get_nonl(keybuf, in) != VSTREAM_EOF) {
if (dict_flags & DICT_FLAG_FOLD_KEY)
lowercase(STR(keybuf));
for (n = 0; n < map_count; n++) {
--- 430,438 ----
* Perform all queries. Open maps on the fly, to avoid opening unecessary
* maps.
*/
! while ((postmap_flags & POSTMAP_FLAG_LONGLINES ?
! readhline(keybuf, in) != VSTREAM_EOF :
! vstring_get_nonl(keybuf, in) != VSTREAM_EOF)) {
if (dict_flags & DICT_FLAG_FOLD_KEY)
lowercase(STR(keybuf));
for (n = 0; n < map_count; n++) {
***************
*** 540,546 ****
/*
* Parse JCL.
*/
! while ((ch = GETOPT(argc, argv, "Nc:d:finopq:rvw")) > 0) {
switch (ch) {
default:
usage(argv[0]);
--- 605,611 ----
/*
* Parse JCL.
*/
! while ((ch = GETOPT(argc, argv, "Nc:d:filnopq:rvw")) > 0) {
switch (ch) {
default:
usage(argv[0]);
***************
*** 564,569 ****
--- 629,637 ----
case 'i':
open_flags &= ~O_TRUNC;
break;
+ case 'l':
+ postmap_flags |= POSTMAP_FLAG_LONGLINES;
+ break;
case 'n':
dict_flags |= DICT_FLAG_TRY0NULL;
dict_flags &= ~DICT_FLAG_TRY1NULL;
***************
*** 619,625 ****
usage(argv[0]);
if (strcmp(query, "-") == 0)
exit(postmap_queries(VSTREAM_IN, argv + optind, argc - optind,
! dict_flags) == 0);
if (dict_flags & DICT_FLAG_FOLD_KEY)
lowercase(query);
while (optind < argc) {
--- 687,693 ----
usage(argv[0]);
if (strcmp(query, "-") == 0)
exit(postmap_queries(VSTREAM_IN, argv + optind, argc - optind,
! postmap_flags, dict_flags) == 0);
if (dict_flags & DICT_FLAG_FOLD_KEY)
lowercase(query);
while (optind < argc) {

--YZ5djTAD1cGYuMQK--
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 09:10 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0