support image/x-eps format via pdf_viewer
[claws.git] / src / common / uuencode.c
blob52da6b73f643007877f56353fb8e52bb35ad9c21
1 /*
2 * Claws Mail -- a GTK based, lightweight, and fast e-mail client
3 * Copyright (C) 1999-2024 Hiroyuki Yamamoto and the Claws Mail Team
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 3 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, see <http://www.gnu.org/licenses/>.
19 #include "config.h"
21 #include <ctype.h>
23 #define UUDECODE(c) (c=='`' ? 0 : c - ' ')
24 #define N64(i) (i & ~63)
26 const char uudigit[64] =
28 '`', '!', '"', '#', '$', '%', '&', '\'',
29 '(', ')', '*', '+', ',', '-', '.', '/',
30 '0', '1', '2', '3', '4', '5', '6', '7',
31 '8', '9', ':', ';', '<', '=', '>', '?',
32 '@', 'A', 'B', 'C', 'D', 'E', 'F', 'G',
33 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
34 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
35 'X', 'Y', 'Z', '[', '\\', ']', '^', '_'
38 int fromuutobits(char *out, const char *in)
40 int len, outlen, inlen;
41 register unsigned char digit1, digit2;
43 outlen = UUDECODE(in[0]);
44 in += 1;
45 if(outlen < 0 || outlen > 45)
46 return -2;
47 if(outlen == 0)
48 return 0;
49 inlen = (outlen * 4 + 2) / 3;
50 len = 0;
52 for( ; inlen>0; inlen-=4) {
53 digit1 = UUDECODE(in[0]);
54 if (N64(digit1)) return -1;
55 digit2 = UUDECODE(in[1]);
56 if (N64(digit2)) return -1;
57 out[len++] = (digit1 << 2) | (digit2 >> 4);
58 if (inlen > 2) {
59 digit1 = UUDECODE(in[2]);
60 if (N64(digit1)) return -1;
61 out[len++] = (digit2 << 4) | (digit1 >> 2);
62 if (inlen > 3) {
63 digit2 = UUDECODE(in[3]);
64 if (N64(digit2)) return -1;
65 out[len++] = (digit1 << 6) | digit2;
68 in += 4;
71 return len == outlen ? len : -3;