📄 mailfilter.java
字号:
/*
* Copyright (C) 2006-2007 Funambol
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the 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 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 General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
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 + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -