本文整理汇总了Java中javax.mail.Address.toString方法的典型用法代码示例。如果您正苦于以下问题:Java Address.toString方法的具体用法?Java Address.toString怎么用?Java Address.toString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.mail.Address
的用法示例。
在下文中一共展示了Address.toString方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: listFolder
import javax.mail.Address; //导入方法依赖的package包/类
static void listFolder(Folder folder, String tab, boolean recurse)
throws Exception {
folder.open(Folder.READ_WRITE);
System.out.println(tab + "Name: " + folder.getName() + '(' +
folder.getFullName() + ')');
if (!folder.isSubscribed())
System.out.println(tab + "Not Subscribed");
if ((folder.getType() & Folder.HOLDS_MESSAGES) != 0) {
if (folder.hasNewMessages())
System.out.println(tab + "Has New Messages");
else
System.out.println(tab + "No New Messages");
Message[] msgs = folder.getMessages();
for (Message m : msgs) {
Address from = m.getFrom()[0];
String fromAddress;
if (from instanceof InternetAddress)
fromAddress = ((InternetAddress)from).getAddress();
else
fromAddress = from.toString();
StringBuffer sb = new StringBuffer();
fromFmt.format(fromAddress, sb, null);
sb. append(" ");
subjFmt.format(m.getSubject(), sb, null);
System.out.println(sb.toString());
}
}
if ((folder.getType() & Folder.HOLDS_FOLDERS) != 0) {
System.out.println(tab + "Is Directory");
}
if (recurse) {
Folder[] fs = folder.list();
for (Folder f : fs) {
listFolder(f, tab + "", recurse);
}
}
}
示例2: toString
import javax.mail.Address; //导入方法依赖的package包/类
public String toString() {
try {
Address from = m.getFrom()[0];
String fromAddress;
if (from instanceof InternetAddress)
fromAddress = ((InternetAddress)from).getAddress();
else
fromAddress = from.toString();
StringBuffer sb = new StringBuffer();
fromFmt.format(fromAddress, sb, null);
sb. append(" ");
subjFmt.format(m.getSubject(), sb, null);
return sb.toString();
} catch (Exception e) {
return e.toString();
}
}
示例3: getSenderEmail
import javax.mail.Address; //导入方法依赖的package包/类
/**
* Returns the sender email from the provided mail object.
*
* @param mailMessage
* The mail message with the fax data
* @return The sender email
* @throws MessagingException
* Any exception while handling the mail message
*/
protected String getSenderEmail(Message mailMessage) throws MessagingException
{
Address[] addresses=mailMessage.getFrom();
String senderEmail=null;
if((addresses!=null)&&(addresses.length>0))
{
//get sender mail address (only first from is used)
Address address=addresses[0];
//get as string
senderEmail=address.toString();
}
return senderEmail;
}
示例4: processRecipients
import javax.mail.Address; //导入方法依赖的package包/类
protected void processRecipients(Message message) throws Exception {
for (Address recipientAddress: message.getAllRecipients()) {
String recipient = recipientAddress.toString();
int ltIndex = recipient.indexOf('<');
int atIndex = recipient.indexOf('@');
int gtIndex = recipient.indexOf('>');
if ( (ltIndex!=-1)
&& (atIndex!=-1)
&& (gtIndex!=-1)
&& (ltIndex<atIndex)
&& (atIndex<gtIndex) ) {
recipient = recipient.substring(ltIndex+1, gtIndex);
}
recipients.add(recipient);
}
}
示例5: getAddressAsString
import javax.mail.Address; //导入方法依赖的package包/类
private static String getAddressAsString(Address[] addresses) {
StringBuffer addresssb = new StringBuffer();
for (Address address : addresses){
String addressstr = address.toString();
int startIndex = addressstr.indexOf("<");
int endIndex = addressstr.indexOf(">");
if (startIndex != -1 || endIndex != -1) {
addressstr = addressstr.substring(startIndex+1, endIndex);
}
addresssb.append(addressstr);
addresssb.append(";");
}
return addresssb.toString();
}
示例6: toEmail
import javax.mail.Address; //导入方法依赖的package包/类
/**
* @param address The address, hopefully an {@link InternetAddress}
* @return The email address if it can, otherwise the whole address.
*/
private String toEmail(Address address)
{
if (address instanceof InternetAddress)
{
return ((InternetAddress) address).getAddress();
}
else
{
return address.toString();
}
}