Search in sources :

Example 1 with ParseException

use of com.zimbra.cs.mailclient.ParseException in project zm-mailbox by Zimbra.

the class MailboxName method decodePEM.

private static void decodePEM(ByteBuffer bb, StringBuffer sb) throws ParseException {
    try {
        int c = bb.get();
        if (c == '-') {
            sb.append('&');
            return;
        }
        int bits = 0;
        int count = 0;
        do {
            byte b = DECODE_PEM[c & 0xff];
            if (b == -1) {
                throw new ParseException("Invalid Base64 character: " + c);
            }
            bits = bits << 6 | b;
            count += 6;
            if (count > 15) {
                // bits remaining
                count -= 16;
                sb.append((char) (bits >> count));
                bits &= (1 << count) - 1;
            }
        } while ((c = bb.get()) != '-');
        // Discard remaining bits
        if (count > 0 && bits != 0) {
            throw new ParseException("Invalid Base64 encoding");
        }
    } catch (IndexOutOfBoundsException e) {
        throw new ParseException("Unterminated Base64 encoding");
    }
}
Also used : ParseException(com.zimbra.cs.mailclient.ParseException)

Example 2 with ParseException

use of com.zimbra.cs.mailclient.ParseException in project zm-mailbox by Zimbra.

the class AppendResult method parse.

// UIDPLUS (RFC 2359):
// resp_code_apnd ::= "APPENDUID" SPACE nz_number SPACE set
public static AppendResult parse(ImapInputStream is) throws IOException {
    is.skipChar(' ');
    long uidValidity = is.readNZNumber();
    is.skipChar(' ');
    is.skipSpaces();
    String uidSet = is.readText(" ]");
    try {
        return new AppendResult(uidValidity, uidSet);
    } catch (IllegalArgumentException e) {
        throw new ParseException("Invalid APPENDUID result");
    }
}
Also used : ParseException(com.zimbra.cs.mailclient.ParseException)

Example 3 with ParseException

use of com.zimbra.cs.mailclient.ParseException in project zm-mailbox by Zimbra.

the class CopyResult method parse.

public static CopyResult parse(ImapInputStream is) throws IOException {
    is.skipChar(' ');
    long uidValidity = is.readNZNumber();
    is.skipChar(' ');
    is.skipSpaces();
    String fromSet = is.readText(" ");
    is.skipChar(' ');
    is.skipSpaces();
    String toSet = is.readText(" ]");
    try {
        return new CopyResult(uidValidity, fromSet, toSet);
    } catch (IllegalArgumentException e) {
        throw new ParseException("Invalid COPYUID result");
    }
}
Also used : ParseException(com.zimbra.cs.mailclient.ParseException)

Example 4 with ParseException

use of com.zimbra.cs.mailclient.ParseException in project zm-mailbox by Zimbra.

the class Pop3Sync method fetchAndAddMessage.

private void fetchAndAddMessage(int msgno, int size, String uid, boolean allowFilterToMountpoint) throws ServiceException, IOException {
    ContentInputStream cis = null;
    MessageContent mc = null;
    checkIsEnabled();
    try {
        cis = connection.getMessage(msgno);
        mc = MessageContent.read(cis, size);
        ParsedMessage pm = mc.getParsedMessage(null, indexAttachments);
        if (pm == null) {
            LOG.warn("Empty message body for UID %d. Must be ignored.", uid);
            return;
        }
        pm.setDataSourceId(dataSource.getId());
        Message msg = null;
        // bug 47796: Set received date to sent date if available otherwise use current time
        try {
            Date sentDate = pm.getMimeMessage().getSentDate();
            if (sentDate == null) {
                LOG.warn("null sent date; probably due to parse error. Date header value: [%s]", pm.getMimeMessage().getHeader("Date", null));
            }
            pm.setReceivedDate(sentDate != null ? sentDate.getTime() : System.currentTimeMillis());
        } catch (MessagingException e) {
            LOG.warn("unable to get sent date from parsed message due to exception, must use current time", e);
            pm.setReceivedDate(System.currentTimeMillis());
        }
        DeliveryContext dc = mc.getDeliveryContext();
        if (isOffline()) {
            msg = addMessage(null, pm, size, dataSource.getFolderId(), Flag.BITMASK_UNREAD, dc);
        } else {
            Integer localId = getFirstLocalId(RuleManager.applyRulesToIncomingMessage(null, mbox, pm, size, dataSource.getEmailAddress(), dc, dataSource.getFolderId(), true, allowFilterToMountpoint));
            if (localId != null) {
                msg = mbox.getMessageById(null, localId);
            }
        }
        if (msg != null && uid != null) {
            PopMessage msgTracker = new PopMessage(dataSource, msg.getId(), uid);
            msgTracker.add();
        }
    } catch (CommandFailedException e) {
        LOG.warn("Error fetching message number %d: %s", msgno, e.getMessage());
    } finally {
        if (cis != null) {
            try {
                cis.close();
            } catch (ParseException pe) {
                LOG.error("ParseException while closing ContentInputStream. Assuming cis is effectively closed", pe);
            }
        }
        if (mc != null) {
            mc.cleanup();
        }
    }
}
Also used : Message(com.zimbra.cs.mailbox.Message) ParsedMessage(com.zimbra.cs.mime.ParsedMessage) MessagingException(javax.mail.MessagingException) ContentInputStream(com.zimbra.cs.mailclient.pop3.ContentInputStream) ParsedMessage(com.zimbra.cs.mime.ParsedMessage) ParseException(com.zimbra.cs.mailclient.ParseException) DeliveryContext(com.zimbra.cs.mailbox.DeliveryContext) Date(java.util.Date) CommandFailedException(com.zimbra.cs.mailclient.CommandFailedException)

Aggregations

ParseException (com.zimbra.cs.mailclient.ParseException)4 DeliveryContext (com.zimbra.cs.mailbox.DeliveryContext)1 Message (com.zimbra.cs.mailbox.Message)1 CommandFailedException (com.zimbra.cs.mailclient.CommandFailedException)1 ContentInputStream (com.zimbra.cs.mailclient.pop3.ContentInputStream)1 ParsedMessage (com.zimbra.cs.mime.ParsedMessage)1 Date (java.util.Date)1 MessagingException (javax.mail.MessagingException)1