/*
* MessageWrapShow.java
*
* Created on den 23 september 2001, 15:41
*/
package ip1.u9.util;
import javax.mail.*;
import javax.mail.internet.*;
import java.io.IOException;
import javax.mail.MessagingException;
import ip1.u7.b.*;
/** För allmän informaton om MessageWrap-klasserna, se MessageWrap
*
* @author Henrik Johansson, DS80
* @version ht2001
*/
public class MessageWrapShow extends MessageWrap {
/** Skapar nytt MessageWrapShow
* Anropas alltid via MessageWrapFactory
*
* @param message basmeddelande som skall formateras och eventuellt ges tilläggsinformation
*/
protected MessageWrapShow(Message message) {
this(message, null);
}
/** Skapar nytt MessageWrapShow
* Anropas alltid via MessageWrapFactory
*
* @param message basmeddelande som skall formateras och eventuellt ges tilläggsinformation
* @param server Kontoinformation som eventuellt läggs till i meddealnde tex avsändaradress eller signatur
*/
protected MessageWrapShow(Message message, ServerInfo server) {
super(message, server);
}
/** Returnerar basmeddelandets innehåll*/
public String getContent() throws MessagingException, IOException {
return message.getContent().toString();
}
/** Returnerar basmeddelandets ämnesrad*/
public String getSubject() throws MessagingException {
return message.getSubject();
}
/**Returnerar en String-matrsi fylld med basmeddelandets mottagare.
* Primära mottagare föregås av "TO: ".
* Sekundära mottagare föregås av "Cc: ".
*/
public String[] getRecipients() throws MessagingException {
Address[] to = ((MimeMessage) message).getRecipients(Message.RecipientType.TO);
Address[] cc = ((MimeMessage) message).getRecipients(Message.RecipientType.CC);
Address[] bcc = ((MimeMessage) message).getRecipients(Message.RecipientType.BCC);
int tolength = 0;
if(to != null)
tolength = to.length;
int cclength = 0;
if(cc != null)
cclength = cc.length;
int bcclength = 0;
if(bcc != null)
bcclength = bcc.length;
String[] rec = new String[tolength + cclength + bcclength];
for(int i = 0; i < tolength; i++) {
rec[i] = "To: " + to[i].toString();
}
for(int i = 0; i < cclength; i++) {
rec[i + tolength] = "Cc: " + cc[i].toString();
}
for(int i = 0; i < bcclength; i++) {
rec[i + tolength + cclength] = "bcc: " + bcc[i].toString();
}
return rec;
}
/** returnerar en InternetAddress-matris som innehåller basmeddelandets avsändare*/
public InternetAddress[] getFrom() throws MessagingException {
return (InternetAddress[]) ((MimeMessage) message).getFrom();
}
}