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

📄 messageheader.java

📁 手机邮箱撒的方式方式方式的
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
    //gets emails from one big string of emails - recipients
    public Vector getRcp() {
        return Functions.parseRcp(recipients);
    }

    //changes the size of the mail to the current situation
    public int updateSize() {
    	int newSize = Functions.getStringByteSize(from) + Functions.getStringByteSize(subject) + Functions.getStringByteSize(recipients);

        for (byte i = (byte) (bodyParts.size() - 1); i >= 0; --i) {
        	newSize += ((BodyPart) bodyParts.elementAt(i)).getStorage().getSize();
        }

        setSize( newSize );
        return newSize;
    }
    
    /**
     * Gets the number of milliseconds since the standard base time known as 
     *  "the epoch", namely January 1, 1970, 00:00:00 GMT to the date of the message.
     * @return  the unix timestamp of the message.
     */
    public long getTime() {
        return time;
    }

    //converts long time to string format "Tue, 28 Nov 2006 17:00:05", this method is extremely slow, use it wisely.
    public String getTimeStr() {
        String time = new Date(this.time).toString();
        StringBuffer sb = new StringBuffer(37);
        if (time.length() >= 33) //has timezone info and time shift (nokia 7500 has this)
        {
            sb.append(time.substring(0, 3)).append(", ").append(time.substring(8, 10)).append(time.substring(3, 7)).append(time.substring(29)).append(time.substring(10, 19));
        } else if (time.length() >= 27) //has timezone info
        {
            sb.append(time.substring(0, 3)).append(", ").append(time.substring(8, 10)).append(time.substring(3, 7)).append(time.substring(23)).append(time.substring(10, 19));
        } else {
            sb.append(time.substring(0, 3)).append(", ").append(time.substring(8, 10)).append(time.substring(3, 7)).append(time.substring(20)).append(time.substring(10, 19));
        }
        return sb.toString();
    }

    //converts long time to string format "17:00"
    public String getShortTimeStr() {
        int minutes = (int) ((time / 60000) % 60);
        int hours = (int) ((time / 3600000) % 24);
        String minutesStr = (minutes < 10 ? "0" : "") + minutes;
        String hoursStr = (hours < 10 ? "0" : "") + hours;
        return hoursStr + ":" + minutesStr;
    }

    public byte getBpState(byte i) {
        return ((BodyPart) bodyParts.elementAt(i)).getBodyState();
    }

    public byte getBpOriginalOrder(byte i) {
        return ((BodyPart) bodyParts.elementAt(i)).getOrder();
    }

    //tells if a bodypart of a concrete type can be saved to the DB if it's damaged or only partially downloaded
    static public boolean canBePartiallySaved(BodyPart body) {
        switch (body.getHeader().getBodyPartContentType()) {
            case BodyPart.TYPE_TEXT:
            case BodyPart.TYPE_HTML:
                return true;
            default:
                return false;
        }

    }

    public void setMessageID(String messageID) {
        this.messageID = messageID;
    }

    public String getMessageID() {
        return messageID;
    }
    
    public String getIMAPFolder() {
        return imapFolder;
    }
    
    /**
     * Sets imap folder name where message take place. 
     * Note for POP3 can be left empty.
     * @param folderName INBOX a so on [Gmail]/All mails
     */
    public void setIMAPFolder(String folderName) {
        if (DEBUG) System.out.println("DEBUG MessageHeader.setIMAPFolder : " + folderName);
        imapFolder = folderName;
    }
    
    /**
     * @return the threadingMessageID
     */
    public String getThreadingMessageID() {
        return threadingMessageID;
    }

    /**
     * @param threadingMessageID the threadingMessageID to set
     */
    public void setThreadingMessageID(String threadingMessageID) {
        this.threadingMessageID = threadingMessageID;
    }

    /**
     * Getter for {@link #boundary} field.
     * 
     * @return {@link #boundary}
     */
    public String getBoundary() {
        return boundary;
    }

    public void setFrom(String from) {
        this.from = from;
    }

    public void setSubject(String subject) {
        this.subject = subject;
    }

    public void setTime( //in Bytes TODO: <- Betlista: ?!?
    long time) {
        this.time = time;
    }

    /**
     * Setter for {@link #boundary} field.
     * 
     * @param boundary new mail boundary
     */
    public void setBoundary(String boundary) {
        this.boundary = boundary;
    }

    public void setAccountID( /** Account from which the mail was downloaded - must be given for every mail */
    String accountID) {
        this.accountID = accountID;
    }

    public //we must initiate from and recipients otherwise sort wont allways work
    String getFrom() {
        return from;
    }

    public String getAccountID() {
        return accountID;
    }

    public int getSize() {
        return size;
    }

    /**
     * Setter for {@link #size} field.
     * 
     * @param size new size
     */
    public void setSize(int size) {
        this.size = size;
    }

    private void copyVectorToVector(final Vector from, final Vector to) {
        Object o;
        for (int i = 0; i < from.size(); ++i) {
            o = from.elementAt( i );
            to.addElement( o );
        }
    }

    public void fillWith(final MessageHeader messageHeader) {
        this.DBStatus = messageHeader.DBStatus;
        this.accountID = messageHeader.accountID;
        Vector v = new Vector();
        copyVectorToVector(messageHeader.bodyParts, v);
        this.bodyParts = v;
        this.boundary = messageHeader.boundary;
//        this.box = messageHeader.box;
        this.DBStatus = messageHeader.DBStatus;
        this.deleted = messageHeader.deleted;
        this.flagged = messageHeader.flagged;
        this.from = messageHeader.from;
        this.isEmpty = messageHeader.isEmpty;
        this.messageFormat = messageHeader.messageFormat;
        this.messageID = messageHeader.messageID;
        this.imapFolder = messageHeader.imapFolder;
        this.threadingMessageID = messageHeader.threadingMessageID;
        this.orgLocation = messageHeader.orgLocation;
        this.parentID = messageHeader.parentID;
        v = new Vector();
        copyVectorToVector(messageHeader.parentIDs, v);
        this.parentIDs = v;
        this.readStatus = messageHeader.readStatus;
        this.recipients = messageHeader.recipients;
        this.recordID = messageHeader.recordID;
        this.replyTo = messageHeader.replyTo;
        //#ifdef MUJMAIL_SEARCH
        this.searchResult = new MessageSearchResult( messageHeader.searchResult );
        //#endif
        this.sendStatus = messageHeader.sendStatus;
        this.size = messageHeader.size;
        this.subject = messageHeader.subject;
        this.time = messageHeader.time;
    }

    /* ********************
     *   Object methods   *
     **********************/
    private static final String CLASS_NAME = "MessageHeader";

    //#ifdef MUJMAIL_DEVELOPMENT
