On 5-Feb-2004 18:49 Mike Schiraldi wrote: | There's some discussion going on over at mutt-users regarding the behavior | of . in mutt regular expressions. Specifically, my pattern of: This is related to the problem that msg_search() just scans its (file) input line by line, so multiple lines are never presented to the regex. Attached is a patch which uses read_rfc822_line() for grabbing lines on header operations (M_HEADER) msg_search(). Since mutt_read_rfc822_line() is used, there are no newlines within the string to match anymore, so your original expression will work. -- -dale
--- PATCHES Dec 2002 17:44:54 -0000 3.6
+++ PATCHES Feb 2004 12:34:29 -0000
@@ -0,0 +1 @@
+patch-1.5.6.dw.pattern-header.1
--- parse.c Sep 2003 13:03:26 -0000 3.10
+++ parse.c Feb 2004 12:34:33 -0000
@@ -33,7 +33,7 @@
* lines. ``line'' must point to a dynamically allocated string; it is
* increased if more space is required to fit the whole line.
*/
-static char *read_rfc822_line (FILE *f, char *line, size_t *linelen)
+char * mutt_read_rfc822_line (FILE *f, char *line, size_t *linelen)
{
char *buf = line;
char ch;
@@ -428,7 +428,7 @@ BODY *mutt_read_mime_header (FILE *fp, i
p->type = digest ? TYPEMESSAGE : TYPETEXT;
p->disposition = DISPINLINE;
- while (*(line = read_rfc822_line (fp, line, &linelen)) != 0)
+ while (*(line = mutt_read_rfc822_line (fp, line, &linelen)) != 0)
{
/* Find the value of the current header */
if ((c = strchr (line, ':')))
@@ -1286,7 +1286,7 @@ ENVELOPE *mutt_read_rfc822_header (FILE
}
while ((loc = ftell (f)),
- *(line = read_rfc822_line (f, line, &linelen)) != 0)
+ *(line = mutt_read_rfc822_line (f, line, &linelen)) != 0)
{
matched = 0;
--- pattern.c Jul 2003 18:40:50 -0000 3.10
+++ pattern.c Feb 2004 12:34:33 -0000
@@ -129,7 +129,7 @@ int mutt_which_case (const char *s)
}
static int
-msg_search (CONTEXT *ctx, regex_t *rx, char *buf, size_t blen, int op, int
msgno)
+msg_search (CONTEXT *ctx, regex_t *rx, int op, int msgno)
{
char tempfile[_POSIX_PATH_MAX];
MESSAGE *msg = NULL;
@@ -139,6 +139,8 @@ msg_search (CONTEXT *ctx, regex_t *rx, c
long lng = 0;
int match = 0;
HEADER *h = ctx->hdrs[msgno];
+ char *mline = safe_malloc (LONG_STRING);
+ size_t mlen = LONG_STRING;
if ((msg = mx_open_message (ctx, msgno)) != NULL)
{
@@ -204,14 +206,23 @@ msg_search (CONTEXT *ctx, regex_t *rx, c
/* search the file "fp" */
while (lng > 0)
{
- if (fgets (buf, blen - 1, fp) == NULL)
- break; /* don't loop forever */
- if (regexec (rx, buf, 0, NULL, 0) == 0)
+ if (op == M_HEADER)
+ {
+ if (*(mline = mutt_read_rfc822_line (fp, mline, &mlen)) == 0)
+ break; /* don't loop forever */
+ }
+ else
+ {
+ if (fgets (mline, mlen - 1, fp) == NULL)
+ break; /* don't loop forever */
+ }
+
+ if (regexec (rx, mline, 0, NULL, 0) == 0)
{
match = 1;
break;
}
- lng -= mutt_strlen (buf);
+ lng -= mutt_strlen (mline);
}
mx_close_message (&msg);
@@ -223,6 +234,8 @@ msg_search (CONTEXT *ctx, regex_t *rx, c
}
}
+ FREE (&mline);
+
return match;
}
@@ -948,8 +961,6 @@ static int match_user (int alladdr, ADDR
int
mutt_pattern_exec (struct pattern_t *pat, pattern_exec_flag flags, CONTEXT
*ctx, HEADER *h)
{
- char buf[STRING];
-
switch (pat->op)
{
case M_AND:
@@ -988,7 +999,7 @@ mutt_pattern_exec (struct pattern_t *pat
case M_BODY:
case M_HEADER:
case M_WHOLE_MSG:
- return (pat->not ^ msg_search (ctx, pat->rx, buf, sizeof (buf), pat->op,
h->msgno));
+ return (pat->not ^ msg_search (ctx, pat->rx, pat->op, h->msgno));
case M_SENDER:
return (pat->not ^ match_adrlist (pat->rx, flags & M_MATCH_FULL_ADDRESS,
pat->alladdr, 1, h->env->sender));
--- protos.h Feb 2004 17:10:43 -0000 3.19
+++ protos.h Feb 2004 12:34:33 -0000
@@ -96,6 +96,7 @@ HASH *mutt_make_subj_hash (CONTEXT *);
LIST *mutt_make_references(ENVELOPE *e);
+char *mutt_read_rfc822_line (FILE *, char *, size_t *);
ENVELOPE *mutt_read_rfc822_header (FILE *, HEADER *, short, short);
HEADER *mutt_dup_header (HEADER *);
Attachment:
pgpWSk0HtYuY1.pgp
Description: PGP signature