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

📄 mailform.java

📁 手机邮箱撒的方式方式方式的
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
            displayAsText = new Command(Lang.get(Lang.BTN_MF_DISPLAY_AS_TEXT), Command.ITEM, 4);            exportBPToFS = new Command(Lang.get(Lang.BTN_MF_EXPORT_BP_TO_FS), Command.ITEM, 5);            viewConverted = new Command(Lang.get(Lang.BTN_MF_VIEW_CONVERTED), Command.ITEM, 6);            if (msgHeader.getBox() == mujMail.getInBox()) {                attchList.addCommand(redownAttchment);            }            attchList.addCommand(back);            attchList.addCommand(deleteAttachment);            attchList.addCommand(displayAsText);            attchList.addCommand(exportBPToFS);            attchList.addCommand(viewConverted);            attchList.setCommandListener(mujMail);        }        for (int i = attchList.size(); i > 0; i--) {            attchList.delete(i - 1);        }        System.out.println(msgHeader);        int bodyPartCount = msgHeader.getBodyPartCount();        for (byte i = 0; i < bodyPartCount; i++) {            // choose different icons according to the bodypart type            String prefix = msgHeader.getBpState(i) == BodyPart.BS_COMPLETE ? "" : " [!] ";            switch (msgHeader.getBpType(i)) {                case BodyPart.TYPE_TEXT:                    attchList.append(prefix + msgHeader.getBodyPart(i).getHeader().getName() + " (" +                            (msgHeader.getBodyPart(i).getSize() > 1024 ? (msgHeader.getBodyPart(i).getSize() >> 10) + "kB" : msgHeader.getBodyPart(i).getSize() + "B") + ")",                            Functions.getIcon("attch_txt.png"));                    break;                case BodyPart.TYPE_MULTIMEDIA:                    attchList.append(prefix + msgHeader.getBodyPart(i).getHeader().getName() + " (" +                            (msgHeader.getBodyPart(i).getSize() > 1024 ? (msgHeader.getBodyPart(i).getSize() >> 10) + "kB" : msgHeader.getBodyPart(i).getSize() + "B") + ")",                            Functions.getIcon("attch_image.png"));                    break;                case BodyPart.TYPE_HTML:                    attchList.append(prefix + msgHeader.getBodyPart(i).getHeader().getName() + " (" +                            (msgHeader.getBodyPart(i).getSize() > 1024 ? (msgHeader.getBodyPart(i).getSize() >> 10) + "kB" : msgHeader.getBodyPart(i).getSize() + "B") + ")",                            Functions.getIcon("attch_html.png"));                    break;                case BodyPart.TYPE_APPLICATION:                case BodyPart.TYPE_OTHER:                    attchList.append(prefix + msgHeader.getBodyPart(i).getHeader().getName() + " (" +                            (msgHeader.getBodyPart(i).getSize() > 1024 ? (msgHeader.getBodyPart(i).getSize() >> 10) + "kB" : msgHeader.getBodyPart(i).getSize() + "B") + ")",                            Functions.getIcon("attch_unknown.png"));                    break;            }        }        mujMail.getDisplay().setCurrent(attchList);    }    /**     * Shows a list of e-mail addresses in a MULTIPLE list.     */    public void listMailAddr() {        if (mailAdrList == null) {            mailAdrList = new List(Lang.get(Lang.BTN_MF_EMAIL_ADDRS), Choice.MULTIPLE);            mailAdrList.addCommand(back);            mailAdrList.addCommand(addMailToBook);            mailAdrList.setCommandListener(mujMail);        }        // delete old items        for (int i = mailAdrList.size(); i > 0; i--) {            mailAdrList.delete(i - 1);        }        // refresh address' Vector and List        Vector addr = Functions.parseRcp(msgHeader.getRecipients() );        addr.addElement(Functions.emailOnly(msgHeader.getFrom()));        for (int i = 0; i < addr.size(); i++) {            mailAdrList.append((String) addr.elementAt(i), null);        }        mujMail.getDisplay().setCurrent(mailAdrList);    }    /**     * Save all checked email addresses in the <code>mailAdrList</code>.     */    public void saveContacts() {        boolean[] checked = new boolean[mailAdrList.size()];        mailAdrList.getSelectedFlags(checked);        AddressBook.Contact contact;        for (int i = 0; i < mailAdrList.size(); ++i) {            if (checked[i]) {                contact = new AddressBook.Contact("", mailAdrList.getString(i), "");                try {                    mujMail.getAddressBook().saveContact(contact);                } catch (MyException ex) {                }            }        }        mujMail.getDisplay().setCurrent(this);    }    /**     * This method completely deletes a method attachment, that is chosen. This bodypart must be deleted from both     * <code> bodyParts Vector </code> and <code> MailDb </code> that is done by <code>deleteBodyPart</code> method.     * @param ID of the attachment. It is attchList.getSelectedIndex + 1.     * @see MessageHeader     */    public void deleteBodyPart(byte ID) {        synchronized (msgHeader) {            byte bodyPartCount = msgHeader.getBodyPartCount();            if (bodyPartCount == 0) {                mujMail.alert.setAlert(this, this, Lang.get(Lang.ALRT_MF_NO_ATTACHMENTS), MyAlert.DEFAULT, AlertType.ERROR);                return;            }            if (0 <= ID && ID < bodyPartCount) {                try {                    msgHeader.getBodyPart(ID).getStorage().deleteContent();                    attchList.delete(ID);                    msgHeader.removeBodyPart(ID);                    //to prevent accessing non-existing bodypart                    if (firstViewable == ID) {                        firstViewable = -1;                    }                    if (currAttachmentID == ID) {                        currAttachmentID = firstViewable;                    }                                        msgHeader.saveHeader(); //we have to update info about msgHeader as well                } catch (MyException ex) {                    mujMail.alert.setAlert(attchList, callBox, Lang.get(Lang.ALRT_MF_DEL_ATT) + Lang.get(Lang.FAILED) + ex.getDetails(), MyAlert.DEFAULT, AlertType.ERROR);                    msgHeader.notify();                    return;                }                mujMail.alert.setAlert(attchList, attchList, Lang.get(Lang.ALRT_MF_DEL_ATT) + Lang.get(Lang.SUCCESS), MyAlert.DEFAULT, AlertType.INFO);            }            msgHeader.notify();        }    }    /**     * Thread method that serves to load body either from MailDB or from remote server.     */    public void run() {        setContext(MODE_LIST);        switch (runMode) {            case LOAD_BODY:                try {                    if (loadBody(msgHeader) == null) { //try to load the body of the mail						                        mujMail.alert.setAlert(this, callBox, Lang.get(Lang.ALRT_MF_LOAD_BODY) + Lang.get(Lang.FAILED), MyAlert.DEFAULT, AlertType.ERROR);                        return;                    }                    //only inBox needs a counter for unread mails                    if (msgHeader.readStatus == MessageHeader.NOT_READ && msgHeader.getBox() == mujMail.getInBox()) {                        msgHeader.readStatus = MessageHeader.READ;                        //Seen flag is set automatically when                        //FETCH BODY is called -> no need to set \Seen flag                        /*                        MailAccount msgAcct = (MailAccount)mujMail.mailAccounts.get(msgHeader.accountID);                                                //Set '\Seen' flag on server if it's an IMAP account                        if (msgAcct.type == MailAccount.IMAP)                        {                        	msgAcct.protocol.setFlags(msgHeader, "(\\Seen)");                        }                        */                                                try {                            msgHeader.saveHeader(); //update new data into DBase                        } catch (MyException me) {                        }                        ((InBox) msgHeader.getBox()).changeUnreadMails(-1);                    }                    firstViewable = getFirstViewableBody(msgHeader); //find the first viewable bodypart;                    if (firstViewable == -1) { //non are viewable																		                        listAttachments();                        attchList.addCommand(showHeader);                        attchList.addCommand(showAddresses);                        attchList.addCommand(delete);                        attchList.addCommand(forward);                        attchList.addCommand(edit);                                                //#ifdef MUJMAIL_FS                        attchList.addCommand(exportToFS);                        //#endif                        mujMail.alert.setAlert(this, attchList, Lang.get(Lang.ALRT_MF_NO_VIEWABLE_BODY), MyAlert.DEFAULT, AlertType.INFO);                    } else { //there are some viewable bodyparts                        BodyPart bp = msgHeader.getBodyPart(firstViewable);                        currAttachmentID = firstViewable;                        setContext(MODE_BASIC);                        bp.getAutoViewingMode().initDisplayingVariables(this);                                                repaint();                        mujMail.getDisplay().setCurrent(this);                    }                } catch (Exception ex) {                    back();                    mujMail.alert.setAlert(this, callBox, Lang.get(Lang.ALRT_MF_LOAD_BODY) + Lang.get(Lang.FAILED) + ex, MyAlert.DEFAULT, AlertType.ERROR);                } catch (Error e) {                    back();                    mujMail.alert.setAlert(this, callBox, Lang.get(Lang.ALRT_MF_LOAD_BODY) + Lang.get(Lang.FAILED) + e, MyAlert.DEFAULT, AlertType.ERROR);                }                break;            case REDOWNLOAD_BODY:                synchronized (msgHeader) {                    mujMail.getInBox().regetBody(msgHeader, bodyPartToRedown);                    mujMail.getDisplay().setCurrent(callBox);                    try {                        msgHeader.wait();                    } catch (Exception ignored) {                    }                }                listAttachments();                break;        }    }    /**     * Preview the message that user immediately writes.     * When button back is pressed, user can continue writing the message.     */    public void previewMessage() {        previewMode = true;        // the message is saved to outbox, it must be deleted when BACK button        // is pressed!!        viewMessage(mujMail.sendMail.createAndSaveMessage(mujMail.outBox), null);    }    /**     * <p>     * Is used to display body of a message with all attachments. Firstly, it      * shows just a textual part of a body. If the message contains some other      * attachments, the Canvas will have listAttachments Command to display it.     * <p>     * Must be run in separate thread.     *     * @param mh - {@link MessageHeader} that will be displayed.     * @param callBox - this is a screen, that will be shown after an user clicks back button     * Viewing must be run a in different thread, other it would cause the mujmail main thread unable to     * perform any other vital tasks - commandListening, displaying dialog windows!!!     */    public void viewMessage(MessageHeader msgHeader, TheBox callBox) {        if (msgHeader == null) {            return;        }        bpViewingMode = BPViewingModes.NOT_SPECIFIED;                this.callBox = callBox;        this.msgHeader = msgHeader;        runMode = LOAD_BODY;        Thread t = new Thread(this);        t.start();        t.setPriority(Thread.MAX_PRIORITY);    }        //#ifdef MUJMAIL_FS    /**     * Exports given bodypart to filesystem.     * @param ID ID of the BodyPart to be exported.     */    void exportBPToFS(byte ID) {        FileSystemBodyPartExporter.exportBPToFS(this, msgHeader, ID);    }    //#endif    /**     * Displays the chosen bodypart.     * @param ID ID of the BodyPart.     * @param viewingMode the viewing mode of the body part     */    public void viewBodyPart(byte ID, BPViewingModes viewingMode) {    	  if (DEBUG) System.out.println("DEBUG MailForm.viewBodyPart(ID=" + ID + ", viewingMode=" + viewingMode + ")");        BodyPart actBodyPart = msgHeader.getBodyPart(ID);          if (DEBUG) System.out.println("DEBUG MailForm.viewBodyPart(byte, BPViewingModes) - " + actBodyPart );        bpViewingMode = viewingMode;        if ( !getBPViewingModeWithActions().isViewable(actBodyPart, attchList) ) {        	  if (DEBUG) System.out.println( "DEBUG MailForm.viewBodyPart(byte, BPViewingModes) - BodyPart is not viewable" );        	return;        }        if (0 <= ID && ID < msgHeader.getBodyPartCount()) {            if (ID != firstViewable) //another bodypart than firstViewable was chosen            {                setContext(MODE_BROWSE);            } else {                setContext(MODE_BASIC);            } //prevents viewing the same bodypart twice            if ( ! getBPViewingModeWithActions().prepareForViewingBP(actBodyPart, ID, this) ) {                return;            }            currAttachmentID = ID;            repaint();        }        mujMail.getDisplay().setCurrent(this);    }    private byte getFirstViewableBody(MessageHeader mh) {        byte bpCount = mh.getBodyPartCount();        byte i;        BodyPart bp;        for (i = 0; i < bpCount; i++) {            bp = mh.getBodyPart((byte) i);            if (bp.getAutoViewingMode() != BPViewingModes.NO_VIEW) {                return i;            }        }        return -1;    }    /**     * Loads and displays the first text or HTML part of a body.     * If the body has not been downloaded yet, than it is necessary to retrieve the whole message from the remote server.     * @param mh - {@link MessageHeader} that body should be read.     * @return first bodyPart String. If there is no textual part of the body, then it returns a <code> String </code> informing     * about it.     */    public MessageHeader loadBody(MessageHeader mh) {        this.msgHeader = mh;        // if body is in the RecordStore        if (mh.getBodyPartCount() > 0) {            return mh;        } // body must be downloaded        else {            //its not inBox or user folder (ie trash), but we would save the mail's body the inbox             //and it would cause a mess in Database            if (!(mh.getBox() instanceof InBox)) {                return null;            }            synchronized (mh) {                ((InBox)mh.getBox()).getBody(mh);                try {                    mh.wait();                } catch (Exception ex) {                }            }            if (mh.getBodyPartCount() == 0) //message could not be downloaded            {                return null;            }            return mh;        }    }    /**     * Changes a graphical context, which is used to recognize, what is to be displayed. There are three possible     * choices.     * <ol>     * 	<li> TEXT_MODE context - is used to display plain text.     * 	<li> MODE_BROWSE context - is used to display image attachments.     * 	<li> MODE_LIST context - is used when some form or list is supposed to be displayed .     * </ol>     *     * <p> It sets up appropriate Commands to the listAttachments object.     * @param contextID - graphical context.     */    public void setContext(byte contextID) {        this.contextID = contextID;        currDisplay = 0;        switch (contextID) {            // text/html context            case MODE_BASIC:                if (msgHeader.messageFormat == MessageHeader.FRT_MULTI && msgHeader.getBodyPartCount() > 1) {                    addCommand(listAttachments);                }                addCommand(back);                addCommand(listAttachments);                addCommand(showHeader);                addCommand(showAddresses);                //#ifdef MUJMAIL_FS                addCommand(exportToFS);

⌨️ 快捷键说明

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