KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > armedbear > j > mail > LocalMessageBuffer


1 /*
2  * LocalMessageBuffer.java
3  *
4  * Copyright (C) 2000-2002 Peter Graves
5  * $Id: LocalMessageBuffer.java,v 1.2 2002/10/11 01:42:37 piso Exp $
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20  */

21
22 package org.armedbear.j.mail;
23
24 import org.armedbear.j.Editor;
25
26 /*package*/ final class LocalMessageBuffer extends MessageBuffer
27 {
28     /*package*/ LocalMessageBuffer(LocalMailbox mailbox, MailboxEntry entry)
29     {
30         super();
31         this.mailbox = mailbox;
32         showFullHeaders = mailbox.showFullHeaders;
33         showRawText = mailbox.showRawText;
34         setEntry(entry);
35         initializeUndo();
36         type = TYPE_NORMAL;
37         lineSeparator = "\n";
38         mode = MessageMode.getMode();
39         formatter = mode.getFormatter(this);
40         readOnly = true;
41     }
42
43     public int load()
44     {
45         if (mailbox.lock()) {
46             try {
47                 loadMessage(null);
48                 setLoaded(true);
49                 return LOAD_COMPLETED;
50             }
51             finally {
52                 mailbox.unlock();
53             }
54         } else
55             Editor.currentEditor().status("Mailbox is locked");
56         return LOAD_FAILED;
57     }
58
59     public void deleteMessage()
60     {
61         if (mailbox.lock()) {
62             try {
63                 if (!entry.isDeleted()) {
64                     entry.setFlags(entry.getFlags() | MailboxEntry.DELETED);
65                     mailbox.setDirty(true);
66                     mailbox.updateEntry(entry);
67                 }
68                 MailboxEntry nextEntry = mailbox.getNextUndeleted(entry);
69                 if (nextEntry != null) {
70                     setEntry(nextEntry);
71                     loadMessage(null);
72                 } else {
73                     Editor editor = Editor.currentEditor();
74                     MailCommands.messageIndex(editor);
75                     editor.status("Last undeleted message");
76                 }
77             }
78             finally {
79                 mailbox.unlock();
80             }
81         }
82     }
83
84     public void flagMessage()
85     {
86         if (mailbox.lock()) {
87             try {
88                 if (entry.isFlagged())
89                     entry.unflag();
90                 else
91                     entry.flag();
92                 mailbox.setDirty(true);
93                 mailbox.updateEntry(entry);
94                 MailboxEntry nextEntry = mailbox.getNextUndeleted(entry);
95                 if (nextEntry != null) {
96                     setEntry(nextEntry);
97                     loadMessage(null);
98                 } else {
99                     Editor editor = Editor.currentEditor();
100                     MailCommands.messageIndex(editor);
101                     editor.status("Last undeleted message");
102                 }
103             }
104             finally {
105                 mailbox.unlock();
106             }
107         }
108     }
109 }
110
Popular Tags