Page MenuHomeFreeBSD

D48381.diff
No OneTemporary

D48381.diff

diff --git a/usr.bin/bintrans/bintrans.1 b/usr.bin/bintrans/bintrans.1
--- a/usr.bin/bintrans/bintrans.1
+++ b/usr.bin/bintrans/bintrans.1
@@ -236,6 +236,8 @@
Output to
.Ar output_file
instead of standard output.
+.It fl r
+Encode/Decode in RFC2047 specific variant.
.El
.Sh EXAMPLES
The following example packages up a source tree, compresses it,
diff --git a/usr.bin/bintrans/qp.c b/usr.bin/bintrans/qp.c
--- a/usr.bin/bintrans/qp.c
+++ b/usr.bin/bintrans/qp.c
@@ -51,7 +51,7 @@
static void
-decode_quoted_printable(const char *body, FILE *fpo)
+decode_quoted_printable(const char *body, FILE *fpo, bool rfc2047)
{
while (*body != '\0') {
switch (*body) {
@@ -80,6 +80,12 @@
fputc(decode_char(body), fpo);
body += 2;
break;
+ case '_':
+ if (rfc2047) {
+ fputc(0x20, fpo);
+ break;
+ }
+ /* FALLTHROUGH */
default:
fputc(*body, fpo);
break;
@@ -89,7 +95,7 @@
}
static void
-encode_quoted_printable(const char *body, FILE *fpo)
+encode_quoted_printable(const char *body, FILE *fpo, bool rfc2047)
{
const char *end = body + strlen(body);
size_t linelen = 0;
@@ -111,7 +117,10 @@
if ((*body == ' ' || *body == '\t') &&
body + 1 < end &&
(body[1] != '\n' && body[1] != '\r')) {
- fputc(*body, fpo);
+ if (*body == 0x20 && rfc2047)
+ fputc('_', fpo);
+ else
+ fputc(*body, fpo);
prev = *body;
} else {
fprintf(fpo, "=%02X", (unsigned char)*body);
@@ -135,16 +144,16 @@
}
static void
-qp(FILE *fp, FILE *fpo, bool encode)
+qp(FILE *fp, FILE *fpo, bool encode, bool rfc2047)
{
char *line = NULL;
size_t linecap = 0;
- void (*codec)(const char *line, FILE *f);
+ void (*codec)(const char *line, FILE *f, bool rfc2047);
codec = encode ? encode_quoted_printable : decode_quoted_printable ;
while (getline(&line, &linecap, fp) > 0)
- codec(line, fpo);
+ codec(line, fpo, rfc2047);
free(line);
}
@@ -152,7 +161,7 @@
usage(void)
{
fprintf(stderr,
- "usage: bintrans qp [-d] [-o outputfile] [file name]\n");
+ "usage: bintrans qp [-d] [-r] [-o outputfile] [file name]\n");
}
int
@@ -160,6 +169,7 @@
{
int ch;
bool encode = true;
+ bool rfc2047 = false;
FILE *fp = stdin;
FILE *fpo = stdout;
@@ -167,10 +177,11 @@
{
{ "decode", no_argument, NULL, 'd'},
{ "output", required_argument, NULL, 'o'},
+ { "rfc2047", no_argument, NULL, 'r'},
{NULL, no_argument, NULL, 0}
};
- while ((ch = getopt_long(argc, argv, "do:u", opts, NULL)) != -1) {
+ while ((ch = getopt_long(argc, argv, "do:ru", opts, NULL)) != -1) {
switch(ch) {
case 'o':
fpo = fopen(optarg, "w");
@@ -184,6 +195,9 @@
case 'd':
encode = false;
break;
+ case 'r':
+ rfc2047 = true;
+ break;
default:
usage();
exit(EXIT_FAILURE);
@@ -198,7 +212,7 @@
exit(EXIT_FAILURE);
}
}
- qp(fp, fpo, encode);
+ qp(fp, fpo, encode, rfc2047);
return (EXIT_SUCCESS);
}

File Metadata

Mime Type
text/plain
Expires
Thu, May 1, 1:09 PM (17 h, 8 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
17882032
Default Alt Text
D48381.diff (2 KB)

Event Timeline