aboutsummaryrefslogtreecommitdiffstats
path: root/mail/mboxgrep
diff options
context:
space:
mode:
authormi <mi@FreeBSD.org>2007-03-09 16:05:08 +0800
committermi <mi@FreeBSD.org>2007-03-09 16:05:08 +0800
commitb4494573cfe122410156b8c7991313902356dd68 (patch)
tree66fe7fc487a85d754b60367103526370a8714491 /mail/mboxgrep
parent70cfb75eaa7229f1455d3078f837821e5698e6fd (diff)
downloadfreebsd-ports-graphics-b4494573cfe122410156b8c7991313902356dd68.tar.gz
freebsd-ports-graphics-b4494573cfe122410156b8c7991313902356dd68.tar.zst
freebsd-ports-graphics-b4494573cfe122410156b8c7991313902356dd68.zip
Don't use the bundled md5.c and getopt1.c in favor of OpenSSL and
USE_GETOPT_LONG respectively. This reduces the executable's size considerably. (More ports should be doing this.) When comparing md5 checksums (used to detect duplicates in the input), treat each as a pair of 8-byte integers instead of calling strncmp, which was just plain buggy. Memcmp should've been used instead, but two integer comparisions are even faster. Re-work the resizable array of checksums removing a separate malloc call for each md5 checksum. This reduces the runtime memory consumption considerably. (Tried using a hashtable instead of linearly searching through the array, but did not see a speed-gain even over a large collection of messages.) Vendor notified, but has not responded (the software's last release is several years old). Bump PORTREVISION. Approved by: maintainer
Diffstat (limited to 'mail/mboxgrep')
-rw-r--r--mail/mboxgrep/Makefile3
-rw-r--r--mail/mboxgrep/files/patch-md5160
-rw-r--r--mail/mboxgrep/files/patch-noredundancy16
3 files changed, 179 insertions, 0 deletions
diff --git a/mail/mboxgrep/Makefile b/mail/mboxgrep/Makefile
index 2d2e51ed01b..a9ee8543d4e 100644
--- a/mail/mboxgrep/Makefile
+++ b/mail/mboxgrep/Makefile
@@ -7,6 +7,7 @@
PORTNAME= mboxgrep
PORTVERSION= 0.7.9
+PORTREVISION= 1
CATEGORIES= mail
MASTER_SITES= ${MASTER_SITE_SOURCEFORGE}
MASTER_SITE_SUBDIR= ${PORTNAME}
@@ -20,6 +21,8 @@ LIB_DEPENDS= pcre.0:${PORTSDIR}/devel/pcre
GNU_CONFIGURE= yes
CONFIGURE_ENV+= CFLAGS="${CFLAGS} -I${LOCALBASE}/include" LIBS="-L${LOCALBASE}/lib"
+USE_OPENSSL= yes
+USE_GETOPT_LONG=yes
MAN1= mboxgrep.1
INFO= mboxgrep
diff --git a/mail/mboxgrep/files/patch-md5 b/mail/mboxgrep/files/patch-md5
new file mode 100644
index 00000000000..87e6f297a58
--- /dev/null
+++ b/mail/mboxgrep/files/patch-md5
@@ -0,0 +1,160 @@
+--- src/mboxgrep.h Sun Apr 6 17:01:49 2003
++++ src/mboxgrep.h Tue Feb 27 17:24:30 2007
+@@ -29,4 +29,5 @@
+
+ #include <config.h>
++#include <stdint.h>
+
+ #include <time.h> /* for tm structure */
+@@ -100,8 +101,13 @@
+ folder_t;
+
++typedef union {
++ uint64_t halves[2];
++ unsigned char bytes[16];
++} md5_t;
++
+ typedef struct
+ {
+- char **md5;
+ int n;
++ md5_t md5s[];
+ }
+ checksum_t;
+--- src/scan.c Sun Apr 6 17:01:49 2003
++++ src/scan.c Tue Feb 27 17:19:23 2007
+@@ -60,5 +60,5 @@
+ #include "maildir.h"
+ #include "wrap.h"
+-#include "md5.h"
++#include <openssl/md5.h>
+ #ifdef HAVE_FTS_OPEN
+ # include <sys/stat.h>
+@@ -74,5 +74,8 @@
+ #endif /* HAVE_LIBDMALLOC */
+
+-void scan_mailbox (char path[])
++static int md5_check_message (const char *body, size_t bbytes);
++
++void
++scan_mailbox (const char path[])
+ /* {{{ */
+ {
+@@ -96,5 +99,4 @@
+ time_t tt;
+ struct tm *ct;
+- extern checksum_t *cs;
+
+ extern option_t config;
+@@ -145,10 +147,10 @@
+ if ((config.format == MBOX) || (config.format == ZMBOX) ||
+ (config.format == BZ2MBOX))
+- msg = (message_t *) mbox_read_message (mbox);
++ msg = mbox_read_message (mbox);
+ else if ((config.format == MH) || (config.format == NNMH) ||
+ (config.format == NNML))
+- msg = (message_t *) mh_read_message (boxd);
++ msg = mh_read_message (boxd);
+ else if (config.format == MAILDIR)
+- msg = (message_t *) maildir_read_message (maildird);
++ msg = maildir_read_message (maildird);
+
+ if (msg == NULL) break;
+@@ -179,5 +181,5 @@
+
+ if (config.dedup)
+- isdup = md5_check_message (msg->body, cs);
++ isdup = md5_check_message (msg->body, msg->bbytes);
+
+ if (((res1 == 0) | (res2 == 0)) ^ ((config.invert ^ delete)) &&
+@@ -282,5 +284,6 @@
+ /* }}} */
+
+-void recursive_scan (char path[])
++void
++recursive_scan (const char path[])
+ /* {{{ */
+
+@@ -313,5 +316,5 @@
+ }
+ #else
+- ftw (path, (void *) scan_mailbox, 1);
++ ftw (path, (int (*)(const char *, const struct *, int))scan_mailbox, 1);
+ #endif /* HAVE_FTS_OPEN */
+ }
+@@ -319,29 +322,33 @@
+ /* }}} */
+
+-int md5_check_message (char *body, checksum_t *chksum)
++static int
++md5_check_message (const char *body, size_t bbytes)
+ /* {{{ */
+ {
+- struct md5_ctx a;
+- unsigned char b[16];
++ MD5_CTX a;
++ md5_t b;
+ int i;
++ extern checksum_t *cs;
+
+- md5_init_ctx (&a);
++ MD5_Init(&a);
+ if (body == NULL)
+- md5_process_bytes ("", 0, &a);
++ MD5_Update(&a, "", 0);
+ else
+- md5_process_bytes (body, strlen(body), &a);
+- md5_finish_ctx(&a, b);
++ MD5_Update(&a, body, bbytes);
++ MD5_Final(b.bytes, &a);
+
+- for (i = 0; i < chksum->n; i++)
++ for (i = 0; i < cs->n; i++)
+ {
+- if (0 == strncmp (chksum->md5[i], b, 16))
++ if (b.halves[0] == cs->md5s[i].halves[0] &&
++ b.halves[1] == cs->md5s[i].halves[1])
+ return 1;
+ }
+
+- chksum->md5 =
+- (char **) xrealloc (chksum->md5, (1 + chksum->n) * sizeof (char *));
+- chksum->md5[chksum->n] = xstrdup (b);
++ cs =
++ xrealloc (cs, sizeof(checksum_t) + (i + 1) * sizeof (md5_t));
++ cs->md5s[i].halves[0] = b.halves[0];
++ cs->md5s[i].halves[1] = b.halves[1];
+
+- (chksum->n)++;
++ cs->n++;
+
+ return 0;
+--- src/scan.h Sun Mar 30 18:07:10 2003
++++ src/scan.h Tue Feb 27 16:51:58 2007
+@@ -24,7 +24,6 @@
+ #include "mboxgrep.h"
+
+-void scan_mailbox (char path[]);
+-void recursive_scan (char path[]);
+-int md5_check_message (char *body, checksum_t *chksum);
++void scan_mailbox(const char path[]);
++void recursive_scan(const char path[]);
+
+ #endif /* SCAN_H */
+--- src/main.c Sun Aug 24 15:23:50 2003
++++ src/main.c Tue Feb 27 17:25:30 2007
+@@ -56,5 +56,5 @@
+ int maildir_count = 0;
+ int count = 0;
+-void *tmpp;
++FILE *tmpp;
+ checksum_t *cs;
+
+@@ -239,6 +239,5 @@
+ }
+
+- cs = (checksum_t *) xmalloc (sizeof (checksum_t));
+- cs->md5 = (char **) xcalloc (1, sizeof (char **));
++ cs = xmalloc (sizeof (checksum_t));
+ cs->n = 0;
+
diff --git a/mail/mboxgrep/files/patch-noredundancy b/mail/mboxgrep/files/patch-noredundancy
new file mode 100644
index 00000000000..1d942eb8676
--- /dev/null
+++ b/mail/mboxgrep/files/patch-noredundancy
@@ -0,0 +1,16 @@
+--- src/Makefile.in Sun Mar 30 18:07:10 2003
++++ src/Makefile.in Tue Feb 27 16:50:18 2007
+@@ -22,10 +22,10 @@
+ CC = @CC@
+ OBJS = info.o main.o mh.o scan.o maildir.o mbox.o misc.o \
+- wrap.o getopt.o getopt1.o md5.o
++ wrap.o
+ SRCS = info.c main.c mh.c scan.c maildir.c mbox.c misc.c \
+- wrap.c getopt.c getopt1.c md5.c
++ wrap.c
+ TARGET = mboxgrep
+ CFLAGS = @CFLAGS@
+-LIBS = @LIBS@
++LIBS = @LIBS@ -lcrypto
+ INSTALL = @INSTALL@
+ prefix = @prefix@