Code indentation and other minor cleanups.

This commit is contained in:
Daniel Spiljar 2023-01-30 21:51:37 +01:00
parent 1d75932569
commit 7c94d17bec
15 changed files with 342 additions and 380 deletions

View File

@ -28,7 +28,6 @@
void void
print_wrap (char *str, int len, int *n) print_wrap (char *str, int len, int *n)
/* {{{ */
{ {
*n += len; *n += len;
fprintf (stdout, str); fprintf (stdout, str);
@ -39,11 +38,9 @@ print_wrap (char *str, int len, int *n)
} }
else fprintf (stdout, " "); else fprintf (stdout, " ");
} }
/* }}} */
void void
version (void) version (void)
/* {{{ */
{ {
int n = 0; int n = 0;
@ -93,13 +90,12 @@ version (void)
print_wrap ("HAVE_SYS_NDIR_H", 15, &n); print_wrap ("HAVE_SYS_NDIR_H", 15, &n);
#endif #endif
fprintf (stdout, "\n"); fprintf (stdout, "\n");
exit(0); exit(0);
} }
/* }}} */
void void
help (void) help (void)
/* {{{ */
{ {
fprintf(stdout, "%s %s - search MAILBOX for messages matching PATTERN\n\n", fprintf(stdout, "%s %s - search MAILBOX for messages matching PATTERN\n\n",
APPNAME, VERSION); APPNAME, VERSION);
@ -157,15 +153,12 @@ help (void)
exit(0); exit(0);
} }
/* }}} */
void void
usage (void) usage (void)
/* {{{ */
{ {
printf ("Usage: %s [OPTION] PATTERN MAILBOX ...\n\n" printf ("Usage: %s [OPTION] PATTERN MAILBOX ...\n\n"
"Try `%s --help' for more information.\n", APPNAME, APPNAME); "Try `%s --help' for more information.\n", APPNAME, APPNAME);
exit (2); exit (2);
} }
/* }}} */

View File

@ -1,6 +1,6 @@
/* -*- C -*- /*
mboxgrep - scan mailbox for messages matching a regular expression mboxgrep - scan mailbox for messages matching a regular expression
Copyright (C) 2000, 2001, 2002, 2003 Daniel Spiljar Copyright (C) 2000 - 2003, 2023 Daniel Spiljar
Mboxgrep is free software; you can redistribute it and/or modify it Mboxgrep is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by under the terms of the GNU General Public License as published by
@ -15,8 +15,7 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with mboxgrep; if not, write to the Free Software Foundation, along with mboxgrep; if not, write to the Free Software Foundation,
Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
$Id: info.h,v 1.5 2003-04-13 19:15:58 dspiljar Exp $ */
#ifndef INFO_H #ifndef INFO_H
#define INFO_H #define INFO_H

View File

