1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
4 * Ceph - scalable distributed file system
6 * Copyright (C) 2011 New Dream Network
8 * This is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License version 2.1, as published by the Free Software
11 * Foundation. See file COPYING.
14 #include "common/utf8.h"
19 int mime_encode_as_qp(const char *input, char *output, int outlen)
23 const unsigned char *i = (const unsigned char*)input;
29 else if ((c & 0x80) || (c == '=') || (is_control_character(c))) {
31 snprintf(o, outlen, "=%02X", c);
41 snprintf(o, outlen, "%c", c);
52 static inline signed int hexchar_to_int(unsigned int c)
99 int mime_decode_from_qp(const char *input, char *output, int outlen)
103 const unsigned char *i = (const unsigned char*)input;
110 /* The high bit is never set in quoted-printable encoding! */
114 int high = hexchar_to_int(*++i);
117 int low = hexchar_to_int(*++i);
120 c = (high << 4) + low;
125 snprintf(o, outlen, "%c", c);