示例#1
0
文件: dsn.cpp 项目: copernicus/aox
Address * DSN::sender() const
{
    if ( d->sender )
        return d->sender;
    if ( !d->message || !d->message->header() )
        return 0;
    Header * h = d->message->header();
    List<Address> * a = h->addresses( HeaderField::ReturnPath );
    if ( !a || a->isEmpty() )
        return 0;
    return a->firstElement();
}
示例#2
0
文件: exporter.cpp 项目: aox/aox
void Exporter::execute()
{
    if ( Mailbox::refreshing() ) {
        Database::notifyWhenIdle( this );
        return;
    }

    if ( !d->mailbox && !d->sourceName.isEmpty() ) {
        d->mailbox = Mailbox::find( d->sourceName );
        if ( !d->mailbox ) {
            log( "No such mailbox: " + d->sourceName.utf8(),
                 Log::Disaster );
            return;
        }
    }

    if ( !d->find ) {
        EStringList wanted;
        wanted.append( "message" );
        d->find = d->selector->query( 0, d->mailbox, 0, this,
                                      true, &wanted, false );
        d->find->execute();
    }

    if ( !d->find->done() )
        return;

    if ( !d->fetcher ) {
        d->messages = new List<Message>;
        while ( d->find->hasResults() ) {
            Row * r = d->find->nextRow();
            Message * m = new Message;
            m->setDatabaseId( r->getInt( "message" ) );
            d->messages->append( m );
        }
        d->fetcher = new Fetcher( d->messages, this, 0 );
        d->fetcher->fetch( Fetcher::Addresses );
        d->fetcher->fetch( Fetcher::OtherHeader );
        d->fetcher->fetch( Fetcher::Body );
        d->fetcher->fetch( Fetcher::Trivia );
        d->fetcher->execute();
    }

    while ( !d->messages->isEmpty() ) {
        Message * m = d->messages->firstElement();
        if ( !m->hasAddresses() )
            return;
        if ( !m->hasHeaders() )
            return;
        if ( !m->hasBodies() )
            return;
        if ( !m->hasTrivia() )
            return;
        d->messages->shift();
        EString from = "From ";
        Header * h = m->header();
        List<Address> * rp = 0;
        if ( h ) {
            rp = h->addresses( HeaderField::ReturnPath );
            if ( !rp )
                rp = h->addresses( HeaderField::Sender );
            if ( !rp )
                rp = h->addresses( HeaderField::From );
        }
        if ( rp )
            from.append( rp->firstElement()->lpdomain() );
        else
            from.append( "*****@*****.**" );
        from.append( "  " );
        Date id;
        if ( m->internalDate() )
            id.setUnixTime( m->internalDate() );
        else if ( m->header()->date() )
            id = *m->header()->date();
        // Tue Jul 23 19:39:23 2002
        from.append( weekdays[id.weekday()] );
        from.append( " " );
        from.append( months[id.month()-1] );
        from.append( " " );
        from.appendNumber( id.day() );
        from.append( " " );
        from.appendNumber( id.hour() );
        from.append( ":" );
        if ( id.minute() < 10 )
            from.append( "0" );
        from.appendNumber( id.minute() );
        from.append( ":" );
        if ( id.second() < 10 )
            from.append( "0" );
        from.appendNumber( id.second() );
        from.append( " " );
        from.appendNumber( id.year() );
        from.append( "\r\n" );
        EString rfc822 = m->rfc822( false );
        int r = ::write( 1, from.data(), from.length() ) +
                ::write( 1, rfc822.data(), rfc822.length() );
        // we don't really care whether the write succeeds or not, so
        // just fool the compiler.
        r = r;
    }

    EventLoop::global()->stop();
}