@ -1,6 +1,6 @@
/* -*- C -*- /*
mboxgrep - scan mailbox for messages matching a regular expression mboxgrep - scan mailbox for messages matching a regular expression
Copyright (C) 2000, 2001, 2002, 2003, 2006 Daniel Spiljar Copyright (C) 2000 - 2003, 2006, 2023 Daniel Spiljar
Mboxgrep is free software; you can redistribute it and/or modify it Mboxgrep is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by under the terms of the GNU General Public License as published by
@ -15,8 +15,7 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with mboxgrep; if not, write to the Free Software Foundation, along with mboxgrep; if not, write to the Free Software Foundation,
Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
$Id: maildir.c,v 1.25 2006-10-19 01:53:43 dspiljar Exp $ */
#include <config.h> #include <config.h>
@ -84,10 +83,10 @@ maildir_open (const char *path)
if (mp->new == NULL) if (mp->new == NULL)
{ {
if (config.merr) if (config.merr)
{ {
fprintf (stderr, "%s: %s: ", APPNAME, dirname); fprintf (stderr, "%s: %s: ", APPNAME, dirname);
perror (NULL); perror (NULL);
} }
free (dirname); free (dirname);
errno = 0; errno = 0;
return NULL; return NULL;
@ -98,14 +97,14 @@ maildir_open (const char *path)
if (mp->cur == NULL) if (mp->cur == NULL)
{ {
if (config.merr) if (config.merr)
{ {
fprintf (stderr, "%s: %s: ", APPNAME, dirname); fprintf (stderr, "%s: %s: ", APPNAME, dirname);
perror (NULL); perror (NULL);
} }
free (dirname); free (dirname);
errno = 0; errno = 0;
return NULL; return NULL;
} }
free (dirname); free (dirname);
return mp; return mp;
@ -128,37 +127,37 @@ maildir_read_message (maildir_t *mdp)
for(;;) for(;;)
{ {
if (mdp->new != NULL) if (mdp->new != NULL)
{ {
d_content = readdir (mdp->new); d_content = readdir (mdp->new);
if (d_content == NULL) if (d_content == NULL)
{ {
closedir (mdp->new); closedir (mdp->new);
mdp->new = NULL; mdp->new = NULL;
} }
} }
if (mdp->new == NULL && mdp->cur != NULL) if (mdp->new == NULL && mdp->cur != NULL)
{ {
d_content = readdir (mdp->cur); d_content = readdir (mdp->cur);
if (d_content == NULL) if (d_content == NULL)
{ {
closedir (mdp->cur); closedir (mdp->cur);
mdp->cur = NULL; mdp->cur = NULL;
} }
} }
if (mdp->new == NULL && mdp->cur == NULL) if (mdp->new == NULL && mdp->cur == NULL)
{ {
free (message->headers); free (message->headers);
free (message->body); free (message->body);
free (message); free (message);
return NULL; return NULL;
} }
if (d_content->d_name[0] == '.') if (d_content->d_name[0] == '.')
continue; continue;
filename = filename =
(char *) xmalloc ((sizeof (char)*((strlen (d_content->d_name)) (char *) xmalloc ((sizeof (char)*((strlen (d_content->d_name))
+ (strlen (config.boxname)) + 6))); + (strlen (config.boxname)) + 6)));
/* /*
filename = filename =
@ -166,9 +165,10 @@ maildir_read_message (maildir_t *mdp)
+ (strlen(config.boxname)) + 2))); + (strlen(config.boxname)) + 2)));
*/ */
if (mdp->new != NULL) if (mdp->new != NULL)
sprintf (filename, "%s/new/%s", config.boxname, d_content->d_name); sprintf (filename, "%s/new/%s", config.boxname, d_content->d_name);
else else
sprintf (filename, "%s/cur/%s", config.boxname, d_content->d_name); sprintf (filename, "%s/cur/%s", config.boxname, d_content->d_name);
message->filename = (char *) xstrdup (filename); message->filename = (char *) xstrdup (filename);
free (filename); free (filename);
@ -176,55 +176,58 @@ maildir_read_message (maildir_t *mdp)
fp = m_fopen(message->filename, "r"); fp = m_fopen(message->filename, "r");
if (fp == NULL) if (fp == NULL)
continue; continue;
while (fgets (buffer, BUFSIZ, fp) != NULL) while (fgets (buffer, BUFSIZ, fp) != NULL)
{ {
s = strlen (buffer); s = strlen (buffer);
if (0 == strncmp ("\n", buffer, 1) && isheaders == 1) if (0 == strncmp ("\n", buffer, 1) && isheaders == 1)
{ {
isheaders = 0; isheaders = 0;
continue; continue;
} /* if */ } /* if */
if (isheaders) if (isheaders)
{ {
if (0 == strncasecmp ("From: ", buffer, 6)) if (0 == strncasecmp ("From: ", buffer, 6))
have_from = 1; have_from = 1;
if (0 == strncasecmp ("Sender: ", buffer, 8)) if (0 == strncasecmp ("Sender: ", buffer, 8))
have_sender = 1; have_sender = 1;
if (0 == strncasecmp ("Date: ", buffer, 6)) if (0 == strncasecmp ("Date: ", buffer, 6))
have_date = 1; have_date = 1;
if (0 == strncasecmp ("To: ", buffer, 4)) if (0 == strncasecmp ("To: ", buffer, 4))
have_to = 1; have_to = 1;
if (0 == strncasecmp ("Message-ID: ", buffer, 12)) if (0 == strncasecmp ("Message-ID: ", buffer, 12))
have_message_id = 1; have_message_id = 1;
if (0 == strncasecmp ("Return-Path: ", buffer, 13)) if (0 == strncasecmp ("Return-Path: ", buffer, 13))
message->from = parse_return_path(buffer); message->from = parse_return_path(buffer);
message->headers =
(char *) xrealloc (message->headers,
((1 + s + message->hbytes) * sizeof (char)));
strcpy (message->headers + message->hbytes, buffer);
message->hbytes += s;
} /* if */
else
{
message->body =
(char *) xrealloc (message->body,
((1 + s + message->bbytes) * sizeof (char)));
strcpy (message->body + message->bbytes, buffer);
message->bbytes += s;
} /* else */
} /* while */
message->headers =
(char *) xrealloc (message->headers,
((1 + s + message->hbytes) * sizeof (char)));
strcpy (message->headers + message->hbytes, buffer);
message->hbytes += s;
} /* if */
else
{
message->body =
(char *) xrealloc (message->body,
((1 + s + message->bbytes) * sizeof (char)));
strcpy (message->body + message->bbytes, buffer);
message->bbytes += s;
} /* else */
} /* while */
/* if (!have_from || !have_to || !have_message_id) */ /* if (!have_from || !have_to || !have_message_id) */
if ((!have_from && !have_sender)|| !have_date) if ((!have_from && !have_sender)|| !have_date)
{ {
if (config.merr) if (config.merr)
fprintf(stderr, "%s: %s: Not a RFC 2822 message\n", fprintf(stderr, "%s: %s: Not a RFC 2822 message\n",
APPNAME, message->filename); APPNAME, message->filename);
fclose(fp); fclose(fp);
continue; continue;
} }
fclose(fp); fclose(fp);
return message; return message;
@ -297,19 +300,19 @@ maildir_create (const char *path)
sprintf(s, "%s", path); sprintf(s, "%s", path);
i = mkdir (s, S_IRWXU); i = mkdir (s, S_IRWXU);
if (-1 == i) if (-1 == i)
break; break;
sprintf(s, "%s/new", path); sprintf(s, "%s/new", path);
i = mkdir (s, S_IRWXU); i = mkdir (s, S_IRWXU);
if (-1 == i) if (-1 == i)
break; break;
sprintf(s, "%s/cur", path); sprintf(s, "%s/cur", path);
i = mkdir (s, S_IRWXU); i = mkdir (s, S_IRWXU);
if (-1 == i) if (-1 == i)
break; break;
sprintf(s, "%s/tmp", path); sprintf(s, "%s/tmp", path);
i = mkdir (s, S_IRWXU); i = mkdir (s, S_IRWXU);
if (-1 == i) if (-1 == i)
break; break;
break; break;
} }
@ -317,9 +320,9 @@ maildir_create (const char *path)
if (errno != 0) if (errno != 0)
{ {
if (config.merr) if (config.merr)
{ {
fprintf(stderr, "%s:%s: ", APPNAME, s); fprintf(stderr, "%s:%s: ", APPNAME, s);
perror (NULL); perror (NULL);
} }
} }
} }

View File

@ -1,6 +1,6 @@
/* -*- C -*- /*
mboxgrep - scan mailbox for messages matching a regular expression mboxgrep - scan mailbox for messages matching a regular expression
Copyright (C) 2000, 2001, 2002, 2003 Daniel Spiljar Copyright (C) 2000 - 2003, 2023 Daniel Spiljar
Mboxgrep is free software; you can redistribute it and/or modify it Mboxgrep is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by under the terms of the GNU General Public License as published by
@ -15,8 +15,7 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with mboxgrep; if not, write to the Free Software Foundation, along with mboxgrep; if not, write to the Free Software Foundation,
Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
$Id: maildir.h,v 1.6 2003-03-30 23:07:10 dspiljar Exp $ */
#ifndef MAILDIR_H #ifndef MAILDIR_H
#define MAILDIR_H #define MAILDIR_H

View File

@ -15,7 +15,6 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with mboxgrep; if not, write to the Free Software Foundation, along with mboxgrep; if not, write to the Free Software Foundation,
Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/ */
#include <config.h> #include <config.h>

View File

@ -1,4 +1,4 @@
/* -*- C -*- /*
mboxgrep - scan mailbox for messages matching a regular expression mboxgrep - scan mailbox for messages matching a regular expression
Copyright (C) 2000, 2001, 2002, 2003, 2004, 2006 Daniel Spiljar Copyright (C) 2000, 2001, 2002, 2003, 2004, 2006 Daniel Spiljar
@ -15,8 +15,7 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with mboxgrep; if not, write to the Free Software Foundation, along with mboxgrep; if not, write to the Free Software Foundation,
Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
$Id: mbox.c,v 1.34 2006-10-22 23:34:49 dspiljar Exp $ */
#include <config.h> #include <config.h>
@ -52,7 +51,6 @@
mbox_t * mbox_t *
mbox_open (const char *path, const char *mode) mbox_open (const char *path, const char *mode)
/* {{{ */
{ {
mbox_t *mp; mbox_t *mp;
static int fd; static int fd;
@ -69,155 +67,153 @@ mbox_open (const char *path, const char *mode)
else else
{ {
if (mode[0] == 'r') if (mode[0] == 'r')
fd = m_open (path, O_RDONLY, 0); fd = m_open (path, O_RDONLY, 0);
else if (mode[0] == 'w') else if (mode[0] == 'w')
fd = m_open (path, (O_WRONLY | O_CREAT | O_APPEND), fd = m_open (path, (O_WRONLY | O_CREAT | O_APPEND),
(S_IWUSR | S_IRUSR)); (S_IWUSR | S_IRUSR));
else else
{ {
fprintf (stderr, "%s: mbox.c: Unknown mode %c. You shouldn't " fprintf (stderr, "%s: mbox.c: Unknown mode %c. You shouldn't "
"get this error...", APPNAME, mode[0]); "get this error...", APPNAME, mode[0]);
exit (2); exit (2);
} }
if (fd == -1) if (fd == -1)
{ {
if (config.merr) if (config.merr)
{ {
fprintf (stderr, "%s: %s: ", APPNAME, path); fprintf (stderr, "%s: %s: ", APPNAME, path);
perror (NULL); perror (NULL);
} }
errno = 0; errno = 0;
return NULL; return NULL;
} }
if (config.lock) if (config.lock)
{ {
#ifdef HAVE_FLOCK #ifdef HAVE_FLOCK
int op; int op;
if (mode[0] == 'r') if (mode[0] == 'r')
op = LOCK_SH; op = LOCK_SH;
else else
op = LOCK_EX; op = LOCK_EX;
if (-1 == flock (fd, op)) if (-1 == flock (fd, op))
#else #else
memset (&lck, 0, sizeof (struct flock)); memset (&lck, 0, sizeof (struct flock));
lck.l_whence = SEEK_SET; lck.l_whence = SEEK_SET;
if (mode[0] == 'r') if (mode[0] == 'r')
lck.l_type = F_RDLCK; lck.l_type = F_RDLCK;
else else
lck.l_type = F_WRLCK; lck.l_type = F_WRLCK;
if (-1 == fcntl (fd, F_SETLK, &lck)) if (-1 == fcntl (fd, F_SETLK, &lck))
#endif /* HAVE_FLOCK */ #endif /* HAVE_FLOCK */
{ {
if (config.merr) if (config.merr)
{ {
fprintf (stderr, "%s: %s: ", APPNAME, path); fprintf (stderr, "%s: %s: ", APPNAME, path);
perror (NULL); perror (NULL);
} }
errno = 0; errno = 0;
close (fd); close (fd);
return NULL; return NULL;
} }
} }
if (mode[0] == 'r') if (mode[0] == 'r')
{ {
if (config.format == MBOX) if (config.format == MBOX)
mp->fp = (FILE *) m_fdopen (fd, "r"); mp->fp = (FILE *) m_fdopen (fd, "r");
#ifdef HAVE_LIBZ #ifdef HAVE_LIBZ
else if (config.format == ZMBOX) else if (config.format == ZMBOX)
mp->fp = (gzFile *) m_gzdopen (fd, "rb"); mp->fp = (gzFile *) m_gzdopen (fd, "rb");
#endif /* HAVE_LIBZ */ #endif /* HAVE_LIBZ */
#ifdef HAVE_LIBBZ2 #ifdef HAVE_LIBBZ2
else if (config.format == BZ2MBOX) else if (config.format == BZ2MBOX)
mp->fp = (BZFILE *) BZ2_bzdopen (fd, "rb"); mp->fp = (BZFILE *) BZ2_bzdopen (fd, "rb");
#endif /* HAVE_LIBBZ2 */ #endif /* HAVE_LIBBZ2 */
} }
else if (mode[0] == 'w') else if (mode[0] == 'w')
{ {
if (config.format == MBOX) if (config.format == MBOX)
mp->fp = (FILE *) m_fdopen (fd, "w"); mp->fp = (FILE *) m_fdopen (fd, "w");
#ifdef HAVE_LIBZ #ifdef HAVE_LIBZ
else if (config.format == ZMBOX) else if (config.format == ZMBOX)
mp->fp = (gzFile *) m_gzdopen (fd, "wb"); mp->fp = (gzFile *) m_gzdopen (fd, "wb");
#endif /* HAVE_LIBZ */ #endif /* HAVE_LIBZ */
#ifdef HAVE_LIBBZ2 #ifdef HAVE_LIBBZ2
else if (config.format == BZ2MBOX) else if (config.format == BZ2MBOX)
mp->fp = (BZFILE *) BZ2_bzdopen (fd, "wb"); mp->fp = (BZFILE *) BZ2_bzdopen (fd, "wb");
#endif /* HAVE_LIBBZ2 */ #endif /* HAVE_LIBBZ2 */
} }
if (mp->fp == NULL) if (mp->fp == NULL)
{ {
if (config.merr) if (config.merr)
{ {
fprintf (stderr, "%s: %s: ", APPNAME, path); fprintf (stderr, "%s: %s: ", APPNAME, path);
perror (NULL); perror (NULL);
} }
errno = 0; errno = 0;
close (fd); close (fd);
return NULL; return NULL;
} }
} }
if (mode[0] == 'r') if (mode[0] == 'r')
{ {
if (config.format == MBOX) if (config.format == MBOX)
fgets (buffer, BUFSIZ, mp->fp); fgets (buffer, BUFSIZ, mp->fp);
#ifdef HAVE_LIBZ #ifdef HAVE_LIBZ
else if (config.format == ZMBOX) else if (config.format == ZMBOX)
gzgets (mp->fp, buffer, BUFSIZ); gzgets (mp->fp, buffer, BUFSIZ);
#endif /* HAVE_LIBZ */ #endif /* HAVE_LIBZ */
#ifdef HAVE_LIBBZ2 #ifdef HAVE_LIBBZ2
else if (config.format == BZ2MBOX) else if (config.format == BZ2MBOX)
{ {
char c[1] = "\0"; char c[1] = "\0";
int n = 0; int n = 0;
while (c[0] != '\n' && n < BUFSIZ) while (c[0] != '\n' && n < BUFSIZ)
{ {
BZ2_bzread (mp->fp, c, 1); BZ2_bzread (mp->fp, c, 1);
buffer[n] = c[0]; buffer[n] = c[0];
n++; n++;
} }
buffer[n] = '\0'; buffer[n] = '\0';
} }
#endif /* HAVE_LIBBZ2 */ #endif /* HAVE_LIBBZ2 */
if (0 != strncmp ("From ", buffer, 5)) if (0 != strncmp ("From ", buffer, 5))
{ {
if (config.merr) if (config.merr)
{ {
if (0 == strcmp ("-", path)) if (0 == strcmp ("-", path))
fprintf (stderr, "%s: (standard input): Not a mbox folder\n", fprintf (stderr, "%s: (standard input): Not a mbox folder\n",
APPNAME); APPNAME);
else else
fprintf (stderr, "%s: %s: Not a mbox folder\n", APPNAME, path); fprintf (stderr, "%s: %s: Not a mbox folder\n", APPNAME, path);
} }
if (config.format == MBOX) if (config.format == MBOX)
fclose (mp->fp); fclose (mp->fp);
#ifdef HAVE_LIBZ #ifdef HAVE_LIBZ
else if (config.format == ZMBOX) else if (config.format == ZMBOX)
gzclose (mp->fp); gzclose (mp->fp);
#endif /* HAVE_LIBZ */ #endif /* HAVE_LIBZ */
#ifdef HAVE_LIBBZ2 #ifdef HAVE_LIBBZ2
else if (config.format == BZ2MBOX) else if (config.format == BZ2MBOX)
BZ2_bzclose (mp->fp); BZ2_bzclose (mp->fp);
#endif /* HAVE_LIBBZ2 */ #endif /* HAVE_LIBBZ2 */
return NULL; return NULL;
} }
strcpy (mp->postmark_cache, buffer); strcpy (mp->postmark_cache, buffer);
} }
return mp; return mp;
} }
/* }}} */
void void
mbox_close (mbox_t * mp) mbox_close (mbox_t * mp)
/* {{{ */
{ {
if (config.format == MBOX) if (config.format == MBOX)
fclose (mp->fp); fclose (mp->fp);
@ -233,12 +229,9 @@ mbox_close (mbox_t * mp)
free (mp->postmark_cache); free (mp->postmark_cache);
free (mp); free (mp);
} }
/* }}} */
message_t * message_t *
mbox_read_message (mbox_t * mp) mbox_read_message (mbox_t * mp)
/* {{{ */
{ {
int isheaders = 1, s; int isheaders = 1, s;
char buffer[BUFSIZ]; char buffer[BUFSIZ];
@ -256,93 +249,89 @@ mbox_read_message (mbox_t * mp)
for (;;) for (;;)
{ {
if (config.format == MBOX) if (config.format == MBOX)
{ {
if (fgets (buffer, BUFSIZ, mp->fp) == NULL) if (fgets (buffer, BUFSIZ, mp->fp) == NULL)
{ {
if (isheaders) if (isheaders)
return NULL; return NULL;
else else
return message; return message;
} }
} }
#ifdef HAVE_LIBZ #ifdef HAVE_LIBZ
else if (config.format == ZMBOX) else if (config.format == ZMBOX)
{ {
if (gzgets (mp->fp, buffer, BUFSIZ) == NULL) if (gzgets (mp->fp, buffer, BUFSIZ) == NULL)
{ {
if (isheaders) if (isheaders)
return NULL; return NULL;
else else
return message; return message;
} }
} }
#endif /* HAVE_LIBZ */ #endif /* HAVE_LIBZ */
#ifdef HAVE_LIBBZ2 #ifdef HAVE_LIBBZ2
else if (config.format == BZ2MBOX) else if (config.format == BZ2MBOX)
{ {
char c[1] = "\0"; char c[1] = "\0";
int n = 0; int n = 0;
while (c[0] != '\n' && n < BUFSIZ) while (c[0] != '\n' && n < BUFSIZ)
{ {
BZ2_bzread (mp->fp, c, 1); BZ2_bzread (mp->fp, c, 1);
buffer[n] = c[0]; buffer[n] = c[0];
n++; n++;
} }
buffer[n] = '\0'; buffer[n] = '\0';
if (buffer[0] == '\0') if (buffer[0] == '\0')
{ {
if (isheaders) if (isheaders)
return NULL; return NULL;
else else
return message; return message;
} }
} }
#endif /* HAVE_LIBBZ2 */ #endif /* HAVE_LIBBZ2 */
s = strlen (buffer); s = strlen (buffer);
if (buffer[0] == '\n' && isheaders == 1) if (buffer[0] == '\n' && isheaders == 1)
{ {
isheaders = 0; isheaders = 0;
continue; continue;
} }
if (isheaders) if (isheaders)
{ {
message->headers = message->headers =
(char *) realloc (message->headers, (char *) realloc (message->headers,
((1 + s + message->hbytes) * sizeof (char))); ((1 + s + message->hbytes) * sizeof (char)));
strcpy (message->headers + message->hbytes, buffer); strcpy (message->headers + message->hbytes, buffer);
message->hbytes += s; message->hbytes += s;
} /* if */ }
else else
{ {
if (0 == strncmp (buffer, "From ", 5)) if (0 == strncmp (buffer, "From ", 5))
{ {
strcpy (mp->postmark_cache, buffer); strcpy (mp->postmark_cache, buffer);
return message; return message;
} }
message->body = message->body =
(char *) realloc (message->body, (char *) realloc (message->body,
((1 + s + message->bbytes) * sizeof (char))); ((1 + s + message->bbytes) * sizeof (char)));
strcpy (message->body + message->bbytes, buffer); strcpy (message->body + message->bbytes, buffer);
message->bbytes += s; message->bbytes += s;
}
} }
} /* for */
return NULL; return NULL;
} }
/* }}} */
void void
tmpmbox_create (const char *path) tmpmbox_create (const char *path)
/* {{{ */
{ {
int foo; int foo;
@ -351,11 +340,9 @@ tmpmbox_create (const char *path)
tmpfile_mod_own (foo, path); tmpfile_mod_own (foo, path);
} }
/* }}} */
void void
tmpfile_name (const char *path) tmpfile_name (const char *path)
/* {{{ */
{ {
char *fname, *tmpdir; char *fname, *tmpdir;
@ -363,7 +350,7 @@ tmpfile_name (const char *path)
{ {
tmpdir = getenv ("TMPDIR"); tmpdir = getenv ("TMPDIR");
if (tmpdir == NULL) if (tmpdir == NULL)
tmpdir = xstrdup ("/tmp"); tmpdir = xstrdup ("/tmp");
fname = xstrdup ("/mboxgrepXXXXXX"); fname = xstrdup ("/mboxgrepXXXXXX");
} }
else else
@ -377,13 +364,10 @@ tmpfile_name (const char *path)
* sizeof (char)); * sizeof (char));
sprintf (config.tmpfilename, "%s%s", tmpdir, fname); sprintf (config.tmpfilename, "%s%s", tmpdir, fname);
} }
/* }}} */
void void
mbox_write_message (message_t *msg, mbox_t *mbox) mbox_write_message (message_t *msg, mbox_t *mbox)
/* {{{ */
{ {
if (config.format == MBOX) if (config.format == MBOX)
fprintf (mbox->fp, "%s\n%s", msg->headers, msg->body); fprintf (mbox->fp, "%s\n%s", msg->headers, msg->body);
@ -404,11 +388,9 @@ mbox_write_message (message_t *msg, mbox_t *mbox)
} }
#endif /* HAVE_LIBBZ2 */ #endif /* HAVE_LIBBZ2 */
} }
/* }}} */
void void
tmpfile_mod_own (const int fd, const char *path) tmpfile_mod_own (const int fd, const char *path)
/* {{{ */
{ {
/* If we're root, copy {owner, group, perms} of mailbox to the tmpfile /* If we're root, copy {owner, group, perms} of mailbox to the tmpfile
* so rename() will thus retain the original's ownership & permissions. * so rename() will thus retain the original's ownership & permissions.
@ -418,20 +400,18 @@ tmpfile_mod_own (const int fd, const char *path)
struct stat s; struct stat s;
if (stat (path, &s) != -1) if (stat (path, &s) != -1)
{ {
if (fchown (fd, s.st_uid, s.st_gid) == -1) if (fchown (fd, s.st_uid, s.st_gid) == -1)
if (config.merr) perror (config.tmpfilename); if (config.merr) perror (config.tmpfilename);
if (fchmod (fd, s.st_mode) == -1) if (fchmod (fd, s.st_mode) == -1)
if (config.merr) perror (config.tmpfilename); if (config.merr) perror (config.tmpfilename);
} }
else if (config.merr) perror (path); else if (config.merr) perror (path);
} }
} }
/* }}} */
int int
tmpfile_create (void) tmpfile_create (void)
/* {{{ */
{ {
int fd; int fd;
@ -439,12 +419,11 @@ tmpfile_create (void)
if (-1 == fd) if (-1 == fd)
{ {
if (config.merr) if (config.merr)
{ {
fprintf (stderr, "%s: %s: ", APPNAME, config.tmpfilename); fprintf (stderr, "%s: %s: ", APPNAME, config.tmpfilename);
perror (NULL); perror (NULL);
} }
exit (2); exit (2);
} }
return fd; return fd;
} }
/* }}} */

View File

@ -1,6 +1,6 @@
/* -*- C -*- /*
mboxgrep - scan mailbox for messages matching a regular expression mboxgrep - scan mailbox for messages matching a regular expression
Copyright (C) 2000, 2001, 2002, 2003, 2004 Daniel Spiljar Copyright (C) 2000 - 2004, 2023 Daniel Spiljar
Mboxgrep is free software; you can redistribute it and/or modify it Mboxgrep is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by under the terms of the GNU General Public License as published by
@ -15,8 +15,7 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with mboxgrep; if not, write to the Free Software Foundation, along with mboxgrep; if not, write to the Free Software Foundation,
Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
$Id: mbox.h,v 1.13 2006-10-22 23:34:49 dspiljar Exp $ */
#ifndef MBOX_H #ifndef MBOX_H
#define MBOX_H 1 #define MBOX_H 1

View File

@ -1,6 +1,6 @@
/* -*- C -*- /*
mboxgrep - scan mailbox for messages matching a regular expression mboxgrep - scan mailbox for messages matching a regular expression
Copyright (C) 2020 Daniel Spiljar Copyright (C) 2020, 2023 Daniel Spiljar
Mboxgrep is free software; you can redistribute it and/or modify it Mboxgrep is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by under the terms of the GNU General Public License as published by
@ -15,8 +15,7 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with mboxgrep; if not, write to the Free Software Foundation, along with mboxgrep; if not, write to the Free Software Foundation,
Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
$Id$ */
#ifndef MESSAGE_H #ifndef MESSAGE_H
#define MESSAGE_H 1 #define MESSAGE_H 1

View File

@ -1,6 +1,6 @@
/* -*- C -*- /*
mboxgrep - scan mailbox for messages matching a regular expression mboxgrep - scan mailbox for messages matching a regular expression
Copyright (C) 2000, 2001, 2002, 2003 Daniel Spiljar Copyright (C) 2000 - 2003, 2023 Daniel Spiljar
Mboxgrep is free software; you can redistribute it and/or modify it Mboxgrep is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by under the terms of the GNU General Public License as published by
@ -15,8 +15,7 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with mboxgrep; if not, write to the Free Software Foundation, along with mboxgrep; if not, write to the Free Software Foundation,
Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
$Id: mh.h,v 1.6 2003-03-30 23:07:10 dspiljar Exp $ */
#ifndef MH_H #ifndef MH_H
#define MH_H 1 #define MH_H 1

View File

@ -1,6 +1,6 @@
/* -*- C -*- /*
mboxgrep - scan mailbox for messages matching a regular expression mboxgrep - scan mailbox for messages matching a regular expression
Copyright (C) 2000, 2001, 2002, 2003, 2006 Daniel Spiljar Copyright (C) 2000 - 2003, 2006, 2023 Daniel Spiljar
Mboxgrep is free software; you can redistribute it and/or modify it Mboxgrep is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by under the terms of the GNU General Public License as published by
@ -15,8 +15,7 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with mboxgrep; if not, write to the Free Software Foundation, along with mboxgrep; if not, write to the Free Software Foundation,
Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
$Id: misc.h,v 1.9 2006-07-06 10:53:49 dspiljar Exp $ */
#ifndef MISC_H #ifndef MISC_H
#define MISC_H 1 #define MISC_H 1

View File

@ -1,6 +1,6 @@
/* -*- C -*- /*
mboxgrep - scan mailbox for messages matching a regular expression mboxgrep - scan mailbox for messages matching a regular expression
Copyright (C) 2006 Daniel Spiljar Copyright (C) 2006, 2023 Daniel Spiljar
Mboxgrep is free software; you can redistribute it and/or modify it Mboxgrep is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by under the terms of the GNU General Public License as published by
@ -15,8 +15,7 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with mboxgrep; if not, write to the Free Software Foundation, along with mboxgrep; if not, write to the Free Software Foundation,
Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
$Id: re.c,v 1.3 2006-07-07 04:15:44 dspiljar Exp $ */
#include <config.h> #include <config.h>
#include <stdio.h> #include <stdio.h>
@ -37,13 +36,13 @@ pcre_init (void)
config.pcre_pattern = config.pcre_pattern =
(pcre *) pcre_compile (config.regex_s, (pcre *) pcre_compile (config.regex_s,
(config.ignorecase ? PCRE_CASELESS : 0), (config.ignorecase ? PCRE_CASELESS : 0),
&error, &errptr, NULL); &error, &errptr, NULL);
if (config.pcre_pattern == NULL) if (config.pcre_pattern == NULL)
{ {
if (config.merr) if (config.merr)
fprintf (stderr, "%s: %s: %s\n", APPNAME, config.regex_s, fprintf (stderr, "%s: %s: %s\n", APPNAME, config.regex_s,
error); error);
exit(2); exit(2);
} }
} }
@ -56,15 +55,15 @@ pcre_match (message_t *msg)
if (config.headers) if (config.headers)
config.res1 = config.res1 =
pcre_exec ((pcre *) config.pcre_pattern, pcre_exec ((pcre *) config.pcre_pattern,
(pcre_extra *) config.pcre_hints, (pcre_extra *) config.pcre_hints,
msg->headers, msg->headers,
(int) strlen (msg->headers), 0, 0, of, BUFSIZ); (int) strlen (msg->headers), 0, 0, of, BUFSIZ);
if (config.body) if (config.body)
config.res2 = config.res2 =
pcre_exec ((pcre *) config.pcre_pattern, pcre_exec ((pcre *) config.pcre_pattern,
(pcre_extra *) config.pcre_hints, (pcre_extra *) config.pcre_hints,
msg->body, msg->body,
(int) strlen (msg->body), 0, 0, of, BUFSIZ); (int) strlen (msg->body), 0, 0, of, BUFSIZ);
config.res1 = config.res1 ^ 1; config.res1 = config.res1 ^ 1;
config.res2 = config.res2 ^ 1; config.res2 = config.res2 ^ 1;
@ -88,11 +87,10 @@ regex_init (void)
if (0 != errcode) if (0 != errcode)
{ {
if (config.merr) if (config.merr)
{ {
regerror (errcode, (regex_t *) config.posix_pattern, errbuf, BUFSIZ); regerror (errcode, (regex_t *) config.posix_pattern, errbuf, BUFSIZ);
fprintf (stderr, "%s: %s: %s\n", APPNAME, config.regex_s, fprintf (stderr, "%s: %s: %s\n", APPNAME, config.regex_s, errbuf);
errbuf); }
}
exit (2); exit (2);
} }
} }
@ -102,8 +100,8 @@ regex_match (message_t *msg)
{ {
if (config.headers) if (config.headers)
config.res1 = regexec ((regex_t *) config.posix_pattern, config.res1 = regexec ((regex_t *) config.posix_pattern,
msg->headers, 0, NULL, 0); msg->headers, 0, NULL, 0);
if (config.body) if (config.body)
config.res2 = regexec ((regex_t *) config.posix_pattern, config.res2 = regexec ((regex_t *) config.posix_pattern,
msg->body, 0, NULL, 0); msg->body, 0, NULL, 0);
} }

View File

@ -1,6 +1,6 @@
/* -*- C -*- /*
mboxgrep - scan mailbox for messages matching a regular expression mboxgrep - scan mailbox for messages matching a regular expression
Copyright (C) 2006 Daniel Spiljar Copyright (C) 2006, 2023 Daniel Spiljar
Mboxgrep is free software; you can redistribute it and/or modify it Mboxgrep is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by under the terms of the GNU General Public License as published by
@ -15,8 +15,7 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with mboxgrep; if not, write to the Free Software Foundation, along with mboxgrep; if not, write to the Free Software Foundation,
Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
$Id: re.h,v 1.3 2006-07-07 04:15:44 dspiljar Exp $ */
#include "mboxgrep.h" #include "mboxgrep.h"

View File

@ -1,6 +1,6 @@
/* -*- C -*- /*
mboxgrep - scan mailbox for messages matching a regular expression mboxgrep - scan mailbox for messages matching a regular expression
Copyright (C) 2000, 2001, 2002, 2003 Daniel Spiljar Copyright (C) 2000 - 2003, 2023 Daniel Spiljar
Mboxgrep is free software; you can redistribute it and/or modify it Mboxgrep is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by under the terms of the GNU General Public License as published by
@ -15,8 +15,7 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with mboxgrep; if not, write to the Free Software Foundation, along with mboxgrep; if not, write to the Free Software Foundation,
Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
$Id: scan.h,v 1.7 2003-03-30 23:07:10 dspiljar Exp $ */
#ifndef SCAN_H #ifndef SCAN_H
#define SCAN_H 1 #define SCAN_H 1

