📄 message.java
字号:
import java.util.*;
public class Message
{
/**
* 所有的数组初始化长度为0
*/
public Message()
{ recipientTO = new Address[0];
recipientCC = new Address[0];
recipientBCC = new Address[0];
}
/**
*添加新的email地址到列表中
*/
public void addRecipient( int type,Address address)
{
Address[] tempAddr = new Address[1];
tempAddr[0] = address;
addRecipients(type,tempAddr );
}
/**
*添加多个email地址到列表中
*/
public void addRecipients( int type,Address[] addresses)
{
//int newSize;
if( type == RecipientType.TO )
recipientTO = addArray( RecipientType.TO,recipientTO,addresses );
else if( type == RecipientType.CC )
recipientCC = addArray( RecipientType.CC,recipientCC,addresses );
else if( type == RecipientType.BCC )
recipientBCC = addArray( RecipientType.BCC,recipientBCC,addresses );
}
/**
* 合并两个地址数组.
*/
private Address[] addArray( int type,Address[] array1,Address[] array2 )
{
int i,j;
Address[] tempAddr = new Address[array1.length + array2.length];
for( i=0; i<array1.length; i++ )
tempAddr[i] = array1[i];
for( j=i; j<(array2.length+i); j++ )
tempAddr[j] = array2[j-i];
Address[] a = tempAddr;
return a;
}
/**
* 返回指定的数组.
*/
public Address[] getRecipients( int type )
{ if( type == RecipientType.TO )
return this.recipientTO;
else if( type == RecipientType.CC )
return this.recipientCC;
else //if( type == RecipientType.BCC )
return this.recipientBCC;
}
/**
*从地址数组中返回
*/
public Address[] getFrom( )
{ Address[] tempAddr = new Address[1];
tempAddr[0] = from;
return tempAddr;
}
/**
* 返回信息对象
*/
public String getSubject( )
{ return subject;
}
/**
* 返回信息文本
*/
public String getText( )
{ return msgText;
}
public void setFrom( Address address )
{ from = address;//设置地址
}
/**
*此方法设置接收对象,并重置所有被保存的信息
*/
public void setRecipient( int type,Address address )
{ Address[] tempAddr = new Address[1];
tempAddr[0] = address;
setRecipients( type,tempAddr );
}
/**
*此方法设置多个接收对象。并重置所有被保存的信息
*/
public void setRecipients( int type,Address[] addresses )
{
if( type == RecipientType.TO )
this.recipientTO = addresses;
else if( type == RecipientType.CC )
this.recipientCC = addresses;
else if( type == RecipientType.BCC )
this.recipientBCC = addresses;
}
/**
* 设置email对象
*/
public void setSubject( String subject )
{ this.subject = subject;
if( this.subject == null )
this.subject = " ";
}
/**
* 设置email的文本信息
*/
public void setText( String msgText )
{ this.msgText = msgText;
}
//数据
private Address from;
private Address[] recipientTO;
private Address[] recipientCC;
private Address[] recipientBCC;
private String subject;
private String msgText;
//private Address[] replyTo; (目前不支持)
//private Date sentDate; (目前不支持)
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -