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

📄 inbox.java

📁 手机邮箱撒的方式方式方式的
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
        }
        if (isBusy()) {
            removeCommand(retrieve);
        } else {
            if ( storage.getSize() == 0 ) { // if storage is empty
                addCommand(retrieve);
            }
            removeCommand(stop);
        }
        if (!btnsHidden) {
            removeCommand(redownload);
        }
        super.hideButtons();
    }

    protected void showButtons() {
        if (btnsHidden) {
            addCommand(retrieve);
            addCommand(redownload);
            removeCommand(stop);
            super.showButtons();
        }
    }

    protected void keyPressed(int keyCode) {
        if (isBusy()) {
            return;
        }
        final MessageHeader messageHeader = getMessageHeaderAt( getSelectedIndex() );
        if (keyCode == '3' && messageHeader != null) {	//key 3 changes readStatus of a mail		
            MessageHeader header = messageHeader;
            header.readStatus = (byte) (1 - header.readStatus);
            shiftSelectedIndex( true );
            if (header.readStatus == MessageHeader.READ) {
                getMujMail().getInBox().changeUnreadMails(-1);
            } else {
                getMujMail().getInBox().changeUnreadMails(1);
            }
            repaint();
            try {
                getMailDB().saveHeader(header); //dont forget to write it to the DB						
            } catch (MyException ex) {
                report(ex.getDetails(), SOURCE_FILE);
            }
        }
        else {
        	super.keyPressed(keyCode);
        }
    }

    /**
     * Moves the cursor on the first unread mail.
     */
    public void setCurFirstUnread() {
        if (unreadMails != 0) {
            Enumeration messages = storage.getEnumeration();
            MessageHeader message;
            cur = 0;
            empties = 0;
            while ( messages.hasMoreElements() ) {
                message = (MessageHeader)messages.nextElement();
                if ( message.readStatus == MessageHeader.NOT_READ) {
                    break;
                }
                shiftSelectedIndex(true);
            }
        }
    }

    public void stop() {
        removeCommand(stop);
        for (Enumeration e = getMujMail().getMailAccounts().elements(); e.hasMoreElements();) {
            MailAccount account = (MailAccount) e.nextElement();
            if (account.isActive()) {
                account.getProtocol().stop();
            }
        }
    }

    public MessageHeader storeMail(MessageHeader header) {
        header = super.storeMail(header);
        if (header != null && header.readStatus == MessageHeader.NOT_READ) {
            ++unreadMails;
            msgIDs.put(header.getAccountID() + "@" + header.getMessageID(), header);
        }
        return header;
    }
    
    /**
     * Returns true if there is some account with push active. That means that
     * IMAP command idle was executed and it is waiting for new mails.
     * 
     * @return true if there is some account with push active.
     */
    public boolean isPushActive() {
        return pushActive;
    }
    
    /*
     * Push mail: Push mail or IDLE capability is an possible IMAP capability (RFC 2177) but must not be implemented in each server. 
     * We start a new thread and new IMAP session for each active account if "Push mail" is activate in the settings --> TODO!
     * At first we have to proof the IDLE capability for each IMAP server (TODO: not implemented yet). It can be done in two ways:
     *      1) execute "CAPABILITY" command and look for "IDLE" --> BUT: some servers "hide" the IDLE capability
     *      2) choose the box and execute "IDLE", then look for response
     * The second way is the better one, because of servers that hide their IDLE capability.
     */
    public synchronized void push(){
        if(!pushActive){
            if (!hasAccountToRetrieve()) {                
                getMujMail().alert.setAlert(this, null, Lang.get(Lang.ALRT_AS_NO_ACCOUNT_SET_ACTIVE), MyAlert.DEFAULT, AlertType.WARNING);
            } else {
                //TODO Proof IMAP capability here? 
                pushActive = true;
                for (Enumeration e = getMujMail().getMailAccounts().elements(); e.hasMoreElements();) {
                    MailAccount pushAccount = (MailAccount) e.nextElement();
                    
                    if (pushAccount.isActive() && pushAccount.getProtocol().isImap()) {                        
                        pushAccount.prepareForPushing(this);                        
                        Pushing push = new Pushing(pushAccount);                 
                        push.start();
                        
                    }
                }
            }
        } else {
            pushActive = false;
        }
    
    }
    
    /**
     * Stops pushing new mails in all accounts.
     */
    public synchronized void stopPush() {
        pushActive = false;
    }
    
    /**
     * Called from MailDB after loading db (loadDB) is done
     * Note: Overwrites generic body
     */
    public void loadedDB() {
        initHash(); //init the map of the mails in the Inbox
        resort(); //its needed to resort the box according to the settings
    }

    public void commandAction(Command c, Displayable d) {
        super.commandAction(c, d);

        if (c == retrieve) {
            retrieve();
        } else if (c == redownload) {
            regetBody( getSelectedHeader(), (byte) -1); //redownloading completed mail
        } else if (c == stop) {
            stop();
        }
    }

    /* ***************************
     *    getters and setters    *
     *****************************/
    public MessageHeader getLastSafeMail() {
        return lastSafeMail;
    }

    public void setLastSafeMail(MessageHeader lastSafeMail) {
        this.lastSafeMail = lastSafeMail;
    }
    
    public int getUnreadMailsCount() {
        return unreadMails;
    }
    
    //#ifdef MUJMAIL_USR_FOLDERS    
    public int getUserBoxListDBRecID() {
        return userBoxListDB_recordID;
    }

    public void setUserBoxListDBRecID(int userBoxListDBRecID) {
        userBoxListDB_recordID = userBoxListDBRecID;
    }
    //#endif

    //#ifdef MUJMAIL_USR_FOLDERS    
    /**
     * Loads or saves (in background) accounts that 
     *  have to be retrieved by (user folder).
     * <p>
     * Loading is done automatically during creating folder {@link #InBox}
     *
     * @see mujMail.InBox#saveBoxRetrieveAccounts 
     */
    private class RetrieveBoxAccountsTask extends Thread {
        public static final byte ACCOUNTS_LOAD = 1;
        public static final byte ACCOUNTS_SAVE = 2;
        
        private byte mode;
        RetrieveBoxAccountsTask(byte mode) {
            this.mode = mode;
        }

        public void run() {
            if (InBox.DEBUG) { System.out.println("DEBUG RetrieveBoxAccountsTask.run()"); }
            mujMail.getAccountSettings().waitForAccountsLoading();
            if (InBox.DEBUG) { System.out.println("DEBUG RetrieveBoxAccountsTask.run() after loading of accounts"); }
            try {
                String dbName = getDBFileName() + "_ACC";
                switch (mode) {
                    case ACCOUNTS_LOAD:
                        RecordStore rs1 = RecordStore.openRecordStore(dbName, true);
                        RecordEnumeration en = rs1.enumerateRecords(null, null, false);

                        byte[] data1 = new byte[128];
                        ByteArrayInputStream buffer1 = new ByteArrayInputStream(data1);
                        DataInputStream stream1 = new DataInputStream(buffer1);

                        while (en.hasNextElement()) {
                            int id = en.nextRecordId();
                            int sizeOfRecord = rs1.getRecordSize(id);
                            if (sizeOfRecord > data1.length) {
                                data1 = new byte[sizeOfRecord + 30];
                                buffer1 = new ByteArrayInputStream(data1);
                                stream1 = new DataInputStream(buffer1);
                            }
                            rs1.getRecord(id, data1, 0);
                            stream1.reset();
                            
                            String accountType = stream1.readUTF();
                            if (MailAccountPrimary.CLASS_TYPE_STRING.equalsIgnoreCase(accountType)) {
                                String email = stream1.readUTF();
                                MailAccount ma = (MailAccount)mujMail.getMailAccounts().get(email);
                                if (ma == null) {
                                    if (true || InBox.DEBUG) { System.out.println("Error inbox " + getName() + " mail account " + email + " not exists - willnot be retrieved"); }
                                } else {
                                    accounts.addElement(ma);
                                }
                            } else if (MailAccountDerived.CLASS_TYPE_STRING.equalsIgnoreCase(accountType)) {
                                String email = stream1.readUTF();
                                String imapFld = stream1.readUTF();
                                MailAccount ma = (MailAccount)mujMail.getMailAccounts().get(email);
                                if (ma == null || imapFld == null) {
                                    if (true || InBox.DEBUG) { System.out.println("Error inbox " + getName() + " mail account " + email + " (DERIVED) not exists - will not be retrieved"); }
                                } else {
                                    accounts.addElement( new MailAccountDerived(ma, imapFld));
                                }
                            }
                        }
                        stream1.close();
                        buffer1.close();
                        rs1.closeRecordStore();
                        break;
                    case ACCOUNTS_SAVE:
                        // Clear currently saved
                        try {
                            RecordStore.deleteRecordStore(dbName);
                        } catch (Exception e) {
                            // record store not exists
                        }
                        RecordStore rs2 = RecordStore.openRecordStore(dbName, true);
                        for(int i = 0; i < accounts.size(); i++) {
                            MailAccount ma = (MailAccount)accounts.elementAt(i);

                            ByteArrayOutputStream buffer2 = new ByteArrayOutputStream();
                            DataOutputStream stream2 = new DataOutputStream(buffer2);
                            // 1. case Primary email (POP3)
                            if (ma.getAccountClassType() == MailAccount.ACCOUNT_CLASS_TYPE_PRIMARY) {
                                stream2.writeUTF(MailAccountPrimary.CLASS_TYPE_STRING);
                                stream2.writeUTF(ma.getEmail());
                            } else if (ma.getAccountClassType() == MailAccount.ACCOUNT_CLASS_TYPE_DERIVED) {
                            	//#ifdef MUJMAIL_SYNC
                                stream2.writeUTF(MailAccountDerived.CLASS_TYPE_STRING);
                                //#endif
                                stream2.writeUTF(ma.getEmail());
                                stream2.writeUTF(ma.getIMAPPprimaryBox());
                            }
                            stream2.flush();
                            rs2.addRecord(buffer2.toByteArray(), 0, buffer2.size());
                            stream2.close();
                            buffer2.close();
                            if (InBox.DEBUG) { System.out.println("RBAT - successfully saved " + ma.getEmail()); }
                        }
                        rs2.closeRecordStore();
                        break;
                }
            } catch (Exception e) {
                System.out.println(e.toString());
                e.printStackTrace();
            }
        }
    }
    //#endif
}

⌨️ 快捷键说明

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