/** * Method createMetaContents. * * @param message * @return */ private String createMetaContents(IMessageContext message) { Envelope envelope = message.getEnvelope(); Partition partition = message.getPartition(); StringBuffer buf = new StringBuffer(200); buf.append("Subject: ").append(envelope.getSubject()).append(MetaMessageWriterStage.NEW_LINE); Date sentDate = envelope.getSentDate(); if (sentDate != null) { buf.append("Date: ") .append(MetaMessageWriterStage.s_rfc822DateFormat.format(sentDate)) .append(MetaMessageWriterStage.NEW_LINE); } // If there is a header based sender that was found by the vault box, then use it. // The header based sender is usually in a nicer format "Bob Smith" <*****@*****.**> // instead of just the email address of the sender [email protected] String from; if (envelope.getHeaderBasedSender() != null && envelope.getHeaderBasedSender().length() > 3) { from = envelope.getHeaderBasedSender(); } else { from = envelope.getSender(); } if (from != null) { buf.append("From: ").append(from).append(MetaMessageWriterStage.NEW_LINE); } buf.append("Message-ID: "); buf.append(envelope.getSize()); buf.append("__"); buf.append("&mid="); buf.append(message.getInternalId()); buf.append("&svr="); buf.append(partition.getServer()); buf.append("&p="); buf.append(partition.getId()); buf.append(MetaMessageWriterStage.NEW_LINE); return buf.toString(); }
/** * Method writeMetaFiles. This uses the MailStoreFileManger API to store files remotely. * * @param message */ private boolean writeMetaFiles(IMessageContext message) { String metaContents = createMetaContents(message); String metaFileName = new File(message.getStoreFileSubPath()).getName(); Collection<MailStoreFileManager.MetaMessageDescriptor> msgs = new ArrayList<MailStoreFileManager.MetaMessageDescriptor>(); if (!CollectionsUtils.isNullOrEmpty(message.getResolvedRecipients())) { for (ReplicatedRecipient rr : message.getResolvedRecipients()) { msgs.add( new MailStoreFileManager.MetaMessageDescriptor( message.getInternalId(), rr.getMaildir(), metaFileName, message.getEnvelope().getSentDate(), message.getEnvelope().getReceivedDate(), false, rr.getState().toInt())); } } if (message.getResolvedSender() != null) { ReplicatedRecipient rr = message.getResolvedSender(); msgs.add( new MailStoreFileManager.MetaMessageDescriptor( message.getInternalId(), rr.getMaildir(), metaFileName, message.getEnvelope().getSentDate(), message.getEnvelope().getReceivedDate(), true, rr.getState().toInt())); } IMailStoreFileManager imsfm = ManagementContainer.getInstance().getMailStoreFileManager(); if (imsfm.storeMetaMessage(msgs, metaContents)) { m_importer.audit(message, getName(), metaFileName); return true; } else { m_importer.getStatComponent().addToValue(STAT_META_STORE_FAILURES, 1); m_importer.consumerImportFailed(message, true); return false; } }