Browse Source

Add basic support for attachments

master
Damien Goutte-Gattat 11 years ago
parent
commit
850339e7a5
  1. 32
      src/fmail.c

32
src/fmail.c

@ -216,14 +216,40 @@ read_headers(FILE *in, string_buffer_t *headers)
}
}
static void process_attachment(const char *, magic_t, FILE *);
static void
process_text_body(FILE *in, FILE *out)
process_text_body(FILE *in,
char **attachments,
size_t att_count,
magic_t mgc_ctx,
FILE *out)
{
char boundary[32];
int i;
if ( att_count > 0 ) {
generate_boundary(boundary, sizeof(boundary));
fprintf(out, "Content-Type: multipart/mixed;\r\n"
" boundary=\"%s\"\r\n"
"\r\n"
"--%s\r\n",
boundary, boundary);
}
fprintf(out, "Content-Type: text/plain; charset=\"utf-8\"\r\n"
"Content-Transfer-Encoding: quoted-printable\r\n"
"Content-Disposition: inline\r\n\r\n");
qp_encode_stream(in, out);
fprintf(out, "\r\n");
for ( i = 0; i < att_count; i++ ) {
fprintf(out, "--%s\r\n", boundary);
process_attachment(attachments[i], mgc_ctx, out);
if ( i == att_count - 1 )
fprintf(out, "--%s--\r\n", boundary);
}
}
@ -413,7 +439,7 @@ main(int argc, char *argv[])
if ( sign_ctx ) {
FILE *tmp = tmpfile();
process_text_body(stdin, tmp);
process_text_body(stdin, attachments, att_count, mgc_ctx, tmp);
fseek(tmp, 0, SEEK_SET);
sign_stream(sign_ctx, tmp, stdout);
@ -421,7 +447,7 @@ main(int argc, char *argv[])
gpgme_release(sign_ctx);
}
else
process_text_body(stdin, stdout);
process_text_body(stdin, attachments, att_count, mgc_ctx, stdout);
if ( attachments )
free(attachments);

Loading…
Cancel
Save