use of com.zimbra.common.mime.ContentDisposition in project zm-mailbox by Zimbra.
the class ParsedContact method parseBlob.
private static List<Attachment> parseBlob(InputStream in) throws ServiceException, MessagingException, IOException {
MimeMessage mm = new Mime.FixedMimeMessage(JMSession.getSession(), in);
MimeMultipart multi = null;
try {
multi = (MimeMultipart) mm.getContent();
} catch (ClassCastException x) {
throw ServiceException.FAILURE("MimeMultipart content expected but got " + mm.getContent().toString(), x);
}
List<Attachment> attachments = new ArrayList<Attachment>(multi.getCount());
for (int i = 1; i <= multi.getCount(); i++) {
MimeBodyPart bp = (MimeBodyPart) multi.getBodyPart(i - 1);
ContentDisposition cdisp = new ContentDisposition(bp.getHeader("Content-Disposition", null));
Attachment attachment = new Attachment(bp.getDataHandler(), cdisp.getParameter("field"));
attachment.setPartName(Integer.toString(i));
attachments.add(attachment);
}
return attachments;
}
use of com.zimbra.common.mime.ContentDisposition in project zm-mailbox by Zimbra.
the class ParseMimeMessage method attachUpload.
private static void attachUpload(MimeMultipart mmp, Upload up, String contentID, ParseMessageContext ctxt, ContentType ctypeOverride, String contentDescription, String contentDisposition) throws ServiceException, MessagingException {
// make sure we haven't exceeded the max size
ctxt.incrementSize("upload " + up.getName(), (long) (up.getSize() * 1.33));
// scan upload for viruses
StringBuffer info = new StringBuffer();
UploadScanner.Result result = UploadScanner.accept(up, info);
if (result == UploadScanner.REJECT) {
throw MailServiceException.UPLOAD_REJECTED(up.getName(), info.toString());
} else if (result == UploadScanner.ERROR) {
throw MailServiceException.SCAN_ERROR(up.getName());
}
String filename = up.getName();
// create the part and override the DataSource's default ctype, if required
MimeBodyPart mbp = new ForceBase64MimeBodyPart();
UploadDataSource uds = new UploadDataSource(up);
if (ctypeOverride != null && !ctypeOverride.equals("")) {
uds.setContentType(ctypeOverride);
}
mbp.setDataHandler(new DataHandler(uds));
// set headers -- ctypeOverride non-null has magical properties that I'm going to regret tomorrow
ContentType ctype = ctypeOverride;
ContentDisposition cdisp;
if (Part.INLINE.equalsIgnoreCase(contentDisposition)) {
cdisp = new ContentDisposition(Part.INLINE, ctxt.use2231);
} else {
cdisp = new ContentDisposition(Part.ATTACHMENT, ctxt.use2231);
}
if (ctype == null) {
ctype = new ContentType(up.getContentType() == null ? MimeConstants.CT_APPLICATION_OCTET_STREAM : up.getContentType());
ctype.cleanup().setParameter("name", filename);
cdisp.setParameter("filename", filename);
}
mbp.setHeader("Content-Type", ctype.setCharset(ctxt.defaultCharset).toString());
mbp.setHeader("Content-Disposition", cdisp.setCharset(ctxt.defaultCharset).toString());
if (contentDescription != null) {
mbp.setHeader("Content-Description", contentDescription);
}
if (ctype.getContentType().equals(MimeConstants.CT_APPLICATION_PDF)) {
mbp.setHeader("Content-Transfer-Encoding", "base64");
}
mbp.setContentID(contentID);
// add to the parent part
mmp.addBodyPart(mbp);
}
use of com.zimbra.common.mime.ContentDisposition in project zm-mailbox by Zimbra.
the class CollectLDAPConfigZimbra method doGet.
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
try {
//check the auth token
AuthToken authToken = getAdminAuthTokenFromCookie(req, resp);
if (authToken == null) {
resp.sendError(HttpServletResponse.SC_UNAUTHORIZED);
}
if (!authToken.isAdmin()) {
resp.sendError(HttpServletResponse.SC_UNAUTHORIZED);
}
//find the LDAP master
Provisioning prov = Provisioning.getInstance();
String ldapHost = LC.ldap_host.value();
if (ldapHost == null) {
throw ServiceException.INVALID_REQUEST("Cannot find value for ldap_host in local config", null);
}
Server server = prov.get(Key.ServerBy.name, ldapHost);
if (server == null) {
throw ServiceException.INVALID_REQUEST("Cannot find server record for LDAP master host: " + ldapHost, null);
}
//call RemoteManager
RemoteManager rmgr = RemoteManager.getRemoteManager(server);
RemoteResult rr = rmgr.execute(RemoteCommands.COLLECT_LDAP_ZIMBRA);
//stream the data
resp.setContentType(DOWNLOAD_CONTENT_TYPE);
ContentDisposition cd = new ContentDisposition(Part.INLINE).setParameter("filename", ldapHost + ".ldif.gz");
resp.addHeader("Content-Disposition", cd.toString());
ByteUtil.copy(new ByteArrayInputStream(rr.getMStdout()), true, resp.getOutputStream(), false);
} catch (ServiceException e) {
returnError(resp, e);
return;
}
}
Aggregations