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

📄 bodypart.java

📁 手机邮箱撒的方式方式方式的
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/*MujMail - Simple mail client for J2MECopyright (C) 2008 David Hauzar <david.hauzar.mujmail@gmail.com>Copyright (C) 2006 Nguyen Son Tung <n.sontung@gmail.com>Copyright (C) 2006 Martin Stefan <martin.stefan@centrum.cz>This program is free software; you can redistribute it and/or modifyit under the terms of the GNU General Public License as published bythe Free Software Foundation; either version 2 of the License, or(at your option) any later version.This program is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See theGNU General Public License for more details.You should have received a copy of the GNU General Public Licensealong with this program; if not, write to the Free SoftwareFoundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */package mujmail;import mujmail.util.Functions;import java.io.DataInputStream;import java.io.DataOutputStream;import javax.microedition.lcdui.StringItem;/** * Represents an email part - email body or email attachment. Contains * information about the body part such as it's name, encoding etc. * Does not store the content of the body part but contains object * of type {@link ContentStorage} that stores the content. *  * This object is stored persistently in RMS database. It's loading * and saving does object of instance {@link MessageHeader} that * contains this body part. *  */public class BodyPart {        public static final String SOURCE_FILE = "BodyPart";        //body state constants    public static final byte BS_COMPLETE = 0;    public static final byte BS_PARTIAL = 1;    public static final byte BS_EMPTY = 2;        //types of MIME body part, separated only to these types    //for more detailed information of the type use bodyPart.getBpExtension	    public static final byte TYPE_TEXT = 2;    public static final byte TYPE_HTML = 4;    public static final byte TYPE_MULTIMEDIA = 8; //image audio video    public static final byte TYPE_APPLICATION = 16;//pdf, postscrips...	    public static final byte TYPE_OTHER = 32;//model, xworld,... - will never be supported by mujmail        // bodypart transfer encodings    public static final byte ENC_NORMAL = 0; //7bit    public static final byte ENC_BASE64 = 1;    public static final byte ENC_QUOTEDPRINTABLE = 2;    public static final byte ENC_8BIT = 4;	//8bit 		    //bodypart text charset    public static final byte CH_NORMAL = 0; //ASCII and whatever    public static final byte CH_ISO88591 = 1;    public static final byte CH_ISO88592 = 2;    public static final byte CH_WIN1250 = 3;    public static final byte CH_UTF8 = 4;    public static final byte CH_USASCII = 5;        private boolean convertedContentMode = false;    public MessageHeader getMessageHeader() {        return messageHeader;    }    public void setOrder(    byte order) {        this.order = order;    }    public byte getOrder() {        return order;    }        /**     * Manages displaying body part in the sendmail form.     */    public class SendMailDisplayer {        public SendMailDisplayer() {};                /** The number of items of attachment info in sendmail form.         * Used when removing attachments from the form. */        public static final int numberOfItemsInForm = 2;                /** The string item in which is displayed the size of the file in Sendmail form */        private final StringItem siSize = new StringItem(Lang.get(Lang.SM_FILE_SIZE), "");                /**         * Displays this body part in the sendmail form.         * @param sendmail the form to which add information about this body part         */        public void addAttachmentToForm(SendMail sendmail) {            // the name of the attachment            StringItem siFileNameAttached = new                     StringItem(Lang.get(Lang.SM_ATTACHMENT), getHeader().getName() + "\n");            sendmail.append(siFileNameAttached);            // the size of the attachment            sendmail.append(siSize);            updateSize();        }                        /**         * Updates size of the body part in the SendMail form.         */        public void updateSize() {            System.out.println("Updating size");            siSize.setText(Functions.formatNumberByteorKByte(getSize()) + "\n");        }    }        /**     * Returns true if the body state is at least partial - this means complete     * or partial.     * @return true if the body state is at least partial - this means complete     * or partial     */    public boolean atLeastPartial() {        return (bodyState == BS_COMPLETE || bodyState == BS_PARTIAL) ? true : false;    }        /**     * Contains information about the storage of this body part.     */    private ContentStorage contentStorage;        /**     * Contains information about the storage of this body part.     */    private ContentStorage convertedContentStorage;            /** Contains information about body part header */    private Header bodyPartHeader;            private byte order = 0; //the order of the bodypart in a mail body    /** Manages displaying this bodypart in sendmail form */    private SendMailDisplayer sendMailDisplayer = new SendMailDisplayer();        /**     * The message header of message to which this body part belongs.     */    private MessageHeader messageHeader;        /**     * Gets the box in which this body part is.     * @return     */    public PersistentBox getBox() {return getMessageHeader().getBox();}        /**     * Gets the object which manages displaying this bodypart on the SendMail form.     * @return the object which manages displaying this bodypart on the SendMail      *  form.     */    public SendMailDisplayer getSendMailDisplayer() { return sendMailDisplayer; }        /**         * Indicates whether body part is partially downloaded or decoded.         * BS_COMPLETE         * BS_PARTIAL         * BS_EMPTY         */        private byte bodyState = BS_COMPLETE;                public byte getBodyState() { return bodyState; }        public void setBodyState(byte bodyState) { this.bodyState = bodyState; }    /**     * Creates new instance of body part belonging to header header with the     * order and body part header the same as body part copy and with the     * same storage type as body part copy.     * Note that it just creates the storage of the same type as BodyPart copy     * but does not copy it's content!!     * @param header     * @param copy     * @param copyMode copy mode of the content of the body part     */    public BodyPart(MessageHeader header, BodyPart copy, ContentStorage.CopyingModes copyMode) {        this.messageHeader = header;        contentStorage =             copy.getStorage().copy(this, copyMode);                bodyPartHeader = new Header(copy.bodyPartHeader);                        order = copy.order;    //don't copy bodyState. because InProtocol may be downloading the old incomplete bodyPart,     //and by marking this new bodyPart also incomplete bodyPart by default would confuse InProtocol    //and make it unable to replace the old one with the new one    }        /**     * Creates new body part which belongs to the message with header header.     * The storage type will be determined according to mujMail settings.     * @param header the header of the message to which this body part belongs     */    public BodyPart(MessageHeader header) {        // TODO: determine the storage type according to mujMail settings        this.messageHeader = header;        bodyPartHeader = new Header();        contentStorage = new RMSStorage(this);    }    //#ifdef MUJMAIL_FS    /**     * Creates new instance of body part with content stored in FSStorage.     * @param messageHeader     * @param fileURL     * @param fileName     * @param name     * @param size     */    public BodyPart(MessageHeader messageHeader, String fileURL, String fileName, String name, long size) {        this.messageHeader = messageHeader;        contentStorage = new FSStorage(this, size, fileURL);                bodyPartHeader = new Header();        bodyPartHeader.setName(name);    }    //#endif    //create this when sending a mail    public BodyPart(MessageHeader messageHeader, String name) {        this.messageHeader = messageHeader;                // TODO: create storage according to global settings of mujMail        contentStorage = new RMSStorage(this);        bodyPartHeader = new Header();        bodyPartHeader.setName(name);    }    //we can call this constructor after a complete parsing and storing a content    public BodyPart(MessageHeader messageHeader, String nm, byte encoding, byte type, byte charset) {        this.messageHeader = messageHeader;        // TODO: create storage according to global settings of mujMail        contentStorage = new RMSStorage(this);                bodyPartHeader = new Header(nm, type, charset, encoding);    }        public BodyPart(MessageHeader messageHeader, Header bodyPartHeader) {        this.messageHeader = messageHeader;        // TODO: create storage according to global settings of mujMail        contentStorage = ContentStorage.createStorageInstance(this, ContentStorage.StorageTypes.RMS_STORAGE.getStorageTypeNumber());        this.bodyPartHeader = bodyPartHeader;    }        /**     * Gets viewing mode of this bodypart determined from the content and header     * of the bodypart.     * @return the viewing mode of this bodypart determined from it's content and header     */    public MailForm.BPViewingModes.ViewingModesWithActions getAutoViewingMode() {        if ( getHeader().getBodyPartContentType() == BodyPart.TYPE_HTML ) {         	return MailForm.BPViewingModes.HTML;        } else if ( getHeader().getBodyPartContentType() == BodyPart.TYPE_TEXT) {            return MailForm.BPViewingModes.PLAIN_TEXT;        }        if (getHeader().getBodyPartContentType() == BodyPart.TYPE_MULTIMEDIA &&                (getHeader().getName().toLowerCase().endsWith("jpg") ||                 getHeader().getName().toLowerCase().endsWith("jpeg") ||                 getHeader().getName().toLowerCase().endsWith("gif") || 

⌨️ 快捷键说明

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