Пример #1
0
 static QByteArray formatSubject( QString s ) {
   if ( isUsAscii( s ) )
     return s.remove( QLatin1Char('\n') ).toLatin1(); // don't break header folding,
                                         // so remove any line break
                                         // that happen to be around
   else
     return rfc2047Encode( s );
 }
Пример #2
0
  static QByteArray formatFromAddress( const QString & fromRealName, const QString & fromAddress ) {
    if ( fromRealName.isEmpty() )
      return fromAddress.toLatin1(); // no real name: return "*****@*****.**"

    // return "Joe User <*****@*****.**>", "\"User, Joe\" <*****@*****.**>"
    // or "=?utf-8?q?Joe_User?= <*****@*****.**>", depending on real name's nature.
    QByteArray r = isUsAscii( fromRealName ) ? quote( fromRealName ) : rfc2047Encode( fromRealName );
    return r + " <" + fromAddress.toLatin1() + '>';
  }
Пример #3
0
static string hdr_MakeEmail( const char * cprefix, Pair a )
{
    string buf = snew();
    if( !buf ) return NULL;

    if( A_NAME( a ) )
    {
        if( isUsAscii( A_NAME( a ) ) )
        {
            if( !sprint( buf, "%s <%s>", A_NAME( a ), A_EMAIL( a ) ) )
            {
                sdel( buf );
                return NULL;
            }
        }
        else
        {
            string b64 = hdr_Encodeb64( cprefix, A_NAME( a ) );
            if( !b64 )
            {
                sdel( buf );
                return NULL;
            }
            if( !sprint( buf, "%s <%s>", sstr( b64 ), A_EMAIL( a ) ) )
            {
                sdel( buf );
                sdel( b64 );
                return NULL;
            }
            sdel( b64 );
        }
    }
    else
    {
        if( !scatc( buf, A_EMAIL( a ) ) )
        {
            sdel( buf );
            return 0;
        }
    }
    return buf;
}
Пример #4
0
static int hdr_MakeTextHeader( msg_Header header, const char * cprefix,
        string out )
{
    char * value;
    string rc = snew();
    if( !rc ) return 0;

    value = slfirst( header->values );
    while( value )
    {
        if( isUsAscii( value ) )
        {
            if( !xscatc( rc, header->name, ": ", value, "\r\n", NULL ) )
            {
                sdel( rc );
                return 0;
            }
        }
        else
        {
            string b64 = hdr_Encodeb64( cprefix, value );
            if( !b64 ) return 0;
            if( !xscatc( rc, header->name, ": ", sstr( b64 ), "\r\n", NULL ) )
            {
                sdel( b64 );
                sdel( rc );
                return 0;
            }
            sdel( b64 );
        }
        value = slnext( header->values );
    }
    if( !scat( out, rc ) )
    {
        sdel( rc );
        return 0;
    }
    sdel( rc );
    return 1;
}
Пример #5
0
  static QByteArray quote( const QString & s ) {
    assert( isUsAscii( s ) );

    QByteArray r( s.length() * 2, 0 );
    bool needsQuotes = false;

    unsigned int j = 0;
    for ( int i = 0 ; i < s.length() ; ++i ) {
      char ch = s[i].toLatin1();
      if ( isSpecial( ch ) ) {
        if ( needsQuoting( ch ) )
          r[j++] = '\\';
        needsQuotes = true;
      }
      r[j++] = ch;
    }
    r.truncate( j );

    if ( needsQuotes )
      return '"' + r + '"';
    else
      return r;
  }