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

📄 sendmail.java

📁 手机邮箱撒的方式方式方式的
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
                StringBuffer newBody = new StringBuffer(header.getBodyPartContent((byte) 0));                int i = 0;                newBody.insert(i, '>');                while (i < newBody.length()) {                    if (newBody.charAt(i) == '\n') {                        newBody.insert(i + 1, '>');                        i += 2;                    } else {                        i++;                    }                }                if (newBody.length() > body.getMaxSize()) {                    body.setMaxSize(newBody.length() + 1000);                }                body.setString("\r\n" + newBody.toString() + "\r\n");            }            reply(header);        }    }    public void edit(MessageHeader header, Displayable nextScreen) {        edit(header, nextScreen, NORMAL);    }    private void edit(MessageHeader header, Displayable nextScreen, byte mode) {//        this.header = header;        this.nextScreen = nextScreen;        this.mode = mode;                from.setText(header.getFrom());        String rcps = header.getRecipients();        int x, y, z;        //detect To: Bcc: Cc:         x = rcps.indexOf("Bcc:");        y = rcps.indexOf("Cc:");        z = rcps.indexOf("To:");        if (z != -1) {            to.setString(rcps.substring(z + 3, rcps.indexOf(" *", z + 4)).trim());        }        if (x != -1 || y != -1) {            set(1, bcc);            set(2, cc);            if (x != -1) {                bcc.setString(rcps.substring(x + 4, rcps.indexOf(" *", x + 5)).trim());            }            if (y != -1) {                cc.setString(rcps.substring(y + 3, rcps.indexOf(" *", y + 4)).trim());            }            append(subject);            append(body);            removeCommand(bc);        }        subject.setString(header.getSubject());        BodyPart bp = header.getBodyPart((byte) 0);        try {            if (mode == NORMAL) {                body.setString(bp.getStorage().getContent());            } else {                body.setString("\n---------- Forwarded message ----------\n" +                    "From: " + header.getFrom() + "\n" +                    "Date: " + header.getTimeStr() + "\n" +                    "Subject: " + header.getSubject() + "\n" + "" +                    "Recipients: " + header.getRecipients() + "\n" + "\n" +                    header.getBodyPartContent((byte) 0));            }        } catch (Throwable ex) {            ex.printStackTrace();        }        //#ifdef MUJMAIL_FS        attachementsAdder.importAttachmentsFromHeader(header);        //#endif                this.callBox = header.getBox();        mujMail.getDisplay().setCurrent(this);    }    /**     * Forward the message.     * @param callBox     */    public void initForward(TheBox callBox, Displayable nextScreen) {        edit(callBox.getSelectedHeader(), nextScreen, FORWARD);    }    public void addBc() {        if (bcc_cc_added == false) {            set(2, bcc); //set subject textfield to bcc            set(3, cc); //set body to cc            append(subject);            append(body);            if (mode == FORWARD) {                StringItem fwdMsgNotice = (StringItem) get(4);                delete(4); //remove the old one                append(fwdMsgNotice); //append again the forwarded message string item			            }            removeCommand(bc);            bcc_cc_added = true;        }    }    public void chooseAccounts() {        accountsForm.refresh();    }            /**     * Creates the message from data filled in this form and saves it to the     * database. If the storingBox is the same as {@link SendMail#callBox}     * and mode is {@link SendMail#EDIT}, saves the message to already existing     * record in the RMS database.     *      * @param storingBox the box to which the header will be stored (will belong)     * @return the message header of message created form data filled in this      *  form.     */    public MessageHeader createAndSaveMessage(PersistentBox storingBox) {        StringBuffer rcps = new StringBuffer();        String recipients;        //now try to append all the recipients ()        if (bcc.getString().length() != 0) {            rcps.append("Bcc: ").append(bcc.getString()).append(" *");        }        if (cc.getString().length() != 0) {            rcps.append("Cc: ").append(cc.getString()).append(" *");        }        if (to.getString().length() != 0) {            rcps.append("To: ").append(to.getString());        }        recipients = rcps.toString().trim();        if (!recipients.endsWith("*")) {            recipients = recipients + " *";        }        if (recipients.length() < 6) { //its to short, must be invalid address            storingBox.report("100: " + Lang.get(Lang.ALRT_SM_NO_RCP), SOURCE_FILE);            return null;        }                String ID = Functions.genID();        MessageHeader tmpM = new MessageHeader(storingBox, from.getText(), recipients, subject.getString(), ID, System.currentTimeMillis());        BodyPart bp = new BodyPart(tmpM, "default_mail_body");        tmpM.addBodyPart(bp);        //#ifdef MUJMAIL_FS        //add attachment file to header if user attached one        if (getAttachementsAdder().getAttachmentsCount() > 0) {            // remove all existing file system attachments (in case of editing message)            tmpM.removeFSAttachments();            getAttachementsAdder().exportAttachmentsToHeader(tmpM);                        tmpM.messageFormat = MessageHeader.FRT_MULTI;        } else {            tmpM.messageFormat = MessageHeader.FRT_PLAIN;        }        //#else//#         tmpM.messageFormat = MessageHeader.FRT_PLAIN;        //#endif                        // bodyparts are already saved while making deep copy        try {            bp.getStorage().addToContent(body.getString() + "\r\n");            if (mode == SendMail.EDIT && storingBox == callBox) {                // the message will be only updated while calling storingBox.mailDB.saveHeader(tmpM);                // it will be stored to existing database record                tmpM.setRecordID( storingBox.getMessageHeaderAt( storingBox.getSelectedIndex() ).getRecordID() );                tmpM.DBStatus = MessageHeader.STORED; //so we can update the old mail in the mailDB.saveHeader()call later            }            storingBox.mailDB.saveHeader(tmpM);        } catch (Exception ex) { //rollback & cleaning            ex.printStackTrace();            storingBox.report(ex.getMessage() + " " + subject.getString(), SOURCE_FILE);            bp.getStorage().deleteContent();            return null;        }        tmpM.updateSize();        return tmpM;    }    public void selectFromAccount() {        from.setText(accountsCG.getString(accountsCG.getSelectedIndex()));        mujMail.getDisplay().setCurrent(this);    }    /**     * Displays the form for writingn new mail.     * @param nextScreen     */    public void writeMail(Displayable nextScreen) {        this.nextScreen = nextScreen;        initFrom();        MujMail.mujmail.getDisplay().setCurrent(this);    }    private void initFrom() {        from.setText(Settings.primaryEmail);        //primaryEmail is not set, let's select the first one at least        if (Settings.primaryEmail.equals(Settings.notSetPE)) {            for (Enumeration e = mujMail.getMailAccounts().elements(); e.hasMoreElements();) {                MailAccount account = (MailAccount) e.nextElement();                if (account.isActive()) {                    from.setText(account.getEmail());                    break;                }            }        }    }    /**     * Clears text fields and attachments.     */    public void clear() {        to.setString("");        subject.setString("");        body.setString("");        bcc.setString("");        cc.setString("");        if (bcc_cc_added) {            delete(2);            delete(2);            addCommand(bc);            bcc_cc_added = false;        }                //#ifdef MUJMAIL_FS        attachementsAdder.removeAllAttachments();        //#endif    }    public void CheckRecordSize(List list) throws RecordStoreException {        RecordStore rs = RecordStore.openRecordStore("test_this", true);        try {            list.append(String.valueOf(rs.getSizeAvailable()), null);        } finally {            rs.closeRecordStore();        }    }    //edits body in a whole screen textbox    public void editBody() {        if (body.size() > editbodyTB.getMaxSize()) {            editbodyTB.setMaxSize(body.size()+1000);        }        editbodyTB.setString(body.getString());        //editbodyTB.insert(" ", 0); //reset caret? no        mujMail.getDisplay().setCurrent(editbodyTB);    }    /**     * Displays the screen that should follow after this form.     */    public void showNextScreen() {        System.out.println("Next screen is " + nextScreen);        MujMail.mujmail.getDisplay().setCurrent(nextScreen);    }    //updates body from a whole screen textbox    public void updateBody() {        if (editbodyTB.size() > body.getMaxSize()) {            body.setMaxSize(editbodyTB.size()+1000);                    }        body.setString(editbodyTB.getString());        mujMail.getDisplay().setCurrent(this);        //unfortunately, no set focus in MIDP 1        //body.insert("", body.getCaretPosition());        // this don't work for focus either: IllegalStateException at javax.microedition.lcdui.Form.append(Form.java:218)        //this.markAsDeleted(3);        //this.append(body);    }    //cancels body from a whole screen textbox    public void cancelBody() {        mujMail.getDisplay().setCurrent(this);        selectedField = this.body;    } }

⌨️ 快捷键说明

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