Back to index

webcit  8.12-dfsg
Functions
decode.c File Reference
#include "webcit.h"

Go to the source code of this file.

Functions

void utf8ify_rfc822_string (char **a)
int webcit_rfc2047encode (char *target, int maxlen, char *source, long SourceLen)
 RFC2047-encode a header field if necessary.

Function Documentation

void utf8ify_rfc822_string ( char **  a) [inline]

Definition at line 250 of file decode.c.

{};

Here is the caller graph for this function:

int webcit_rfc2047encode ( char *  target,
int  maxlen,
char *  source,
long  SourceLen 
)

RFC2047-encode a header field if necessary.

         If no non-ASCII characters are found, the string
         will be copied verbatim without encoding.
Parameters:
targetTarget buffer.
maxlenMaximum size of target buffer.
sourceSource string to be encoded.
SourceLenLength of the source string
Returns:
encoded length; -1 if non success.

Definition at line 268 of file decode.c.

{
       const char headerStr[] = "=?UTF-8?Q?";
       int need_to_encode = 0;
       int i = 0;
       int len;
       unsigned char ch;

       if ((source == NULL) || 
           (target == NULL) ||
           (SourceLen > maxlen)) return -1;

       while ((!IsEmptyStr (&source[i])) && 
              (need_to_encode == 0) &&
              (i < SourceLen) ) {
              if (((unsigned char) source[i] < 32) || 
                  ((unsigned char) source[i] > 126)) {
                     need_to_encode = 1;
              }
              i++;
       }

       if (!need_to_encode) {
              memcpy (target, source, SourceLen);
              target[SourceLen] = '\0';
              return SourceLen;
       }
       
       if (sizeof (headerStr + SourceLen + 2) > maxlen)
              return -1;
       memcpy (target, headerStr, sizeof (headerStr));
       len = sizeof (headerStr) - 1;
       for (i=0; (i < SourceLen) && (len + 3< maxlen) ; ++i) {
              ch = (unsigned char) source[i];
              if ((ch < 32) || (ch > 126) || (ch == 61)) {
                     sprintf(&target[len], "=%02X", ch);
                     len += 3;
              }
              else {
                     sprintf(&target[len], "%c", ch);
                     len ++;
              }
       }
       
       if (len + 2 < maxlen) {
              strcat(&target[len], "?=");
              len +=2;
              return len;
       }
       else
              return -1;
}