Browse Source

Add Quoted-Printable encoding function

master
Damien Goutte-Gattat 10 years ago
parent
commit
e1d6815412
  1. 53
      src/fmail.c

53
src/fmail.c

@ -23,6 +23,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <getopt.h>
#include <ctype.h>
/* Help and informations about the program. */
@ -60,6 +61,58 @@ See the COPYING file or <http://www.gnu.org/licenses/gpl.html>.\n\
/* Helper functions. */
static void
qp_encode_stream(FILE *in, FILE *out)
{
int c;
unsigned n;
n = 0;
while ( ! feof(in) ) {
c = fgetc(in);
if ( n >= 72 ) {
fprintf(out, "=\r\n");
n = 0;
}
if ( c == '\t' || c == ' ' ) {
int next = fgetc(in);
if ( next == '\n' ) {
fprintf(out, "=%02X", c);
n += 3;
}
else {
fputc(c, out);
n += 1;
}
ungetc(next, in);
}
else if ( c == '=' ) {
fprintf(out, "=%02X", c);
n += 3;
}
else if ( isprintc(c) ) {
fputc(c, out);
n += 1;
}
else if ( c == '\n' ) {
fprintf(out, "\r\n");
n = 0;
}
else if ( c != EOF ) {
fprintf(out, "=%02X", c);
n += 3;
}
}
}
/* Main function. */
int

Loading…
Cancel
Save