use of com.zimbra.cs.store.MailboxBlob in project zm-mailbox by Zimbra.
the class TestDocumentServer method getBlobDir.
private File getBlobDir(Document doc) throws Exception {
MailboxBlob mblob = StoreManager.getInstance().getMailboxBlob(doc);
File blobFile = mblob.getLocalBlob().getFile();
return blobFile.getParentFile();
}
use of com.zimbra.cs.store.MailboxBlob in project zm-mailbox by Zimbra.
the class VerifyStoreManager method testStore.
private void testStore() throws Exception {
ParsedMessage pm = getMessage(1024);
byte[] mimeBytes = readInputStream(pm.getRawInputStream());
Mailbox mbox = MailboxManager.getInstance().getMailboxByAccount(AccountTestUtil.getAccount(USER_NAME));
StoreManager sm = StoreManager.getInstance();
Blob blob = sm.storeIncoming(pm.getRawInputStream());
assertEquals("blob size = message size", pm.getRawData().length, blob.getRawSize());
assertTrue("blob content = mime content", bytesEqual(mimeBytes, readInputStream(blob.getInputStream())));
StagedBlob staged = sm.stage(blob, mbox);
assertEquals("staged size = blob size", blob.getRawSize(), staged.getSize());
MailboxBlob mblob = sm.link(staged, mbox, 0, 0);
assertEquals("link size = staged size", staged.getSize(), mblob.getSize());
assertTrue("link content = mime content", bytesEqual(mimeBytes, readInputStream(mblob.getLocalBlob().getInputStream())));
mblob = sm.getMailboxBlob(mbox, 0, 0, staged.getLocator());
assertEquals("mblob size = staged size", staged.getSize(), mblob.getSize());
assertTrue("mailboxblob content = mime content", bytesEqual(mimeBytes, readInputStream(mblob.getLocalBlob().getInputStream())));
sm.delete(mblob);
}
use of com.zimbra.cs.store.MailboxBlob in project zm-mailbox by Zimbra.
the class SpamHandler method sendReport.
private void sendReport(SpamReport sr) throws ServiceException, MessagingException {
Config config = Provisioning.getInstance().getConfig();
String isSpamString = sr.isSpam ? config.getSpamReportTypeSpam() : config.getSpamReportTypeHam();
SMTPMessage out = new SMTPMessage(JMSession.getSmtpSession());
Mailbox mbox = MailboxManager.getInstance().getMailboxById(sr.mailboxId);
Message msg = mbox.getMessageById(null, sr.messageId);
MimeMultipart mmp = new ZMimeMultipart("mixed");
MimeBodyPart infoPart = new ZMimeBodyPart();
infoPart.setHeader("Content-Description", "Zimbra spam classification report");
String body = String.format("Classified-By: %s\r\n" + "Classified-As: %s\r\n" + "Action: %s\r\n" + "Source-Folder: %s\r\n" + "Destination-Folder: %s\r\n" + "Destination-Mailbox: %s\r\n", Strings.nullToEmpty(sr.accountName), isSpamString, Strings.nullToEmpty(sr.action), Strings.nullToEmpty(sr.sourceFolder), Strings.nullToEmpty(sr.destFolder), Strings.nullToEmpty(sr.destAccountName));
infoPart.setText(body);
mmp.addBodyPart(infoPart);
MailboxBlob blob = msg.getBlob();
MimeBodyPart mbp = new ZMimeBodyPart();
mbp.setDataHandler(new DataHandler(new MailboxBlobDataSource(blob)));
mbp.setHeader("Content-Type", MimeConstants.CT_MESSAGE_RFC822);
mbp.setHeader("Content-Disposition", Part.ATTACHMENT);
mmp.addBodyPart(mbp);
out.setContent(mmp);
out.addHeader(config.getSpamReportSenderHeader(), sr.accountName);
out.addHeader(config.getSpamReportTypeHeader(), isSpamString);
if (config.isSmtpSendAddOriginatingIP() && sr.origIp != null)
out.addHeader(MailSender.X_ORIGINATING_IP, MailSender.formatXOrigIpHeader(sr.origIp));
out.setRecipient(javax.mail.Message.RecipientType.TO, sr.reportRecipient);
out.setEnvelopeFrom(config.getSpamReportEnvelopeFrom());
out.setSubject(config.getSpamTrainingSubjectPrefix() + " " + sr.accountName + ": " + isSpamString);
Transport.send(out);
ZimbraLog.misc.info("Sent " + sr);
}
use of com.zimbra.cs.store.MailboxBlob in project zm-mailbox by Zimbra.
the class Document method generateIndexData.
@Override
public List<IndexDocument> generateIndexData() throws TemporaryIndexingException {
try {
MailboxBlob mblob = getBlob();
if (mblob == null) {
ZimbraLog.index.warn("Unable to fetch blob for Document id=%d,ver=%d,vol=%s", mId, mVersion, getLocator());
throw new MailItem.TemporaryIndexingException();
}
ParsedDocument pd = null;
pd = new ParsedDocument(mblob.getLocalBlob(), getName(), getContentType(), getChangeDate(), getCreator(), getDescription(), isDescriptionEnabled());
if (pd.hasTemporaryAnalysisFailure()) {
throw new MailItem.TemporaryIndexingException();
}
IndexDocument doc = pd.getDocument();
if (doc != null) {
List<IndexDocument> toRet = new ArrayList<IndexDocument>(1);
toRet.add(doc);
return toRet;
} else {
return new ArrayList<IndexDocument>(0);
}
} catch (IOException e) {
ZimbraLog.index.warn("Error generating index data for Wiki Document " + getId() + ". Item will not be indexed", e);
return new ArrayList<IndexDocument>(0);
} catch (ServiceException e) {
ZimbraLog.index.warn("Error generating index data for Wiki Document " + getId() + ". Item will not be indexed", e);
return new ArrayList<IndexDocument>(0);
}
}
use of com.zimbra.cs.store.MailboxBlob in project zm-mailbox by Zimbra.
the class AbstractExternalStoreManagerTest method testUncachedFile.
@Test
public void testUncachedFile() throws Exception {
ParsedMessage pm = ThreaderTest.getRootMessage();
byte[] mimeBytes = TestUtil.readInputStream(pm.getRawInputStream());
Mailbox mbox = MailboxManager.getInstance().getMailboxByAccountId(MockProvisioning.DEFAULT_ACCOUNT_ID);
StoreManager sm = StoreManager.getInstance();
Blob blob = sm.storeIncoming(pm.getRawInputStream());
StagedBlob staged = sm.stage(blob, mbox);
MailboxBlob mblob = sm.link(staged, mbox, 0, 0);
mblob = sm.getMailboxBlob(mbox, 0, 0, staged.getLocator());
Blob localBlob = mblob.getLocalBlob();
InputStream stream = sm.getContent(localBlob);
Assert.assertTrue("input stream external", stream instanceof BlobInputStream);
if (sm instanceof ExternalStoreManager) {
((ExternalStoreManager) sm).clearCache();
}
blob.getFile().delete();
Assert.assertFalse(blob.getFile().exists());
//now get it again. this would bomb if it only looked in cache
stream = sm.getContent(mblob.getLocalBlob());
Assert.assertTrue("input stream external", stream instanceof ExternalBlobInputStream);
ExternalBlobInputStream extStream = (ExternalBlobInputStream) stream;
File file = extStream.getRootFile();
Assert.assertTrue(file.exists());
Assert.assertTrue("stream content = mime content", TestUtil.bytesEqual(mimeBytes, stream));
}
Aggregations