mailfilter.java
来自「moblie syncml mail javame」· Java 代码 · 共 239 行
JAVA
239 行
/*
* Funambol is a mobile platform developed by Funambol, Inc.
* Copyright (C) 2003 - 2007 Funambol, Inc.
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU Affero General Public License version 3 as published by
* the Free Software Foundation with the addition of the following permission
* added to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED
* WORK IN WHICH THE COPYRIGHT IS OWNED BY FUNAMBOL, FUNAMBOL DISCLAIMS THE
* WARRANTY OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program; if not, see http://www.gnu.org/licenses or write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301 USA.
*
* You can contact Funambol, Inc. headquarters at 643 Bair Island Road, Suite
* 305, Redwood City, CA 94063, USA, or at email address info@funambol.com.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License
* version 3, these Appropriate Legal Notices must retain the display of the
* "Powered by Funambol" logo. If the display of the logo is not reasonably
* feasible for technical reasons, the Appropriate Legal Notices must display
* the words "Powered by Funambol".
*/
package com.funambol.mailclient;
import java.util.Date;
import com.funambol.util.MailDateFormatter;
/**
* This class is a bean containing the mail filter informations, used by the
* mail client to set a filter to the messages to be downloaded from the remote
* server.
* <p>
* The implementations of the interface will use the feautures of different
* protocols to filter the received emails (SyncML, IMAP, POP). If the
* underlying protocol is not able to filter, the implementation must do it
* on the client side.
*/
public class MailFilter {
//---------------------------------------------------------------- Constant
//-------------------------------------------------------------- Attributes
/**
* The maximum size of the message to download: the server should cut the
* message at this limit. It can be interpreted as a gross size by the
* server, with the protocol overhead. So, the actual size of the message
* can be smaller.
*/
private int size;
/**
* Only the messages newer than the date will be retrieved. If a message
* was present on the client with a date older than this, it should be
* removed by the server.
*/
private Date date;
/**
* Ask the server to download the body of the message. If the protocol does
* not support this type of filter headers are automatically discarded.
*
*/
private boolean headersOnly;
/**
* Ask the server to download the attachments too. If the protocol does
* not support this type of filter attachments are automatically discarded.
*
*/
private boolean withAttachments;
//------------------------------------------------------------ Constructors
/**
* Default constructor. Initialize the filter with no filtering active.
*/
public MailFilter() {
size = 0;
date = null;
headersOnly = false;
withAttachments = true;
}
/**
* Full constructor. Initialize the filter with the given values.
* The message-specific filter is always <code>null</code>, and can
* be set separately.
*/
public MailFilter(int size, Date date,
boolean headersOnly, boolean withAttachments) {
this.size = size;
this.date = date;
this.headersOnly = headersOnly;
this.withAttachments = withAttachments;
}
/**
* Copy constructor. Initialize the filter from another one.
*/
public MailFilter(MailFilter other) {
this.size = other.size;
this.date = other.date;
this.withAttachments = other.withAttachments;
}
//---------------------------------------------------------- Public Methods
/**
* Return the current size for the filter.
*/
public int getSize() {
return size;
}
/**
* Return the date from which the messages will be downloaded.
* The date is the one set by setDate() and should be in local time.
*/
public Date getDate() {
return date;
}
/**
* Return true if the headersOnly filter is active.
*/
public boolean isHeadersOnly() {
return headersOnly;
}
/**
* Return true if the attachments are selected for download.
*/
public boolean downloadAttachments() {
return withAttachments;
}
/**
* Set the maximum size of the message to download: the server should cut
* the message at this limit. It can be interpreted as a gross size by the
* server, with the protocol overhead. So, the actual size of the message
* can be smaller.
*
* @param size the size limit to set, or 0 to remove any limit on size.
*/
public void setSize(int size) {
this.size= size;
}
/**
* Set the date from which the messages will be retrieved. If a message
* was present on the client with a date older than this, it should be
* removed by the server (or by the SyncML protocol itself if not supported
*
* @param date the date filter to set, in local time, or null for
* no date filter.
*/
public void setDate(Date date) {
this.date = date;
}
/**
* Ask the server to download the headers only. If the protocol does
* not support this type of filter, it should be discarded.
*
* @param withAttachments true: download attachments with messages
* false: do not download attachments
*/
public void enableHeadersOnly(boolean headersOnly) {
this.headersOnly = headersOnly;
}
/**
* Ask the server to download the attachments too. If the protocol does
* not support this type of filter, the attachments should be discard.
*
* @param withAttachments true: download attachments with messages
* false: do not download attachments
*/
public void enableAttachmentsDownload(boolean withAttachments) {
this.withAttachments= withAttachments;
}
/**
* Override equals method to compare two filters
*/
public boolean equals(MailFilter f) {
if(this.size != f.size){
return false;
}
if(this.date == null) {
if (f.date != null) return false;
}
else {
if (!this.date.equals(f.date)) {
return false;
}
}
if(this.headersOnly != f.headersOnly) {
return false;
}
if(this.withAttachments != f.withAttachments) {
return false;
}
return true;
}
/**
* Override toString to show the content in Log
*/
public String toString() {
StringBuffer sb = new StringBuffer();
sb.append("size: ").append(size)
.append(", date: ").append(
(date != null) ? MailDateFormatter.dateToUTC(date) : "null" )
.append((headersOnly)? " - only headers" : " - headers and body")
.append((withAttachments)? ", with " : ", without ")
.append("attachments");
return sb.toString();
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?