Browse Source

Add basic headers handling and body encoding

master
Damien Goutte-Gattat 10 years ago
parent
commit
026a032ecc
  1. 39
      src/fmail.c

39
src/fmail.c

@ -24,6 +24,7 @@
#include <stdlib.h>
#include <getopt.h>
#include <ctype.h>
#include <time.h>
/* Help and informations about the program. */
@ -96,7 +97,7 @@ qp_encode_stream(FILE *in, FILE *out)
fprintf(out, "=%02X", c);
n += 3;
}
else if ( isprintc(c) ) {
else if ( isprint(c) ) {
fputc(c, out);
n += 1;
}
@ -111,6 +112,37 @@ qp_encode_stream(FILE *in, FILE *out)
}
}
static void
print_date_header(FILE *out)
{
time_t timestamp;
struct tm *timestruct;
char buffer[32];
const char *rfc2822_format = "%a, %d %b %Y %H:%M:%S %z";
timestamp = time(NULL);
timestruct = localtime(&timestamp);
strftime(buffer, sizeof(buffer), rfc2822_format, timestruct);
fprintf(out, "Date: %s\r\n", buffer);
}
static void
process_given_headers(FILE *in, FILE *out)
{
char *buffer = NULL;
size_t len;
ssize_t n;
while ( (n = getline(&buffer, &len, in)) > 1 ) {
fwrite(buffer, 1, n - 1, out);
fprintf(out, "\r\n");
}
if ( buffer )
free(buffer);
}
/* Main function. */
@ -145,5 +177,10 @@ main(int argc, char *argv[])
}
}
print_date_header(stdout);
process_given_headers(stdin, stdout);
fprintf(stdout, "\r\n");
qp_encode_stream(stdin, stdout);
return EXIT_SUCCESS;
}
Loading…
Cancel
Save