ba01e1269f4acfefaff02b195a8f58f293e54454
[citadel.git] / citadel / qpdecode.c
1 /*
2  * Convert "quoted printable" encoding to binary (stdin to stdout)
3  * Copyright (C) 1999 by Art Cancro
4  * Distributed under the terms of the GNU General Public License.
5  */
6
7 #include <stdlib.h>
8 #include <unistd.h>
9 #include <stdio.h>
10 #include <ctype.h>
11 #include <string.h>
12
13 int main(int argc, char *argv[]) {
14         char buf[80];
15         int soft_line_break = 0;
16         int ch;
17
18         while (fgets(buf, 80, stdin) != NULL) {
19                 while (isspace(buf[strlen(buf)-1]))
20                         buf[strlen(buf)-1] = 0;
21                 soft_line_break = 0;
22
23                 while (strlen(buf) > 0) {
24                         if (!strcmp(buf, "=")) {
25                                 soft_line_break = 1;
26                                 strcpy(buf, "");
27                         } else if ( (strlen(buf)>=3) && (buf[0]=='=') ) {
28                                 sscanf(&buf[1], "%02x", &ch);
29                                 putc(ch, stdout);
30                                 strcpy(buf, &buf[3]);
31                         } else {
32                                 putc(buf[0], stdout);
33                                 strcpy(buf, &buf[1]);
34                         }
35                 }
36                 if (soft_line_break == 0) printf("\r\n");
37         }
38         exit(0);
39 }