本文整理匯總了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();
}
}