Browse Source

Add Quoted-Printable encoding function

tags/v0.1.0
Damien Goutte-Gattat 9 years ago
parent
commit
e1d6815412
1 changed files with 53 additions and 0 deletions
  1. +53
    -0
      src/fmail.c

+ 53
- 0
src/fmail.c View File

@@ -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