001: /*
002: * LocalMessageBuffer.java
003: *
004: * Copyright (C) 2000-2002 Peter Graves
005: * $Id: LocalMessageBuffer.java,v 1.2 2002/10/11 01:42:37 piso Exp $
006: *
007: * This program is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU General Public License
009: * as published by the Free Software Foundation; either version 2
010: * of the License, or (at your option) any later version.
011: *
012: * This program is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
015: * GNU General Public License for more details.
016: *
017: * You should have received a copy of the GNU General Public License
018: * along with this program; if not, write to the Free Software
019: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
020: */
021:
022: package org.armedbear.j.mail;
023:
024: import org.armedbear.j.Editor;
025:
026: /*package*/final class LocalMessageBuffer extends MessageBuffer {
027: /*package*/LocalMessageBuffer(LocalMailbox mailbox,
028: MailboxEntry entry) {
029: super ();
030: this .mailbox = mailbox;
031: showFullHeaders = mailbox.showFullHeaders;
032: showRawText = mailbox.showRawText;
033: setEntry(entry);
034: initializeUndo();
035: type = TYPE_NORMAL;
036: lineSeparator = "\n";
037: mode = MessageMode.getMode();
038: formatter = mode.getFormatter(this );
039: readOnly = true;
040: }
041:
042: public int load() {
043: if (mailbox.lock()) {
044: try {
045: loadMessage(null);
046: setLoaded(true);
047: return LOAD_COMPLETED;
048: } finally {
049: mailbox.unlock();
050: }
051: } else
052: Editor.currentEditor().status("Mailbox is locked");
053: return LOAD_FAILED;
054: }
055:
056: public void deleteMessage() {
057: if (mailbox.lock()) {
058: try {
059: if (!entry.isDeleted()) {
060: entry.setFlags(entry.getFlags()
061: | MailboxEntry.DELETED);
062: mailbox.setDirty(true);
063: mailbox.updateEntry(entry);
064: }
065: MailboxEntry nextEntry = mailbox
066: .getNextUndeleted(entry);
067: if (nextEntry != null) {
068: setEntry(nextEntry);
069: loadMessage(null);
070: } else {
071: Editor editor = Editor.currentEditor();
072: MailCommands.messageIndex(editor);
073: editor.status("Last undeleted message");
074: }
075: } finally {
076: mailbox.unlock();
077: }
078: }
079: }
080:
081: public void flagMessage() {
082: if (mailbox.lock()) {
083: try {
084: if (entry.isFlagged())
085: entry.unflag();
086: else
087: entry.flag();
088: mailbox.setDirty(true);
089: mailbox.updateEntry(entry);
090: MailboxEntry nextEntry = mailbox
091: .getNextUndeleted(entry);
092: if (nextEntry != null) {
093: setEntry(nextEntry);
094: loadMessage(null);
095: } else {
096: Editor editor = Editor.currentEditor();
097: MailCommands.messageIndex(editor);
098: editor.status("Last undeleted message");
099: }
100: } finally {
101: mailbox.unlock();
102: }
103: }
104: }
105: }
|