Example #1
0
uint Command::msn()
{
    Mailbox *m;
    ImapSession *session = imap()->session();
    if ( !session || ( m = session->mailbox() ) == 0 ) {
        error( Bad, "Need mailbox to parse MSN" );
        return 1;
    }

    d->usesMsn = true;

    uint star = session->count();
    uint r = star;
    if ( nextChar() == '*' ) {
        step();
        if ( star == 0 )
            error( Bad, "* is not valid as MSN in an empty mailbox" );
    }
    else {
        r = nzNumber();
    }

    if ( r > star ) {
        respond( "OK MSN " + fn( r ) + " is too large. "
                 "I hope you mean " + fn( star ) +
                 " and will act accordingly." );
        r = star;
    }

    return session->uid( r );
}
Example #2
0
IntegerSet Command::set( bool parseMsns = false )
{
    IntegerSet result;
    ImapSession *s = 0;
    if ( imap() )
        s = imap()->session();

    uint n1 = 0, n2 = 0;
    bool done = false;
    while ( ok() && !done ) {
        char c = nextChar();
        if ( c == '*' ) {
            step();
            n1 = 0;
            if ( s )
                n1 = s->largestUid();
            else
                error( Bad, "Need a mailbox session to use * as an UID/MSN" );
        }
        else if ( c >= '1' && c <= '9' ) {
            if ( parseMsns )
                n1 = msn();
            else
                n1 = nzNumber();
        }
        else {
            error( Bad, "number or '*' expected, saw: " + following() );
        }
        c = nextChar();
        if ( c == ':' ) {
            if ( n2 )
                error( Bad,
                       "saw colon after range (" + fn( n1 ) + ":" +
                       fn( n2 ) + "), saw:" + following() );
            n2 = n1;
            n1 = 0;
            step();
        }
        else if ( ok() ) {
            if ( n2 )
                result.add( n1, n2 );
            else
                result.add( n1 );
            n1 = 0;
            n2 = 0;
            if ( c == ',' )
                step();
            else
                done = true;
        }
    };
    return result;
}
Example #3
0
File: imapurl.cpp Project: aox/aox
bool ImapUrlParser::hostport( EString & host, uint * port )
{
    // We're very laid-back about parsing the "host" production. About
    // the only thing we'll reject is -foo.com, and not doing so would
    // make the loop below twice as simple.

    char c = nextChar();
    while ( ( (c|0x20) >= 'a' && (c|0x20) <= 'z' ) ||
            ( c >= '0' && c <= '9' ) )
    {
        host.append( c );
        step();

        c = nextChar();
        while ( ( (c|0x20) >= 'a' && (c|0x20) <= 'z' ) ||
                ( c >= '0' && c <= '9' ) ||
                ( c == '-' ) )
        {
            host.append( c );
            step();
            c = nextChar();
        }

        if ( c == '.' ) {
            host.append( c );
            step();
            c = nextChar();
        }
    }

    if ( host.isEmpty() )
        return false;

    *port = 143;
    if ( nextChar() == ':' ) {
        step();
        *port = nzNumber();
        if ( !ok() )
            return false;
    }

    return true;
}