/**
* Notification by Pop3Driver when a (response) email message arrives.
* Enforced by I_ResponseListener
*/
public void incomingMessage(String requestId, Object response) {
EmailData emailData = (EmailData) response;
AttachmentHolder msgUnitAttachmentHolder = null;
String pop3Url = null;
try {
pop3Url = getPop3Driver().getPop3Url(); // for logging only
msgUnitAttachmentHolder =
emailData.getMsgUnitAttachment(); // "*.xbf", "*.xbfz", "*.xmlz", ...
} catch (Throwable e) {
log.warning("Error parsing email data from "
+ pop3Url
+ ", please check the format: "
+ e.toString());
return;
}
if (msgUnitAttachmentHolder == null) {
log.warning("Got email from POP3 but there was no MsgUnit attachment, we ignore it: " + emailData.toXml(true));
return;
}
byte[] encodedMsgUnit = msgUnitAttachmentHolder.getContent();
MsgInfo[] msgInfos = null;
try {
if (MsgInfo.isCompressed(msgUnitAttachmentHolder.getFileName(), msgUnitAttachmentHolder.getContentType())) {
// Decompress the bytes
int length = encodedMsgUnit.length;
this.decompressor.reset();
this.decompressor.setInput(encodedMsgUnit, 0, length);
byte[] buf = new byte[2048+length];
ByteArrayOutputStream out = new ByteArrayOutputStream(2048+length);
while (!this.decompressor.finished()) {
int resultLength = this.decompressor.inflate(buf);
if (resultLength > 0)
out.write(buf, 0, resultLength);
}
encodedMsgUnit = out.toByteArray();
if (log.isLoggable(Level.FINE)) log.fine("Decompressed message from " + length + " to " + encodedMsgUnit.length + " bytes");
}
String parserClassName = MsgInfoParserFactory.instance().guessParserName(msgUnitAttachmentHolder.getFileName(), msgUnitAttachmentHolder.getContentType());
msgInfos = MsgInfo.parse(glob, this.progressListener, encodedMsgUnit, parserClassName, this.pluginConfig);
if (msgInfos.length < 1) {
// spam?
log.warning("Unexpected msgInfo with length==0, requestId=" + requestId + " data=" + emailData.toXml(true));
Thread.dumpStack();
return;
}
for (int j=0; j<msgInfos.length; j++) {
MsgInfo msgInfo = msgInfos[j];
msgInfo.setRequestIdGuessed(emailData.isRequestIdFromSentDate());
msgInfo.setBounceObject(BOUNCE_MAILFROM_KEY, emailData.getFrom());
// The messageId could be in the subject and not in the attachment
msgInfo.setBounceObject(BOUNCE_MESSAGEID_KEY, emailData.getMessageId(messageIdFileName));
AttachmentHolder[] attachments = emailData.getAttachments();
for (int i=0; i<attachments.length; i++) {
AttachmentHolder a = attachments[i];
if (a == msgUnitAttachmentHolder)
continue;
// TODO: Determine which attachments to bounce
msgInfo.setBounceObject(a.getFileName(), a);
}
}
} catch (Throwable e) {
log.warning("Error parsing email data from "
+ pop3Url
+ ", check if client and server have identical compression settings: "
+ e.toString() + ": " + emailData.toXml(true));
return;
}
// Response and Exception messages should NEVER expire
if (emailData.isExpired(messageIdFileName) && msgInfos[0].isInvoke()) {
log.warning("Message is expired, we discard it: " + emailData.toString());
return;
}
// For XmlScript && INVOKE we could have multiple message bundled
// else length is always 1!
for (int i=0; i<msgInfos.length; i++) {
MsgInfo msgInfo = msgInfos[i];
// If counterside has stripped information we add it again from the messageId attachment
if (msgInfo.getRequestId().length() == 0)
msgInfo.setRequestId(emailData.getRequestId(messageIdFileName));
if (msgInfo.getSecretSessionId().length() == 0)
msgInfo.setSecretSessionId(emailData.getSessionId(messageIdFileName));
try {
if (i==0 && msgInfo.isInvoke()) {
if (isLoopingMail(msgInfo, emailData))
return;