Search in sources :

Example 6 with MimeException

use of org.apache.james.mime4j.MimeException in project webservices-axiom by apache.

the class MultipartBody method getNextPart.

PartImpl getNextPart() {
    if (currentPart != null) {
        currentPart.fetch();
    }
    if (parser.getState() == EntityState.T_END_MULTIPART) {
        currentPart = null;
    } else {
        String partContentID = null;
        boolean isRootPart;
        try {
            checkParserState(parser.next(), EntityState.T_START_HEADER);
            List<Header> headers = new ArrayList<Header>();
            while (parser.next() == EntityState.T_FIELD) {
                Field field = parser.getField();
                String name = field.getName();
                String value = field.getBody();
                if (log.isDebugEnabled()) {
                    log.debug("addHeader: (" + name + ") value=(" + value + ")");
                }
                headers.add(new Header(name, value));
                if (partContentID == null && name.equalsIgnoreCase("Content-ID")) {
                    partContentID = normalizeContentID(value);
                }
            }
            checkParserState(parser.next(), EntityState.T_BODY);
            if (rootPartContentID == null) {
                isRootPart = firstPart == null;
            } else {
                isRootPart = rootPartContentID.equals(partContentID);
            }
            PartImpl part = new PartImpl(this, isRootPart ? MemoryBlob.FACTORY : attachmentBlobFactory, partContentID, headers, parser);
            if (currentPart == null) {
                firstPart = part;
            } else {
                currentPart.setNextPart(part);
            }
            currentPart = part;
        } catch (IOException ex) {
            throw new MIMEException(ex);
        } catch (MimeException ex) {
            throw new MIMEException(ex);
        }
        partCount++;
        if (partContentID != null) {
            if (partMap.containsKey(partContentID)) {
                throw new MIMEException("Two MIME parts with the same Content-ID not allowed.");
            }
            partMap.put(partContentID, currentPart);
        }
        if (isRootPart) {
            rootPart = currentPart;
        }
        if (partCreationListener != null) {
            partCreationListener.partCreated(currentPart);
        }
    }
    return currentPart;
}
Also used : Field(org.apache.james.mime4j.stream.Field) ArrayList(java.util.ArrayList) MimeException(org.apache.james.mime4j.MimeException) IOException(java.io.IOException)

Example 7 with MimeException

use of org.apache.james.mime4j.MimeException in project webservices-axiom by apache.

the class PartImpl method discard.

@Override
public void discard() {
    try {
        switch(state) {
            case STATE_UNREAD:
                EntityState parserState;
                do {
                    parserState = parser.next();
                } while (parserState != EntityState.T_START_BODYPART && parserState != EntityState.T_END_MULTIPART);
                state = STATE_DISCARDED;
                break;
            case STATE_BUFFERED:
                content.release();
        }
    } catch (MimeException ex) {
        throw new MIMEException(ex);
    } catch (IOException ex) {
        throw new MIMEException(ex);
    }
}
Also used : MimeException(org.apache.james.mime4j.MimeException) EntityState(org.apache.james.mime4j.stream.EntityState) IOException(java.io.IOException)

Example 8 with MimeException

use of org.apache.james.mime4j.MimeException in project webservices-axiom by apache.

the class PartImpl method moveToNextPart.

private void moveToNextPart() {
    try {
        checkParserState(parser.next(), EntityState.T_END_BODYPART);
        EntityState state = parser.next();
        if (state == EntityState.T_EPILOGUE) {
            while (parser.next() != EntityState.T_END_MULTIPART) {
            // Just loop
            }
        } else if (state != EntityState.T_START_BODYPART && state != EntityState.T_END_MULTIPART) {
            throw new IllegalStateException("Internal error: unexpected parser state " + state);
        }
    } catch (IOException ex) {
        throw new MIMEException(ex);
    } catch (MimeException ex) {
        throw new MIMEException(ex);
    }
    parser = null;
}
Also used : MimeException(org.apache.james.mime4j.MimeException) EntityState(org.apache.james.mime4j.stream.EntityState) IOException(java.io.IOException)

Example 9 with MimeException

use of org.apache.james.mime4j.MimeException in project Gargoyle by callakrsos.

