2 * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3 * Copyright (C) 1999-2002 Hiroyuki Yamamoto
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 static gboolean get_hex_value(guchar *out, gchar c1, gchar c2);
24 static void get_hex_str(gchar *out, guchar ch);
26 gint qp_decode_line(gchar *str)
28 gchar *inp = str, *outp = str;
30 while (*inp != '\0') {
32 if (inp[1] && inp[2] &&
33 get_hex_value(outp, inp[1], inp[2]) == TRUE) {
35 } else if (inp[1] == '\0' || isspace(inp[1])) {
39 /* broken QP string */
53 gint qp_decode_q_encoding(guchar *out, const gchar *in, gint inlen)
55 const gchar *inp = in;
61 while (inp - in < inlen && *inp != '\0') {
62 if (*inp == '=' && inp + 3 - in <= inlen) {
63 if (get_hex_value(outp, inp[1], inp[2]) == TRUE) {
68 } else if (*inp == '_') {
82 gint qp_get_q_encoding_len(const guchar *str)
84 const guchar *inp = str;
87 while (*inp != '\0') {
90 else if (*inp == '=' || *inp == '?' || *inp == '_' ||
91 *inp < 32 || *inp > 127 || isspace(*inp))
102 void qp_q_encode(gchar *out, const guchar *in)
104 const guchar *inp = in;
107 while (*inp != '\0') {
110 else if (*inp == '=' || *inp == '?' || *inp == '_' ||
111 *inp < 32 || *inp > 127 || isspace(*inp)) {
113 get_hex_str(outp, *inp);
124 #define HEX_TO_INT(val, hex) \
128 if ('0' <= c && c <= '9') { \
130 } else if ('a' <= c && c <= 'f') { \
131 val = c - 'a' + 10; \
132 } else if ('A' <= c && c <= 'F') { \
133 val = c - 'A' + 10; \
139 static gboolean get_hex_value(guchar *out, gchar c1, gchar c2)
146 if (hi == -1 || lo == -1)
149 *out = (hi << 4) + lo;
153 #define INT_TO_HEX(hex, val) \
158 hex = 'A' + (val) - 10; \
161 static void get_hex_str(gchar *out, guchar ch)
165 INT_TO_HEX(hex, ch >> 4);
167 INT_TO_HEX(hex, ch & 0x0f);