From nobody Thu Jan 16 09:18:21 2025 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4YYcjV0kYjz5lQP7; Thu, 16 Jan 2025 09:18:22 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R11" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4YYcjT6sZpz3mnv; Thu, 16 Jan 2025 09:18:21 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1737019102; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=yrNr6Ssphe5mSAioFOsjT46UJVnO2ASjAATUfErB6SE=; b=j1Vimv2YoIwOPkg0QfJvmW9G8K/r/XA38V+nY99iWfz1gOKcao5GXN9imZRXzniE/kZzdJ rQdJIFf0PQxv1WULmjyXWNw0XAYAae6RRccMESuhtZkaUd7iUAbq0XIkDctdNH51RRKpMn VPF1PrR9tXsi25VgoEnJUgZWcx3rRmRBpeazK3EdqsYKLoqaQLVnYxc6iFvMmQBVefQZIW ZvzJYBxsdUEQcgIwv71mY23ZLEg3eMJeSqz6ur5XoKngbdgWpLXs10qn4rDP+6G1cyLyy9 FG5p/BFJ75YTmTW6SV4HX7fAwTpLZuoatrEHuFpCAWvJeIcWp1w3/tZvSOvD7Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1737019102; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=yrNr6Ssphe5mSAioFOsjT46UJVnO2ASjAATUfErB6SE=; b=vJ910Q4fooOpCKQg0ZPCeG4CKWJ1kG4rXEaB79VHrJgGYPTYjl1h+HtmEEu8lv9XNFBzoD inWZNJi6rV3Od/4W1Ty7HEbqkXXJd/G9/tc0SC0AGQUF4u8kO+5mPOiz4NbcicL8h5FLwr SQw2cqjBYTSoM5JiLpjXAfAnfskruiULKVjxrAX+qdnWgR78+5SQUQsIDzfG0WN32pIKP3 WCCvs9Pdj6yuiwRfEckDmItQdr0VIYS9za8q9/qI6Zc4n7GrJ/3WJb6cNVmYBa0BEXJrZ4 Ooe8cpQs0gdmFjl54y42pQf2sNHu/bsUC4lWA8vEFuW3BuGv89VwK+wK3ohoZQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1737019102; a=rsa-sha256; cv=none; b=iOb6z2ORHDYevrYUNas5qKm0kCdZJXsqLzobKAJyDOhl3cFcWZELwUFZ79oiOiTG9y/9pa 7VRvOtOcRDpLn4pnn/dtdDvyz1v2u+fP1ZszZGfQVTWUMypnr6RwKwp9hJbHDCrEnGhfLq eV4WreKsSIBAbZ+ENklXP59wT03mm16b+b+ZUIfteNLloDzc9OM9+WQi16XKzSppTVxCbk z3T7Gv5dpbLgQXg6Y574kfS028DROeRZ95a1nI5juE1+5zZZuPJp17E2kOI5gHVBB47D5B Szj49MFDy4p+123ASnmjTpOTqHfrcGOe2pP6eQ/lu53Ukf5sbHctLMoSuXFLng== ARC-Authentication-Results: i=1; mx1.freebsd.org; none Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4YYcjT6KHjzB7C; Thu, 16 Jan 2025 09:18:21 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 50G9IL0R096069; Thu, 16 Jan 2025 09:18:21 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 50G9IL1G096065; Thu, 16 Jan 2025 09:18:21 GMT (envelope-from git) Date: Thu, 16 Jan 2025 09:18:21 GMT Message-Id: <202501160918.50G9IL1G096065@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Baptiste Daroussin Subject: git: 1795eae9a2cf - stable/14 - bintrans(1): RFC2047 variant of quoted print List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: bapt X-Git-Repository: src X-Git-Refname: refs/heads/stable/14 X-Git-Reftype: branch X-Git-Commit: 1795eae9a2cfdd0d83dc2b76420d55d363627ae7 Auto-Submitted: auto-generated The branch stable/14 has been updated by bapt: URL: https://cgit.FreeBSD.org/src/commit/?id=1795eae9a2cfdd0d83dc2b76420d55d363627ae7 commit 1795eae9a2cfdd0d83dc2b76420d55d363627ae7 Author: Baptiste Daroussin AuthorDate: 2025-01-08 12:39:30 +0000 Commit: Baptiste Daroussin CommitDate: 2025-01-16 09:18:14 +0000 bintrans(1): RFC2047 variant of quoted print MFC After: 1 week Reviewed by: pstref Differential Revision: https://reviews.freebsd.org/D48381 (cherry picked from commit beab8b1ddf86a88e0605562f2cc1d6a26c68604f) --- usr.bin/bintrans/bintrans.1 | 2 ++ usr.bin/bintrans/qp.c | 32 +++++++++++++++++++++++--------- 2 files changed, 25 insertions(+), 9 deletions(-) diff --git a/usr.bin/bintrans/bintrans.1 b/usr.bin/bintrans/bintrans.1 index 4177a5c6b9eb..02571067c8f0 100644 --- a/usr.bin/bintrans/bintrans.1 +++ b/usr.bin/bintrans/bintrans.1 @@ -236,6 +236,8 @@ Decode. 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 index 3bff47945acf..862db437f4e0 100644 --- a/usr.bin/bintrans/qp.c +++ b/usr.bin/bintrans/qp.c @@ -51,7 +51,7 @@ decode_char(const char *s) 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 @@ decode_quoted_printable(const char *body, FILE *fpo) 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 @@ decode_quoted_printable(const char *body, FILE *fpo) } 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 @@ encode_quoted_printable(const char *body, FILE *fpo) 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 @@ encode_quoted_printable(const char *body, FILE *fpo) } 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 @@ static void 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 @@ main_quotedprintable(int argc, char *argv[]) { int ch; bool encode = true; + bool rfc2047 = false; FILE *fp = stdin; FILE *fpo = stdout; @@ -167,10 +177,11 @@ main_quotedprintable(int argc, char *argv[]) { { "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 @@ main_quotedprintable(int argc, char *argv[]) case 'd': encode = false; break; + case 'r': + rfc2047 = true; + break; default: usage(); exit(EXIT_FAILURE); @@ -198,7 +212,7 @@ main_quotedprintable(int argc, char *argv[]) exit(EXIT_FAILURE); } } - qp(fp, fpo, encode); + qp(fp, fpo, encode, rfc2047); return (EXIT_SUCCESS); }