|
|
@ -26,6 +26,8 @@ |
|
|
|
#include <ctype.h> |
|
|
|
#include <time.h> |
|
|
|
|
|
|
|
#include <sbuffer.h> |
|
|
|
|
|
|
|
|
|
|
|
/* Help and informations about the program. */ |
|
|
|
|
|
|
@ -113,7 +115,7 @@ qp_encode_stream(FILE *in, FILE *out) |
|
|
|
} |
|
|
|
|
|
|
|
static void |
|
|
|
print_date_header(FILE *out) |
|
|
|
make_date_header(string_buffer_t *headers) |
|
|
|
{ |
|
|
|
time_t timestamp; |
|
|
|
struct tm *timestruct; |
|
|
@ -124,23 +126,33 @@ print_date_header(FILE *out) |
|
|
|
timestruct = localtime(×tamp); |
|
|
|
strftime(buffer, sizeof(buffer), rfc2822_format, timestruct); |
|
|
|
|
|
|
|
fprintf(out, "Date: %s\r\n", buffer); |
|
|
|
sb_addf(headers, "Date: %s\r\n", buffer); |
|
|
|
} |
|
|
|
|
|
|
|
static void |
|
|
|
process_given_headers(FILE *in, FILE *out) |
|
|
|
read_headers(FILE *in, string_buffer_t *headers) |
|
|
|
{ |
|
|
|
char *buffer = NULL; |
|
|
|
size_t len; |
|
|
|
ssize_t n; |
|
|
|
int c, empty_line; |
|
|
|
size_t n; |
|
|
|
|
|
|
|
while ( (n = getline(&buffer, &len, in)) > 1 ) { |
|
|
|
fwrite(buffer, 1, n - 1, out); |
|
|
|
fprintf(out, "\r\n"); |
|
|
|
} |
|
|
|
n = empty_line = 0; |
|
|
|
|
|
|
|
if ( buffer ) |
|
|
|
free(buffer); |
|
|
|
while ( ! empty_line ) { |
|
|
|
c = fgetc(in); |
|
|
|
|
|
|
|
if ( c == '\n' ) { |
|
|
|
if ( n == 0 ) |
|
|
|
empty_line = 1; |
|
|
|
else { |
|
|
|
sb_add(headers, "\r\n"); |
|
|
|
n = 0; |
|
|
|
} |
|
|
|
} |
|
|
|
else { |
|
|
|
sb_addc(headers, c); |
|
|
|
n += 1; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -151,6 +163,7 @@ int |
|
|
|
main(int argc, char *argv[]) |
|
|
|
{ |
|
|
|
char c; |
|
|
|
string_buffer_t *headers; |
|
|
|
|
|
|
|
struct option options[] = { |
|
|
|
{ "help", 0, NULL, 'h' }, |
|
|
@ -159,6 +172,7 @@ main(int argc, char *argv[]) |
|
|
|
}; |
|
|
|
|
|
|
|
setprogname(argv[0]); |
|
|
|
headers = sb_new(0); |
|
|
|
|
|
|
|
while ( (c = getopt_long(argc, argv, "hv", |
|
|
|
options, NULL)) != -1 ) { |
|
|
@ -177,9 +191,9 @@ main(int argc, char *argv[]) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
print_date_header(stdout); |
|
|
|
process_given_headers(stdin, stdout); |
|
|
|
fprintf(stdout, "\r\n"); |
|
|
|
make_date_header(headers); |
|
|
|
read_headers(stdin, headers); |
|
|
|
fprintf(stdout, "%s\r\n", sb_get(headers)); |
|
|
|
qp_encode_stream(stdin, stdout); |
|
|
|
|
|
|
|
return EXIT_SUCCESS; |
|
|
|