//#     /**
//#      * Returns string representation for this class.
//#      * It's used only in development environment, that's the reason why
//#      * the method is not fully implemented (doesn't contain all fields
//#      * in string representation).
//#      */
//#     public String toString() {
//#         StringBuffer buff = new StringBuffer( CLASS_NAME ).append('[');
//#         buff.append("messageID='").append( messageID ).append('\'')
//#             .append(", threadedMessageID='").append( threadingMessageID ).append('\'')
//#             .append(", parentID='").append( parentID ).append('\'')
//#             .append(", parentIDs=").append( parentIDs )
//#             .append(", subject='").append( subject ).append('\'')
//#             .append(", isEmpty=").append( isEmpty )
//#             .append(", deleted=").append( deleted )
//#             .append(']');
//#         return buff.toString();
//#     }
    //#endif

    /* (non-Javadoc)
     * @see java.lang.Object#hashCode()
     */
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + DBStatus;
        result = prime * result
                + ((accountID == null) ? 0 : accountID.hashCode());
        result = prime * result
                + ((bodyParts == null) ? 0 : bodyParts.hashCode());
        result = prime * result
                + ((boundary == null) ? 0 : boundary.hashCode());
        result = prime * result + ((box == null) ? 0 : box.hashCode());
        result = prime * result + (deleted ? 1231 : 1237);
        result = prime * result + (flagged ? 1231 : 1237);
        result = prime * result + ((from == null) ? 0 : from.hashCode());
        result = prime * result + (isEmpty ? 1231 : 1237);
        result = prime * result + messageFormat;
        result = prime * result
                + ((messageID == null) ? 0 : messageID.hashCode());
        result = prime * result
                + ((threadingMessageID == null) ? 0 : threadingMessageID.hashCode());
        result = prime * result + orgLocation;
        result = prime * result
                + ((parentID == null) ? 0 : parentID.hashCode());
        result = prime * result
                + ((parentIDs == null) ? 0 : parentIDs.hashCode());
        result = prime * result + readStatus;
        result = prime * result
                + ((recipients == null) ? 0 : recipients.hashCode());
        result = prime * result + recordID;
        result = prime * result + ((replyTo == null) ? 0 : replyTo.hashCode());
        //#ifdef MUJMAIL_SEARCH
        result = prime * result
                + ((searchResult == null) ? 0 : searchResult.hashCode());
        //#endif
        result = prime * result + sendStatus;
        result = prime * result + size;
        result = prime * result + ((subject == null) ? 0 : subject.hashCode());
        result = prime * result + (int) (time ^ (time >>> 32));
        return result;
    }

    /* (non-Javadoc)
     * @see java.lang.Object#equals(java.lang.Object)
     */
    public boolean equals(Object obj) {
        if (this == obj)
            return true;
        if (obj == null)
            return false;
        if (getClass() != obj.getClass())
            return false;

        MessageHeader other = (MessageHeader) obj;
        if (DBStatus != other.DBStatus)
            return false;
        if (accountID == null) {
            if (other.accountID != null)
                return false;
        } else if (!accountID.equals(other.accountID))
            return false;
        if (bodyParts == null) {
            if (other.bodyParts != null)
                return false;
        } else if (!bodyParts.equals(other.bodyParts))
            return false;
        if (boundary == null) {
            if (other.boundary != null)
                return false;
        } else if (!boundary.equals(other.boundary))
            return false;
        if (box == null) {
            if (other.box != null)
                return false;
        } else if (!box.equals(other.box))
            return false;
        if (deleted != other.deleted)
            return false;
        if (flagged != other.flagged)
            return false;
        if (from == null) {
            if (other.from != null)
                return false;
        } else if (!from.equals(other.from))
            return false;
        if (isEmpty != other.isEmpty)
            return false;
        if (messageFormat != other.messageFormat)
            return false;
        if (messageID == null) {
            if (other.messageID != null)
                return false;
        } else if (!messageID.equals(other.messageID))
            return false;

        if (imapFolder == null) {
            if (other.imapFolder != null)
                return false;
        } else if (!imapFolder.equals(other.imapFolder))
            return false;
        
        if (threadingMessageID == null) {
            if (other.threadingMessageID != null)
                return false;
        } else if (!threadingMessageID.equals(other.threadingMessageID))
            return false;

        if (orgLocation != other.orgLocation)
            return false;
        if (parentID == null) {
            if (other.parentID != null)
                return false;
        } else if (!parentID.equals(other.parentID))
            return false;
        if (parentIDs == null) {
            if (other.parentIDs != null)
                return false;
        } else if (!parentIDs.equals(other.parentIDs))
            return false;
        if (readStatus != other.readStatus)
            return false;
        if (recipients == null) {
            if (other.recipients != null)
                return false;
        } else if (!recipients.equals(other.recipients))
            return false;
        if (recordID != other.recordID)
            return false;
        if (replyTo == null) {
            if (other.replyTo != null)
                return false;
        } else if (!replyTo.equals(other.replyTo))
            return false;
        //#ifdef MUJMAIL_SEARCH
        if (searchResult == null) {
            if (other.searchResult != null)
                return false;
        } else if (!searchResult.equals(other.searchResult))
            return false;
        //#endif
        if (sendStatus != other.sendStatus)
            return false;
        if (size != other.size)
            return false;
        if (subject == null) {
            if (other.subject != null)
                return false;
        } else if (!subject.equals(other.subject))
            return false;
        if (time != other.time)
            return false;
        return true;
    }

}

⌨️ 快捷键说明

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