the class MimeToHtmlAdapter method getContent.

/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.kyj.fx.voeditor.visual.framework.word.AbstractMimeAdapter#getContent(
	 * )
	 */
@Override
public String getContent() {
    StringBuilder sb = new StringBuilder();
    try {
        final MessageBuilder builder = new DefaultMessageBuilder();
        Message message = builder.parseMessage(new ByteArrayInputStream(this.content));
        Body body = ((Entity) message).getBody();
        append(sb, body);
    } catch (MimeException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return sb.toString();
}
Also used : Entity(org.apache.james.mime4j.dom.Entity) StringBuilder(scala.collection.mutable.StringBuilder) MessageBuilder(org.apache.james.mime4j.dom.MessageBuilder) DefaultMessageBuilder(org.apache.james.mime4j.message.DefaultMessageBuilder) Message(org.apache.james.mime4j.dom.Message) ByteArrayInputStream(java.io.ByteArrayInputStream) DefaultMessageBuilder(org.apache.james.mime4j.message.DefaultMessageBuilder) MimeException(org.apache.james.mime4j.MimeException) IOException(java.io.IOException) BinaryBody(org.apache.james.mime4j.dom.BinaryBody) Body(org.apache.james.mime4j.dom.Body) TextBody(org.apache.james.mime4j.dom.TextBody)

Example 10 with MimeException

use of org.apache.james.mime4j.MimeException in project Gargoyle by callakrsos.

the class MimeToHtmlWordAdapter method getContent.

/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.kyj.fx.voeditor.visual.framework.word.AbstractMimeAdapter#getContent(
	 * )
	 */
@Override
public String getContent() {
    StringBuilder sb = new StringBuilder();
    try {
        final MessageBuilder builder = new DefaultMessageBuilder();
        Message message = builder.parseMessage(new ByteArrayInputStream(this.content));
        Body body = ((Entity) message).getBody();
        append(sb, body);
    } catch (MimeException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return sb.toString();
}
Also used : Entity(org.apache.james.mime4j.dom.Entity) StringBuilder(scala.collection.mutable.StringBuilder) MessageBuilder(org.apache.james.mime4j.dom.MessageBuilder) DefaultMessageBuilder(org.apache.james.mime4j.message.DefaultMessageBuilder) Message(org.apache.james.mime4j.dom.Message) ByteArrayInputStream(java.io.ByteArrayInputStream) DefaultMessageBuilder(org.apache.james.mime4j.message.DefaultMessageBuilder) MimeException(org.apache.james.mime4j.MimeException) IOException(java.io.IOException) BinaryBody(org.apache.james.mime4j.dom.BinaryBody) Body(org.apache.james.mime4j.dom.Body) TextBody(org.apache.james.mime4j.dom.TextBody)

Aggregations

MimeException (org.apache.james.mime4j.MimeException)14 IOException (java.io.IOException)8 MimeStreamParser (org.apache.james.mime4j.parser.MimeStreamParser)4 SAXException (org.xml.sax.SAXException)4 MessagingException (com.fsck.k9.mail.MessagingException)3 ByteArrayInputStream (java.io.ByteArrayInputStream)3 Entity (org.apache.james.mime4j.dom.Entity)3 Message (org.apache.james.mime4j.dom.Message)3 MessageBuilder (org.apache.james.mime4j.dom.MessageBuilder)3 TextBody (org.apache.james.mime4j.dom.TextBody)3 DefaultMessageBuilder (org.apache.james.mime4j.message.DefaultMessageBuilder)3 MimeConfig (org.apache.james.mime4j.stream.MimeConfig)3 ArrayList (java.util.ArrayList)2 BinaryBody (org.apache.james.mime4j.dom.BinaryBody)2 Body (org.apache.james.mime4j.dom.Body)2 Mailbox (org.apache.james.mime4j.dom.address.Mailbox)2 EOLConvertingInputStream (org.apache.james.mime4j.io.EOLConvertingInputStream)2 EntityState (org.apache.james.mime4j.stream.EntityState)2 TikaInputStream (org.apache.tika.io.TikaInputStream)2 StringBuilder (scala.collection.mutable.StringBuilder)2