⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 thebox.java

📁 手机邮箱撒的方式方式方式的
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
     * @param index of the message to be retrieved
     * @return message for requested index or null if there is not message with such index
     */
    public MessageHeader getMessageHeaderAt(int index) {
        return storage.getMessageAt( index );
    }

    public MessageHeader getSelectedHeader() {
//        return storageAt(getSelectedIndex());
        return getMessageHeaderAt( getSelectedIndex() );
    }

    /**
     * Indicates whether there proceeds some action beyond the mails in this
     * box.
     * @return true if there proceeds some action beyond the mails int this
     * box
     * 
     * TODO: this is now used only for canceling ticker. Refactor!
     */
    protected boolean isBusy() {
        return false;
    }
    
    /**
     * Displays report message which has originated because of some exception.
     * 
     * @param report message which to display. If it ends with '+' it will
     *  be just printed to the standard output, if it ends with '*', the focus
     *  will be returned back after displaying the message.
     * @param sourceFile the source file where the message which is reported
     *  was originated
     * @param ex the exception because of the message is reported
     */
    public void report(String report, String sourceFile, Exception ex) {
        if (DEBUG) {
            ex.printStackTrace();
        }
        
        report(report, sourceFile);
    }
    
    /**
     * Stores mail to this box. 
     * If this box is persistent, makes the copy of given mail and stores it to
     * the RMS database and container of this box.
     * If this box is not persistent, stores the mail only to the container of
     * this box and does not make a copy.
     * @param header the mail to be stored
     * @return the mail that was stored (in case of persistent box, this is the
     *  copy of mail in parameter)
     */
    public abstract MessageHeader storeMail(MessageHeader header);

    /**
     * Displays report message.
     * 
     * @param report message which to display. If it ends with '+' it will
     *  be just printed to the standard output, if it ends with '*', the focus
     *  will be returned back after displaying the message.
     * @param sourceFile the source file where the message which is reported
     *  was originated
     */
    public synchronized void report(String report, String sourceFile) {
          if (DEBUG) System.out.println("DEBUG " + sourceFile + " - " + report);
        //return;
        if (report.startsWith("+")) //not important messages
        {
            return;
        }
        Displayable display;
        activity = report;

        if (report.endsWith("*")) //then we need to get back the focus afted displaying an alert
        {
            display = this;
        } else {
            display = null;
        }

        if (report.startsWith("100:")) {
            getMujMail().alert.setAlert(this, display, report.substring(4), MyAlert.DEFAULT, AlertType.ERROR);
        } else if (report.startsWith("200:")) {
            getMujMail().alert.setAlert(this, display, report.substring(4), MyAlert.DEFAULT, AlertType.WARNING);
        } else if (report.startsWith("300:")) {
            getMujMail().alert.setAlert(this, display, report.substring(4), MyAlert.DEFAULT, AlertType.INFO);
        }

        repaint();

        if (report.startsWith("*")) { //important message
            Functions.sleep(1500);
        }
    }

    /**
     * Set the information that will be displayed on the progress bar.
     * Note, that progress bar will be displayed only if isBusy() returns true.
     *
     * TODO: replace by tasks
     * 
     * @param activity the message displayed on the progress bar
     *  if it starts with *, this thread will be 500 milliseconds sleep
     * @param max the number of time units when the activity will be finished
     * @param actual actual number of time units
     */
    private synchronized void setProgress(String activity, int max, int actual) {
        this.activity = activity;
        repaint();

        if (activity.startsWith("*")) {
            Functions.sleep(500);
        }
    }

    public void markAsDeleted(MessageHeader message) {
        if (message != null) {
            if (message.deleted) //was it marked as deleted?
            {
                --deleted;
            } //decrease the counter for marked mails
            else {
                ++deleted;
            }
            message.deleted = !message.deleted; //change its state

            /*
            MailAccount msgAcct = (MailAccount)this.getMujMail().mailAccounts.get(message.accountID);
            
            //Set '\Deleted' flag on server if it's an IMAP account
            if (msgAcct.type == MailAccount.IMAP)
            {
            	msgAcct.protocol.setFlags(message, "(\\Deleted)");
            }
            */

            shiftSelectedIndex(true);

            repaint();
        }
    }

    /**
     * Marks a given message as Seen/Unseen depending on the current flag.
     * In case the message's account is of type IMAP4, command to update
     * IMAP server is send too.
     * @param message		Message to mark as Seen/Unseen
     */
    public void markSeen(MessageHeader message) {
        MailAccount msgAcct = (MailAccount)this.getMujMail().getMailAccounts().get(message.getAccountID());

    	if (message.readStatus == MessageHeader.READ)
    	{
    		message.readStatus = MessageHeader.NOT_READ;
            //Unset '\Seen' flag on server if it's an IMAP account
            if (msgAcct != null && msgAcct.isIMAP())
            {
            	msgAcct.getProtocol().setFlags(message, "(\\Seen)", InProtocol.REMOVE_FLAGS, this);
            }    	
    	}
    	else
    	{
    		message.readStatus = MessageHeader.READ;
            //Set '\Seen' flag on server if it's an IMAP account
            if (msgAcct != null && msgAcct.isIMAP())
            {
            	msgAcct.getProtocol().setFlags(message, "(\\Seen)", InProtocol.SET_FLAGS, this);
            }    	
    	}
    	
    	try {
            // msgAcct.getProtocol().getBox().mailDB.saveHeader(message); // Alf: Why so complicated??
            message.getBox().getMailDB().saveHeader(message);
        } catch (MyException e) {
            MujMail.mujmail.alert.setAlert("Error saving message header", AlertType.ERROR);
        }
        
        repaint();
    }

    /**
     * Marks a given message as Seen/Unseen depending on the current flag.
     * In case the message's account is of type IMAP4, command to update
     * IMAP server is send too.
     * @param message		Message to mark as Seen/Unseen
     */
    public void markFlagged(MessageHeader message) {
        MailAccount msgAcct = (MailAccount)this.getMujMail().getMailAccounts().get(message.getAccountID());
    	if (message.flagged)
    	{
    		message.flagged = false;
            //Unset '\Flagged' flag on server if it's an IMAP account
            if (msgAcct != null && msgAcct.isIMAP())
            {
            	msgAcct.getProtocol().setFlags(message, "(\\Flagged)", InProtocol.REMOVE_FLAGS, this);
            }
    	}
    	else
    	{
    		message.flagged = true;
            //Set '\Flagged' flag on server if it's an IMAP account
            if (msgAcct != null && msgAcct.isIMAP())
            {
            	msgAcct.getProtocol().setFlags(message, "(\\Flagged)", InProtocol.SET_FLAGS, this);
            }
    	}

    	try {
            //  msgAcct.getProtocol().getBox().mailDB.saveHeader(message);
            message.getBox().getMailDB().saveHeader(message);
    	} catch (MyException e) {
            MujMail.mujmail.alert.setAlert("Error saving message header", AlertType.ERROR);
    	}
    	
    	repaint();
    }

    /**
     * Do the work of deleting all mails from database. Called by 
     * deleteAllMailsFromBoxAndDB(boolean).
     * If the box is Persistent, should delete all mails from database of this
     * persistent box.
     * If the box is Unpersistent, should delete also messages from containers
     * of boxes to which stored mails belong.
     */
    protected abstract void deleteAllMailsFromDB();
    
    public void exit() {
        getMujMail().mainMenu();
    }
    
    /**
     * Returns true if this box is empty.
     * @return true if this box is empty.
     */
    public boolean isEmpty() {
        return storage.isEmpty();
    }
    
    /**
     * Deletes all mails in this storage from this storage and from database.
     * Note that this storage does not store any mails so the mails will be
     * deleted from databases of other boxes.
     * 
     * @param sure if it is true, deletes mails in spite of the box is busy and
     *  don't ask user.
     */
    public void deleteAllMailsFromBoxAndDB(boolean sure) {
        if (!sure) {
            if (isBusy()) {
                getMujMail().alert.setAlert(this, this, Lang.get(Lang.ALRT_SYS_BUSY), MyAlert.DEFAULT, AlertType.INFO);
            } else {
                getMujMail().alert.setAlert(this, this, Lang.get(Lang.ALRT_SYS_DEL_ALL_CONFIRM), MyAlert.DB_CLEAR_CONFIRM, AlertType.CONFIRMATION);
            }
            return;
        }
        
        deleteAllMailsFromDB();
        
        synchronized (storage) {
            storage.removeAllMessages();
        }
        
        deleted = 0;
        cur = 0;
        repaint();
    }
    
    /**
     * Immediately deletes given message.
     * @param message the message to be deleted
     * @param  trashMode describes the storing of deleted mail to trash
     */
    public void deleteNowFromBoxAndDB(MessageHeader message, 
            Trash.TrashModes trashMode) {
        message.deleteFromDBAndBox(this, trashMode);
        cur = 0;
        repaint();
    }
    
    /**
     * Do the physical work of deleting marked mails from box and database.
     * Called by deleteMarkedFromBoxAndDB().
     */
    protected abstract void doDeleteMarkedFromBoxAndDB();

    /**
     * Do batch deleteFromDBAndBox of all messages marked as deleted.
     */
    public void deleteMarkedFromBoxAndDB() {
        if (deleted > 0) {
            cancelTicker();
            doDeleteMarkedFromBoxAndDB();
            cur = 0;
            
            repaint();
        }
    }

    protected void cancelTicker() {
        if (tickerTimer != null) {
            tickerTimer.cancel();
            tickerTimer = null;
            tIndex = 0;
            tStarted = false;
        }
    }
    
    /** Shows Box on foreground of display */
    void showBox() {
        mujMail.getDisplay().setCurrent(this);
    }

    /**
     * Cancels ticker and disables running of ticker.
     */
    public void disableTicker() {
        cancelTicker();
        tickerEnabled = false;
    }
    
    /**
     * Enables running of ticker.
     */
    public void enableTicker() {
        tickerEnabled = true;
    }

    public int getSelectedIndex() {
        cancelTicker();
        return cur;
    }

    /**
     * Moves the current index (depends on direction) and returns new current
     * index. It works as cyclic list (from last item it's moved to the first).
     * 
     * @param cur current position
     * @param direction where to move, <code>true</code> moves down (+1)
     * @return new index to current item
     */
    private int moveCurrent( final int cur, final boolean direction ) {
          if (DEBUG) System.out.println( "DEBUG TheBox.moveCurrent(cur=" + cur + ", direction=" + direction + ")" );

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -