use of com.zimbra.cs.mime.MimeHandlerException in project zm-mailbox by Zimbra.
the class TextHtmlHandler method getContentImpl.
@Override
protected String getContentImpl() throws MimeHandlerException {
if (content == null) {
DataSource source = getDataSource();
if (source != null) {
InputStream is = null;
try {
Reader reader = getReader(is = source.getInputStream(), source.getContentType());
content = HtmlTextExtractor.extract(reader, MimeHandlerManager.getIndexedTextLimit());
} catch (Exception e) {
throw new MimeHandlerException(e);
} finally {
ByteUtil.closeStream(is);
}
}
}
if (content == null) {
content = "";
}
return content;
}
use of com.zimbra.cs.mime.MimeHandlerException in project zm-mailbox by Zimbra.
the class TextPlainHandler method getContentImpl.
@Override
protected String getContentImpl() throws MimeHandlerException {
if (content == null) {
DataSource source = getDataSource();
if (source != null) {
String ctype = source.getContentType();
InputStream is = null;
try {
Reader reader = Mime.getTextReader(is = source.getInputStream(), ctype, getDefaultCharset());
content = ByteUtil.getContent(reader, MimeHandlerManager.getIndexedTextLimit(), false);
} catch (IOException e) {
throw new MimeHandlerException(e);
} finally {
ByteUtil.closeStream(is);
}
}
}
if (content == null) {
content = "";
}
return content;
}
use of com.zimbra.cs.mime.MimeHandlerException in project zm-mailbox by Zimbra.
the class MessageRFC822Handler method getContentImpl.
/**
* Returns the subject of the attached message.
*/
@Override
protected String getContentImpl() throws MimeHandlerException {
DataSource ds = getDataSource();
if (ds == null) {
return null;
}
InputStream is = null;
String content = null;
try {
is = ds.getInputStream();
if (is == null) {
return null;
}
InternetHeaders headers = new InternetHeaders(is);
String[] subject = headers.getHeader("Subject");
if (subject == null || subject.length == 0 || subject[0] == null) {
return null;
}
int maxLength = MimeHandlerManager.getIndexedTextLimit();
if (subject[0].length() > maxLength) {
content = subject[0].substring(0, maxLength);
} else {
content = subject[0];
}
} catch (Exception e) {
throw new MimeHandlerException(e);
} finally {
ByteUtil.closeStream(is);
}
return content;
}
use of com.zimbra.cs.mime.MimeHandlerException in project zm-mailbox by Zimbra.
the class TextCalendarHandler method analyze.
private void analyze(boolean needCal) throws MimeHandlerException {
if (mContent != null)
return;
DataSource source = getDataSource();
if (source == null) {
mContent = "";
return;
}
InputStream is = null;
try {
is = source.getInputStream();
String charset = MimeConstants.P_CHARSET_UTF8;
String ctStr = source.getContentType();
if (ctStr != null) {
String cs = Mime.getCharset(ctStr);
if (cs != null)
charset = cs;
}
if (needCal) {
miCalendar = ZCalendarBuilder.build(is, charset);
StringBuilder buf = new StringBuilder(1024);
int maxLength = MimeHandlerManager.getIndexedTextLimit();
for (Iterator<ZComponent> compIter = miCalendar.getComponentIterator(); compIter.hasNext() && buf.length() < maxLength; ) {
ZComponent comp = compIter.next();
for (Iterator<ZProperty> propIter = comp.getPropertyIterator(); propIter.hasNext(); ) {
ZProperty prop = propIter.next();
if (sIndexedProps.contains(prop.getName())) {
String value = prop.getValue();
if (value != null && value.length() > 0) {
if (buf.length() > 0)
buf.append(' ');
buf.append(value);
}
}
}
}
mContent = buf.toString();
} else {
IcsParseHandler handler = new IcsParseHandler();
ZCalendarBuilder.parse(is, charset, handler);
mContent = handler.getContent();
}
} catch (Exception e) {
mContent = "";
ZimbraLog.index.warn("error reading text/calendar mime part", e);
throw new MimeHandlerException(e);
} finally {
ByteUtil.closeStream(is);
}
}
Aggregations