Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Small bugfixes and some new functionality #3

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions imapinterface.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#include <stdio.h>
#include <string.h>
#ifdef USE_OPENSSL
#include <openssl/ssl.h>
#include <openssl/err.h>
#endif
#include "imapinterface.h"
#include "imap.h"
#include "mairix.h"
Expand Down
19 changes: 16 additions & 3 deletions mairix.c
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,7 @@ static void usage(void)/*{{{*/
"-t : include all messages in same threads as matching messages\n"
"-o <mfolder> : override setting of mfolder from mairixrc file\n"
"-r : force raw output regardless of mformat setting in mairixrc file\n"
"--no-lock : skip database locking when searching\n"
"-H : force hard links rather than symbolic ones\n"
"expr_i : search expression (all expr's AND'ed together):\n"
" word : match word in message body and major headers\n"
Expand Down Expand Up @@ -537,6 +538,7 @@ int main (int argc, char **argv)/*{{{*/
int do_fast_index = 0;
int do_mbox_symlinks = 0;
struct imap_ll *imapc = NULL;
int do_not_lock = 0;

unsigned int forced_hash_key = CREATE_RANDOM_DATABASE_HASH;

Expand Down Expand Up @@ -583,6 +585,8 @@ int main (int argc, char **argv)/*{{{*/
do_integrity_checks = 0;
} else if (!strcmp(*argv, "--unlock")) {
do_forced_unlock = 1;
} else if (!strcmp(*argv, "--no-lock")) {
do_not_lock = 1;
} else if (!strcmp(*argv, "-F") ||
!strcmp(*argv, "--fast-index")) {
do_fast_index = 1;
Expand All @@ -605,11 +609,14 @@ int main (int argc, char **argv)/*{{{*/
} else if (!strcmp(*argv, "-h") ||
!strcmp(*argv, "--help")) {
do_help = 1;
} else if ((*argv)[0] == '-') {
fprintf(stderr, "Unrecognized option %s\n", *argv);
} else if (!strcmp(*argv, "--")) {
/* End of args */
argc--;
argv++;
break;
} else if ((*argv)[0] == '-') {
fprintf(stderr, "Unrecognized option %s\n", *argv);
exit(3);
} else {
/* standard args start */
break;
Expand Down Expand Up @@ -699,7 +706,13 @@ int main (int argc, char **argv)/*{{{*/
signal(SIGINT, handlesig);
signal(SIGQUIT, handlesig);

lock_database(database_path, do_forced_unlock);
if (do_not_lock && !do_search) {
fprintf(stderr, "Using --no-lock only permitted for searching\n");
exit(2);
}

if (!do_not_lock)
lock_database(database_path, do_forced_unlock);

if (do_dump) {
dump_database(database_path);
Expand Down
20 changes: 14 additions & 6 deletions nvp.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,14 @@ struct nvp {/*{{{*/
/*}}}*/
static void append(struct nvp *nvp, struct nvp_entry *ne)/*{{{*/
{
if (!ne->rhs) {
ne->rhs = Malloc(1);
ne->rhs[0] = 0;
}
if (!ne->lhs) {
ne->lhs = Malloc(1);
ne->lhs[0] = 0;
}
ne->next = NULL;
ne->prev = nvp->last;
if (nvp->last) nvp->last->next = ne;
Expand Down Expand Up @@ -203,21 +211,21 @@ struct nvp *make_nvp(struct msg_src *src, char *s, const char *pfx)/*{{{*/
newstring[q - copy_start] = 0;
switch (last_copier) {
case COPY_TO_NAME:
if (name) free(name);
free(name);
name = newstring;
#ifdef VERBOSE_TEST
fprintf(stderr, " COPY_TO_NAME \"%s\"\n", name);
#endif
break;
case COPY_TO_MINOR:
if (minor) free(minor);
free(minor);
minor = newstring;
#ifdef VERBOSE_TEST
fprintf(stderr, " COPY_TO_MINOR \"%s\"\n", minor);
#endif
break;
case COPY_TO_VALUE:
if (value) free(value);
free(value);
value = newstring;
#ifdef VERBOSE_TEST
fprintf(stderr, " COPY_TO_VALUE \"%s\"\n", value);
Expand Down Expand Up @@ -309,9 +317,9 @@ struct nvp *make_nvp(struct msg_src *src, char *s, const char *pfx)/*{{{*/

out:
/* Not all productions consume these values */
if (name) free(name);
if (value) free(value);
if (minor) free(minor);
free(name);
free(value);
free(minor);
return result;
}
/*}}}*/
Expand Down
6 changes: 3 additions & 3 deletions rfc822.c
Original file line number Diff line number Diff line change
Expand Up @@ -863,7 +863,7 @@ static void do_multipart(struct msg_src *src,
do {
/* reject boundaries that aren't a whole line */
b1 = NULL;
for (bx = start_b1_search_from; bx < be - (boundary_len + 4); bx++) {
for (bx = start_b1_search_from; bx < be - (boundary_len + 2); bx++) {
if (bx[0] == '-' && bx[1] == '-' &&
!strncmp(bx+2, boundary, boundary_len)) {
b1 = bx;
Expand All @@ -876,12 +876,12 @@ static void do_multipart(struct msg_src *src,
return;
}

looking_at_end_boundary = (b1[boundary_len+2] == '-' &&
looking_at_end_boundary = (b1+boundary_len+3 < be) && (b1[boundary_len+2] == '-' &&
b1[boundary_len+3] == '-');
boundary_ok = 1;
if ((b1 > input) && (*(b1-1) != '\n'))
boundary_ok = 0;
if (!looking_at_end_boundary && !(
if (!looking_at_end_boundary && (b1 + boundary_len + 3 < be) && !(
((b1 + boundary_len + 2 < input + input_len) && (*(b1 + boundary_len + 2) == '\n')) ||
((b1 + boundary_len + 3 < input + input_len) && (*(b1 + boundary_len + 2) == '\r') && (*(b1 + boundary_len + 3) == '\n'))
))
Expand Down
2 changes: 2 additions & 0 deletions search.c
Original file line number Diff line number Diff line change
Expand Up @@ -1322,6 +1322,8 @@ static int do_search(struct read_db *db, char **args, char *output_path, int sho
if (parsed->hdrs.subject) printf(" Subject: %s\n", parsed->hdrs.subject);
if (parsed->hdrs.message_id)
printf(" Message-ID: %s\n", parsed->hdrs.message_id);
if (parsed->hdrs.in_reply_to)
printf(" In-Reply-To:%s\n", parsed->hdrs.in_reply_to);
thetm = gmtime(&parsed->hdrs.date);
strftime(datebuf, sizeof(datebuf), "%a, %d %b %Y", thetm);
printf(" Date: %s\n", datebuf);
Expand Down