Search in sources :

Example 6 with ParsedDocument

use of com.zimbra.cs.mime.ParsedDocument in project zm-mailbox by Zimbra.

the class SaveDocument method redo.

@Override
public void redo() throws Exception {
    Mailbox mbox = MailboxManager.getInstance().getMailboxById(getMailboxId());
    try {
        ParsedDocument pd = new ParsedDocument(getAdditionalDataStream(), mFilename, mMimeType, System.currentTimeMillis(), mAuthor, mDescription, mDescEnabled);
        mbox.createDocument(getOperationContext(), getFolderId(), pd, type, getFlags());
    } catch (MailServiceException e) {
        if (e.getCode() == MailServiceException.ALREADY_EXISTS) {
            mLog.info("Document " + getMessageId() + " is already in mailbox " + mbox.getId());
            return;
        } else {
            throw e;
        }
    }
}
Also used : Mailbox(com.zimbra.cs.mailbox.Mailbox) ParsedDocument(com.zimbra.cs.mime.ParsedDocument) MailServiceException(com.zimbra.cs.mailbox.MailServiceException)

Example 7 with ParsedDocument

use of com.zimbra.cs.mime.ParsedDocument in project zm-mailbox by Zimbra.

the class NativeFormatter method saveDocument.

private void saveDocument(Blob blob, UserServletContext context, String contentType, Folder folder, String filename, InputStream is) throws IOException, ServiceException, UserServletException {
    Mailbox mbox = folder.getMailbox();
    MailItem item = null;
    String creator = context.getAuthAccount() == null ? null : context.getAuthAccount().getName();
    ParsedDocument pd = null;
    try {
        if (contentType == null) {
            contentType = MimeDetect.getMimeDetect().detect(filename);
            if (contentType == null)
                contentType = MimeConstants.CT_APPLICATION_OCTET_STREAM;
        }
        pd = new ParsedDocument(blob, filename, contentType, System.currentTimeMillis(), creator, context.req.getHeader("X-Zimbra-Description"), true);
        item = mbox.getItemByPath(context.opContext, filename, folder.getId());
        // XXX: should we just overwrite here instead?
        if (!(item instanceof Document))
            throw new UserServletException(HttpServletResponse.SC_BAD_REQUEST, "cannot overwrite existing object at that path");
        // scan upload for viruses
        StringBuffer info = new StringBuffer();
        UploadScanner.Result result = UploadScanner.acceptStream(is, info);
        if (result == UploadScanner.REJECT)
            throw MailServiceException.UPLOAD_REJECTED(filename, info.toString());
        if (result == UploadScanner.ERROR)
            throw MailServiceException.SCAN_ERROR(filename);
        item = mbox.addDocumentRevision(context.opContext, item.getId(), pd);
    } catch (NoSuchItemException nsie) {
        item = mbox.createDocument(context.opContext, folder.getId(), pd, MailItem.Type.DOCUMENT, 0);
    }
    sendZimbraHeaders(context, context.resp, item);
}
Also used : MailItem(com.zimbra.cs.mailbox.MailItem) Mailbox(com.zimbra.cs.mailbox.Mailbox) ParsedDocument(com.zimbra.cs.mime.ParsedDocument) UserServletException(com.zimbra.cs.service.UserServletException) ParsedDocument(com.zimbra.cs.mime.ParsedDocument) Document(com.zimbra.cs.mailbox.Document) UploadScanner(com.zimbra.cs.service.mail.UploadScanner) NoSuchItemException(com.zimbra.cs.mailbox.MailServiceException.NoSuchItemException)

Example 8 with ParsedDocument

use of com.zimbra.cs.mime.ParsedDocument 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);
    }
}
Also used : IndexDocument(com.zimbra.cs.index.IndexDocument) MailboxBlob(com.zimbra.cs.store.MailboxBlob) ParsedDocument(com.zimbra.cs.mime.ParsedDocument) ServiceException(com.zimbra.common.service.ServiceException) ArrayList(java.util.ArrayList) IOException(java.io.IOException)

Example 9 with ParsedDocument

use of com.zimbra.cs.mime.ParsedDocument in project zm-mailbox by Zimbra.

the class Document method create.

static Document create(int id, String uuid, Folder folder, String filename, String type, ParsedDocument pd, CustomMetadata custom, int flags, MailItem parent) throws ServiceException {
    assert (id != Mailbox.ID_AUTO_INCREMENT);
    Mailbox mbox = folder.getMailbox();
    UnderlyingData data = prepareCreate(Type.DOCUMENT, id, uuid, folder, filename, type, pd, null, custom, flags);
    if (parent != null) {
        data.parentId = parent.mId;
    }
    data.contentChanged(mbox);
    ZimbraLog.mailop.info("Adding Document %s: id=%d, folderId=%d, folderName=%s", filename, data.id, folder.getId(), folder.getName());
    new DbMailItem(mbox).create(data);
    Document doc = new Document(mbox, data);
    doc.finishCreation(parent);
    pd.setVersion(doc.getVersion());
    return doc;
}
Also used : DbMailItem(com.zimbra.cs.db.DbMailItem) IndexDocument(com.zimbra.cs.index.IndexDocument) ParsedDocument(com.zimbra.cs.mime.ParsedDocument)

Example 10 with ParsedDocument

use of com.zimbra.cs.mime.ParsedDocument in project zm-mailbox by Zimbra.

the class DumpsterTest method createDocument.

private MailItem createDocument(String name, String content) throws Exception {
    InputStream in = new ByteArrayInputStream(content.getBytes());
    ParsedDocument pd = new ParsedDocument(in, name, "text/plain", System.currentTimeMillis(), null, null);
    return mbox.createDocument(null, folder.getId(), pd, MailItem.Type.DOCUMENT, 0);
}
Also used : ParsedDocument(com.zimbra.cs.mime.ParsedDocument) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream)

Aggregations

ParsedDocument (com.zimbra.cs.mime.ParsedDocument)18 ByteArrayInputStream (java.io.ByteArrayInputStream)9 InputStream (java.io.InputStream)7 Document (com.zimbra.cs.mailbox.Document)6 Mailbox (com.zimbra.cs.mailbox.Mailbox)6 IOException (java.io.IOException)6 ServiceException (com.zimbra.common.service.ServiceException)4 IndexDocument (com.zimbra.cs.index.IndexDocument)4 MailItem (com.zimbra.cs.mailbox.MailItem)3 MailboxBlob (com.zimbra.cs.store.MailboxBlob)3 Test (org.junit.Test)3 DbMailItem (com.zimbra.cs.db.DbMailItem)2 MailServiceException (com.zimbra.cs.mailbox.MailServiceException)2 NoSuchItemException (com.zimbra.cs.mailbox.MailServiceException.NoSuchItemException)2 SaveDocument (com.zimbra.cs.redolog.op.SaveDocument)2 UserServletException (com.zimbra.cs.service.UserServletException)2 UploadScanner (com.zimbra.cs.service.mail.UploadScanner)2 MailboxBlobInfo (com.zimbra.cs.store.MailboxBlob.MailboxBlobInfo)2 MailboxBlobDataSource (com.zimbra.cs.store.MailboxBlobDataSource)2 StagedBlob (com.zimbra.cs.store.StagedBlob)2