From e8bc7fca1bef99f0b14fe791594be95cfed134f2 Mon Sep 17 00:00:00 2001 From: Jeremy Harris Date: Tue, 23 Dec 2014 19:43:33 +0000 Subject: [PATCH] Code tidying --- src/src/receive.c | 44 +++++++++++++++--------------- src/src/spam.c | 7 ++--- src/src/transport.c | 65 ++++++++++++++++++++++++--------------------- 3 files changed, 58 insertions(+), 58 deletions(-) diff --git a/src/src/receive.c b/src/src/receive.c index df5441b6a..0466cab8d 100644 --- a/src/src/receive.c +++ b/src/src/receive.c @@ -1232,40 +1232,40 @@ if (Ustrlen(rfc822_file_path) > 0) if (rc == OK) { uschar temp_path[1024]; - struct dirent *entry; - DIR *tempdir; + struct dirent * entry; + DIR * tempdir; - (void)string_format(temp_path, 1024, "%s/scan/%s", spool_directory, - message_id); + (void) string_format(temp_path, sizeof(temp_path), "%s/scan/%s", + spool_directory, message_id); tempdir = opendir(CS temp_path); - do + for (;;) { - entry = readdir(tempdir); - if (entry == NULL) break; - if (strncmpic(US entry->d_name,US"__rfc822_",9) == 0) + if (!(entry = readdir(tempdir))) + break; + if (strncmpic(US entry->d_name, US"__rfc822_", 9) == 0) { - (void)string_format(rfc822_file_path, 2048,"%s/scan/%s/%s", spool_directory, message_id, entry->d_name); - debug_printf("RFC822 attachment detected: running MIME ACL for '%s'\n", rfc822_file_path); + (void) string_format(rfc822_file_path, sizeof(rfc822_file_path), + "%s/scan/%s/%s", spool_directory, message_id, entry->d_name); + debug_printf("RFC822 attachment detected: running MIME ACL for '%s'\n", + rfc822_file_path); break; } - } while (1); + } closedir(tempdir); - if (entry != NULL) + if (entry) { - mbox_file = Ufopen(rfc822_file_path,"rb"); - if (mbox_file == NULL) + if ((mbox_file = Ufopen(rfc822_file_path, "rb"))) { - log_write(0, LOG_PANIC, - "acl_smtp_mime: can't open RFC822 spool file, skipping."); - unlink(CS rfc822_file_path); - goto END_MIME_ACL; + /* set RFC822 expansion variable */ + mime_is_rfc822 = 1; + mime_part_count_buffer = mime_part_count; + goto MIME_ACL_CHECK; } - /* set RFC822 expansion variable */ - mime_is_rfc822 = 1; - mime_part_count_buffer = mime_part_count; - goto MIME_ACL_CHECK; + log_write(0, LOG_PANIC, + "acl_smtp_mime: can't open RFC822 spool file, skipping."); + unlink(CS rfc822_file_path); } } diff --git a/src/src/spam.c b/src/src/spam.c index dab57ff12..45a06931c 100644 --- a/src/src/spam.c +++ b/src/src/spam.c @@ -95,11 +95,8 @@ spam(uschar **listptr) spam_ok = 0; /* if we scanned for this username last time, just return */ - if ( spam_ok && Ustrcmp(prev_user_name, user_name) == 0) - if (override) - return OK; - else - return spam_rc; + if (spam_ok && Ustrcmp(prev_user_name, user_name) == 0) + return override ? OK : spam_rc; /* make sure the eml mbox file is spooled up */ mbox_file = spool_mbox(&mbox_size, NULL); diff --git a/src/src/transport.c b/src/src/transport.c index e833894a8..30e4268d1 100644 --- a/src/src/transport.c +++ b/src/src/transport.c @@ -1015,7 +1015,6 @@ char sbuf[2048]; int sread = 0; int wwritten = 0; uschar *dkim_signature = NULL; -off_t size = 0; /* If we can't sign, just call the original function. */ @@ -1103,12 +1102,6 @@ if (dkim_private_key && dkim_domain && dkim_selector) } } -/* Fetch file size */ -size = lseek(dkim_fd, 0, SEEK_END); - -/* Rewind file */ -lseek(dkim_fd, 0, SEEK_SET); - #ifdef HAVE_LINUX_SENDFILE /* We can use sendfile() to shove the file contents to the socket. However only if we don't use TLS, @@ -1116,8 +1109,13 @@ lseek(dkim_fd, 0, SEEK_SET); before the data finally hits the socket. */ if (tls_out.active != fd) { + off_t size = lseek(dkim_fd, 0, SEEK_END); /* Fetch file size */ ssize_t copied = 0; off_t offset = 0; + + /* Rewind file */ + lseek(dkim_fd, 0, SEEK_SET); + while(copied >= 0 && offset < size) copied = sendfile(fd, dkim_fd, &offset, size - offset); if (copied < 0) @@ -1125,42 +1123,47 @@ if (tls_out.active != fd) save_errno = errno; rc = FALSE; } - goto CLEANUP; } +else + #endif -/* Send file down the original fd */ -while((sread = read(dkim_fd, sbuf, 2048)) > 0) { - char *p = sbuf; - /* write the chunk */ + /* Rewind file */ + lseek(dkim_fd, 0, SEEK_SET); - while (sread) + /* Send file down the original fd */ + while((sread = read(dkim_fd, sbuf, 2048)) > 0) { + char *p = sbuf; + /* write the chunk */ + + while (sread) + { #ifdef SUPPORT_TLS - wwritten = tls_out.active == fd - ? tls_write(FALSE, US p, sread) - : write(fd, p, sread); + wwritten = tls_out.active == fd + ? tls_write(FALSE, US p, sread) + : write(fd, p, sread); #else - wwritten = write(fd, p, sread); + wwritten = write(fd, p, sread); #endif - if (wwritten == -1) - { - /* error, bail out */ - save_errno = errno; - rc = FALSE; - goto CLEANUP; + if (wwritten == -1) + { + /* error, bail out */ + save_errno = errno; + rc = FALSE; + goto CLEANUP; + } + p += wwritten; + sread -= wwritten; } - p += wwritten; - sread -= wwritten; } - } -if (sread == -1) - { - save_errno = errno; - rc = FALSE; - goto CLEANUP; + if (sread == -1) + { + save_errno = errno; + rc = FALSE; + } } CLEANUP: -- 2.30.2