Search in sources :

Example 1 with SieveMailException

use of org.apache.jsieve.mail.SieveMailException in project zm-mailbox by Zimbra.

the class ZimbraMailAdapter method getMatchingHeaderFromAllParts.

/**
 * Scans all MIME parts and returns the values of any headers that
 * match the given name.
 */
public Set<String> getMatchingHeaderFromAllParts(String name) throws SieveMailException {
    MimeMessage msg;
    Set<String> values = new HashSet<String>();
    try {
        msg = handler.getMimeMessage();
        for (MPartInfo partInfo : Mime.getParts(msg)) {
            MimePart part = partInfo.getMimePart();
            values.addAll(Arrays.asList(Mime.getHeaders(part, name)));
        }
    } catch (Exception e) {
        throw new SieveMailException("Unable to match attachment headers.", e);
    }
    return values;
}
Also used : MPartInfo(com.zimbra.cs.mime.MPartInfo) MimeMessage(javax.mail.internet.MimeMessage) SieveMailException(org.apache.jsieve.mail.SieveMailException) MimePart(javax.mail.internet.MimePart) MessagingException(javax.mail.MessagingException) SieveMailException(org.apache.jsieve.mail.SieveMailException) SieveException(org.apache.jsieve.exception.SieveException) AddressException(javax.mail.internet.AddressException) ServiceException(com.zimbra.common.service.ServiceException) ErejectException(com.zimbra.cs.filter.jsieve.ErejectException) IOException(java.io.IOException) HashSet(java.util.HashSet)

Example 2 with SieveMailException

use of org.apache.jsieve.mail.SieveMailException in project zm-mailbox by Zimbra.

the class ZimbraMailAdapter method getHeaderNames.

@Override
public List<String> getHeaderNames() throws SieveMailException {
    Set<String> headerNames = new HashSet<String>();
    MimeMessage msg;
    try {
        msg = handler.getMimeMessage();
    } catch (ServiceException e) {
        ZimbraLog.filter.warn("Unable to get MimeMessage.", e);
        return Collections.emptyList();
    }
    try {
        @SuppressWarnings("unchecked") Enumeration<Header> allHeaders = msg.getAllHeaders();
        while (allHeaders.hasMoreElements()) {
            headerNames.add(allHeaders.nextElement().getName());
        }
        return new ArrayList<String>(headerNames);
    } catch (MessagingException ex) {
        throw new SieveMailException(ex);
    }
}
Also used : ServiceException(com.zimbra.common.service.ServiceException) Header(javax.mail.Header) MimeMessage(javax.mail.internet.MimeMessage) MessagingException(javax.mail.MessagingException) SieveMailException(org.apache.jsieve.mail.SieveMailException) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet)

Aggregations

ServiceException (com.zimbra.common.service.ServiceException)2 HashSet (java.util.HashSet)2 MessagingException (javax.mail.MessagingException)2 MimeMessage (javax.mail.internet.MimeMessage)2 SieveMailException (org.apache.jsieve.mail.SieveMailException)2 ErejectException (com.zimbra.cs.filter.jsieve.ErejectException)1 MPartInfo (com.zimbra.cs.mime.MPartInfo)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Header (javax.mail.Header)1 AddressException (javax.mail.internet.AddressException)1 MimePart (javax.mail.internet.MimePart)1 SieveException (org.apache.jsieve.exception.SieveException)1