View File

@ -1,6 +1,6 @@
/* -*- C -*- /* -*- C -*-
mboxgrep - scan mailbox for messages matching a regular expression mboxgrep - scan mailbox for messages matching a regular expression
Copyright (C) 2000, 2001, 2002, 2003 Daniel Spiljar Copyright (C) 2000 - 2003, 2023 Daniel Spiljar
Mboxgrep is free software; you can redistribute it and/or modify it Mboxgrep is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by under the terms of the GNU General Public License as published by
@ -15,8 +15,7 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with mboxgrep; if not, write to the Free Software Foundation, along with mboxgrep; if not, write to the Free Software Foundation,
Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
$Id: wrap.c,v 1.13 2006-01-20 03:00:39 dspiljar Exp $ */
#include <config.h> #include <config.h>
#include <unistd.h> #include <unistd.h>
@ -65,13 +64,13 @@ int m_open (const char *pathname, int flags, mode_t mode)
if (blah == -1 && config.merr) if (blah == -1 && config.merr)
{ {
if (config.merr) if (config.merr)
{ {
fprintf (stderr, "%s: %s: ", APPNAME, pathname); fprintf (stderr, "%s: %s: ", APPNAME, pathname);
perror (NULL); perror (NULL);
} }
/* failure to open a file for writing should be fatal */ /* failure to open a file for writing should be fatal */
if (((flags & O_WRONLY) == O_WRONLY) || ((flags & O_RDWR) == O_RDWR)) if (((flags & O_WRONLY) == O_WRONLY) || ((flags & O_RDWR) == O_RDWR))
exit (2); exit (2);
} }
return blah; return blah;
} }
@ -84,12 +83,12 @@ FILE *m_fopen (const char *path, const char *mode)
if (blah == NULL) if (blah == NULL)
{ {
if (config.merr) if (config.merr)
{ {
fprintf (stderr, "%s: %s: ", APPNAME, path); fprintf (stderr, "%s: %s: ", APPNAME, path);
perror (NULL); perror (NULL);
} }
if (mode[0] == 'w') if (mode[0] == 'w')
exit (2); exit (2);
} }
return blah; return blah;
} }
@ -102,7 +101,7 @@ FILE *m_fdopen (int fildes, const char *mode)
if (blah == NULL) if (blah == NULL)
{ {
if (config.merr) if (config.merr)
perror (APPNAME); perror (APPNAME);
} }
return blah; return blah;
} }
@ -117,7 +116,7 @@ gzFile *m_gzdopen (int fildes, const char *mode)
if (blah == NULL) if (blah == NULL)
{ {
if (config.merr) if (config.merr)
perror (APPNAME); perror (APPNAME);
} }
return blah; return blah;
} }
@ -132,10 +131,10 @@ DIR *m_opendir (const char *name)
if (blah == NULL) if (blah == NULL)
{ {
if (config.merr) if (config.merr)
{ {
fprintf (stderr, "%s: %s: ", APPNAME, name); fprintf (stderr, "%s: %s: ", APPNAME, name);
perror (NULL); perror (NULL);
} }
} }
return blah; return blah;
} }
@ -150,7 +149,7 @@ void *xmalloc (size_t size)
if (foo == NULL) if (foo == NULL)
{ {
if (config.merr) if (config.merr)
perror (APPNAME); perror (APPNAME);
exit (2); exit (2);
} }
return foo; return foo;
@ -164,7 +163,7 @@ void *xrealloc (void *ptr, size_t size)
if (foo == NULL) if (foo == NULL)
{ {
if (config.merr) if (config.merr)
perror (APPNAME); perror (APPNAME);
exit (2); exit (2);
} }
return foo; return foo;
@ -178,7 +177,7 @@ void *xcalloc (size_t nmemb, size_t size)
if (foo == NULL) if (foo == NULL)
{ {
if (config.merr) if (config.merr)
perror (APPNAME); perror (APPNAME);
exit (2); exit (2);
} }
return foo; return foo;
@ -192,7 +191,7 @@ char *xstrdup (const char *s)
if (foo == NULL) if (foo == NULL)
{ {
if (config.merr) if (config.merr)
perror (APPNAME); perror (APPNAME);
exit (2); exit (2);
} }
return foo; return foo;
@ -208,10 +207,10 @@ int m_unlink (const char *pathname)
if (baz == -1) if (baz == -1)
{ {
if (config.merr) if (config.merr)
{ {
fprintf (stderr, "%s: %s: ", APPNAME, pathname); fprintf (stderr, "%s: %s: ", APPNAME, pathname);
perror (NULL); perror (NULL);
} }
} }
return baz; return baz;
} }
@ -227,10 +226,10 @@ void gzwrite_loop (void *fp, char *str)
for (;;) for (;;)
{ {
len = gzwrite (fp, (str+quux), len = gzwrite (fp, (str+quux),
(((quux + BUFLEN) < baz) ? BUFLEN : (baz - quux))); (((quux + BUFLEN) < baz) ? BUFLEN : (baz - quux)));
quux += len; quux += len;
if (quux == baz) if (quux == baz)
break; break;
} }
} }
@ -247,10 +246,10 @@ void bzwrite_loop (void *fp, char *str)
for (;;) for (;;)
{ {
len = BZ2_bzwrite (fp, (str+quux), len = BZ2_bzwrite (fp, (str+quux),
(((quux + BUFLEN) < baz) ? BUFLEN : (baz - quux))); (((quux + BUFLEN) < baz) ? BUFLEN : (baz - quux)));
quux += len; quux += len;
if (quux == baz) if (quux == baz)
break; break;
} }
} }

View File

@ -1,6 +1,6 @@
/* -*- C -*- /*
mboxgrep - scan mailbox for messages matching a regular expression mboxgrep - scan mailbox for messages matching a regular expression
Copyright (C) 2000, 2001, 2002, 2003 Daniel Spiljar Copyright (C) 2000 - 2003, 2023 Daniel Spiljar
Mboxgrep is free software; you can redistribute it and/or modify it Mboxgrep is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by under the terms of the GNU General Public License as published by
@ -15,8 +15,7 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with mboxgrep; if not, write to the Free Software Foundation, along with mboxgrep; if not, write to the Free Software Foundation,
Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
$Id: wrap.h,v 1.12 2006-01-20 03:00:39 dspiljar Exp $ */
/* This file is part of mboxgrep. */ /* This file is part of mboxgrep. */