1   
2   
3   
4   
5   
6   
7   
8   
9   
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  package de.saly.javamail.mock2;
27  
28  import java.util.ArrayList;
29  import java.util.List;
30  
31  import javax.mail.Folder;
32  import javax.mail.MessagingException;
33  
34  import com.sun.mail.imap.DefaultFolder;
35  
36  public class IMAPDefaultMockFolder extends DefaultFolder {
37  
38      protected final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(this.getClass());
39      private final MockMailbox mailbox;
40      
41      private final IMAPMockStore store;
42  
43      protected IMAPDefaultMockFolder(final IMAPMockStore store, final MockMailbox mailbox) {
44          super(store);
45          
46          this.mailbox = mailbox;
47          this.store = store;
48          logger.debug("Created");
49      }
50  
51      @Override
52      public synchronized boolean create(final int type) throws MessagingException {
53          return true;
54      }
55  
56      @Override
57      public synchronized boolean exists() throws MessagingException {
58          return true;
59      }
60  
61      @Override
62      public Folder getFolder(final String name) throws MessagingException {
63  
64          logger.debug("getFolder(" + name + ") on " + getFullName());
65  
66          if ("inbox".equalsIgnoreCase(name)) {
67              return new IMAPMockFolder(store, mailbox.getInbox());
68          }
69  
70          return new IMAPMockFolder(store, mailbox.getRoot().getOrAddSubFolder(name));
71  
72      }
73  
74      @Override
75      public int getType() throws MessagingException {
76          checkExists();
77          return HOLDS_FOLDERS;
78      }
79  
80      @Override
81      public Folder[] list(final String pattern) throws MessagingException {
82  
83          final List<MailboxFolder> children = mailbox.getRoot().getChildren();
84          final List<Folder> ret = new ArrayList<Folder>();
85  
86          for (final MailboxFolder mf : children) {
87              if (mf.isExists()) {
88                  ret.add(new IMAPMockFolder(store, mf));
89              }
90          }
91  
92          logger.debug("Folder (Defaultroot) list return " + ret);
93  
94          return ret.toArray(new Folder[ret.size()]);
95  
96      }
97  
98      @Override
99      public synchronized Folder[] listSubscribed(final String pattern) throws MessagingException {
100         return new Folder[0];
101     }
102 
103 }