Package com.ettrema.http.caldav.demo

Source Code of com.ettrema.http.caldav.demo.TMailFolder

package com.ettrema.http.caldav.demo;

import com.bradmcevoy.http.Resource;
import com.ettrema.mail.MessageFolder;
import com.ettrema.mail.MessageResource;
import com.ettrema.mail.StandardMessageFactoryImpl;
import com.ettrema.mail.StandardMessageImpl;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import javax.mail.internet.MimeMessage;

/**
*
* @author brad
*/
public class TMailFolder extends TFolderResource implements MessageFolder {

    private int nextMsgId = 1000;

    public TMailFolder(TFolderResource parent, String name) {
        super(parent, name);
    }

    public Collection<MessageResource> getMessages() {
        List<MessageResource> list = new ArrayList<MessageResource>();
        for( Resource r : this.children ) {
            if( r instanceof MessageResource) {
                list.add((MessageResource) r);
            }
        }
        return list;
    }

    public int numMessages() {
        return getMessages().size();
    }

    public int totalSize() {
        int size = 0;
        for( Resource r : this.children ) {
            if( r instanceof MessageResource) {
                MessageResource mr = (MessageResource) r;
                size += mr.getSize();
            }
        }
        return size;

    }

    public void storeMail(MimeMessage mm) {
        StandardMessageFactoryImpl factoryImpl = new StandardMessageFactoryImpl();
        StandardMessageImpl sm = new StandardMessageImpl();
        factoryImpl.toStandardMessage(mm, sm);
        TMessageResource mr = new TMessageResource(this,"msg-" + nextMsgId++, sm);
        System.out.println("stored message in: " + mr.getName());
    }

}
TOP

Related Classes of com.ettrema.http.caldav.demo.TMailFolder

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.