> email | readable | mime <
// Quoted-Printable encoding for email with special characters and readability
Human Readable
ASCII text remains readable while special characters are safely encoded.
Email Standard
MIME standard for encoding email messages with international characters.
Unicode Support
Handles any Unicode character while maintaining compatibility with email systems.
>> technical info
How Quoted-Printable Works:
Quoted-Printable encodes 8-bit data using printable ASCII characters. Non-ASCII bytes are represented as '=' followed by two hex digits. Lines are limited to 76 characters with soft line breaks.
Example:
"Café" → Caf=C3=A9
Why Use Quoted-Printable:
- >Preserves text readability
- >MIME email standard
- >Handles international characters
- >Minimal expansion for ASCII text
- >Line length compliance
>> frequently asked questions
What is Quoted-Printable encoding?
Quoted-Printable is a MIME content transfer encoding that allows 8-bit data to be transmitted over 7-bit email systems while keeping ASCII text human-readable.
When should I use Quoted-Printable?
Use Quoted-Printable for email messages containing mostly ASCII text with occasional special characters or international text. It's ideal when readability is important.
How does it differ from Base64?
Unlike Base64 which makes all content unreadable, Quoted-Printable keeps ASCII text readable and only encodes special characters, making it better for text-heavy content.
What does the '=' character mean?
The '=' character is an escape character in Quoted-Printable. It's followed by two hex digits to represent a byte, or used at line ends for soft line breaks.
Quoted-Printable(QP 符号化)とは?日本語メールで使われる?
Quoted-Printable(QP エンコーディング、Content-Transfer-Encoding: quoted-printable)は MIME 標準(RFC 2045)で定義されたメール用テキスト符号化方式。基本的な ASCII 文字(A-Z、a-z、0-9、基本記号)はそのまま残し、非 ASCII や = 自身を =XX(XX は 16 進バイト)でエスケープする。
日本語メールでの扱い:
• UTF-8 日本語 + QP: こんにちは の UTF-8 バイト列 0xE3 0x81 0x93 0xE3 0x82 0x93 0xE3 0x81 0xAB 0xE3 0x81 0xA1 0xE3 0x81 0xAF → =E3=81=93=E3=82=93=E3=81=AB=E3=81=A1=E3=81=AF。
• ISO-2022-JP + QP: 日本語メールの古典的組み合わせ。ただし ISO-2022-JP は既に 7bit クリーンなのでたいてい Content-Transfer-Encoding: 7bit で送られ、QP は不要。
• Base64 vs QP: 日本語は ASCII 率が低いため、QP だと各バイトに 3 倍のオーバーヘッド(=XX)がかかって肥大化する。Gmail や最近の MUA は日本語本文には Base64 を選ぶことが多い。
使いどころ: 本文の大半が ASCII で、たまに特殊文字(™、€、é 等)が混ざる場合。ASCII 部分がそのまま読めるため、メールのデバッグが容易。
Quoted-Printable エンコーダー / デコーダーの実装例
各言語の標準ライブラリで対応:
Python: import quopri; quopri.encodestring(b'Caf\xc3\xa9') → b'Caf=C3=A9'。デコード: quopri.decodestring(s)。
Node.js: 標準ライブラリなし。npm i quoted-printable → require('quoted-printable').encode('Café')。
PHP: quoted_printable_encode('Café') / quoted_printable_decode(s)(ビルトイン)。
Java: org.apache.commons.codec.net.QuotedPrintableCodec(Apache Commons Codec)。
Ruby: [str].pack('M') / str.unpack('M').first。
QP の詳細ルール:
• ASCII 印字可能文字(0x21-0x7E)の中で = を除く部分はそのまま。
• = 自身は =3D にエスケープ。
• 行末の空白(space/tab)は =20 / =09 に(行末空白は MTA に削除される可能性があるため)。
• 行は 76 文字以内(RFC 2045)。超える場合は行末に ソフト改行 = + CRLF を挿入。
• 8bit バイトは =XX で 16 進エスケープ(大文字推奨)。
Quoted-Printable vs Base64 — どちらを選ぶべきか?
MIME では本文のバイナリ度合いによって選択:
| 観点 | Quoted-Printable | Base64 |
|---|---|---|
| ASCII 率 | 高い (80%+) に最適 | 低い / バイナリに最適 |
| 可読性 | 元テキストが残る | 全く読めない |
| オーバーヘッド | 純 ASCII: 0%、UTF-8 日本語: 200% | 常に ~33% |
| デバッグ容易性 | ◎ less で読める | × 要復号 |
| 添付ファイル | × 非効率 | ◎ 標準 |
判断基準:
• 英語メール本文 + 少量の特殊文字 → QP(ほぼオーバーヘッドなし)
• 日本語 / 中国語 / 韓国語本文 → Base64(QP だとサイズが 3 倍に膨らむ)
• 画像・PDF・ZIP 添付 → Base64(常に)
• プレーンテキスト 100% ASCII →
7bit(符号化不要)