Package org.jasen.error

Examples of org.jasen.error.JasenParseException


  public static boolean verifySenderAddress(DNSResolver dresolver, InetAddressResolver iresolver, ReceivedHeaderParser parser, String receivedHeaderLine, String senderAddress) throws JasenParseException, UnknownHostException, DNSException {

    ReceivedHeaderParserData data = parser.parse(receivedHeaderLine, iresolver);
   
    if(data == null) {
        throw new JasenParseException("Unable to parse header.", ParseErrorType.PARSE_ERROR);
    }

    // Use the InetAddress cache
    InetAddress receiverAddress = iresolver.getByName(data.getSenderIPAddress());
    String senderDomain = getDomainFromAddress(senderAddress);
View Full Code Here


                index++;
            } while (!token.equals("from") && index < split.length);
           
            // If we weren't the first token, throw an exception
            if(index > 1) {
                throw new JasenParseException("'from' token out of place",ParseErrorType.PARSE_ERROR);
            }

            // We should now be at the sender host
            if (index < split.length && token.equals("from")) {
                boolean hostSet = false;
                boolean ipSet = false;

                do {
                    token = split[index];

                    // See if we are a hostname
                    if (DNSUtils.isDomain(token) && !hostSet) {
                        // We have the sender host
                        data.setSenderHostName(token);
                        hostSet = true;
                    } else if (DNSUtils.isIPAddress(token)) {
                        // If this is the first ip.. assume its the host
                        if (!hostSet) {
                            data.setSenderHostName(token);
                        } else if(!ipSet){
                            // Assume its the real ip
                            data.setSenderIPAddress(token);
                            ipSet = true;
                        }
                    }

                    index++;
                } while (!token.equals("by") && index < split.length);

                // Now, look for the recipient data
                if (index < split.length && token.equals("by")) {

                    // Assmume that the next token is the receiver
                    token = split[index];
                    data.setReceiverHostName(token);
                }

            } else {
                throw new JasenParseException("Couldn't locate 'from' token",
                        ParseErrorType.PARSE_ERROR);
            }
        } else {
            throw new JasenParseException(
                    "Couldn't parse header.  No tokens found",
                    ParseErrorType.PARSE_ERROR);
        }
       
        if(data.getSenderIPAddress() == null && data.getSenderHostName() != null) {
View Full Code Here

                message.setHtmlPart ((String) MimeUtils.getPartContent (MimeUtils.getFirstPartFromList (parts, MimeType.TEXT_HTML, null)));

                from = getFromSafe(mm);

                if(from == null) {
                    throw new JasenParseException("Empty from", ParseErrorType.MALFORMED_MIME);
                }

                message.setFrom(from);

                if(mm.getHeader("x-envelope-sender") != null) {
                    message.setEnvelopeSender(mm.getHeader("x-envelope-sender")[0]);
                }
                else
                {
                    message.setEnvelopeSender(message.getFrom().getAddress());
                }

                // Get attachments
                List attachments = MimeUtils.getAllAttachmentParts (parts);

                if (attachments != null && attachments.size () > 0)
                {

                    String[] attachmentNames = new String[attachments.size ()];

                    Iterator i = attachments.iterator ();

                    int count = 0;

                    Part p = null;

                    while (i.hasNext ())
                    {
                        p = (Part) i.next ();
                        try
                        {
                            attachmentNames[count] = p.getFileName ();
                            count++;
                        }
                        catch (MessagingException e)
                        {
                            // Ignore this
                            ErrorHandlerBroker.getInstance().getErrorHandler().handleException(e);
                        }

                    }

                    message.setAttachmentNames (attachmentNames);
                }

            }
            catch (ParseException e)
            {
                throw new JasenParseException (e, ParseErrorType.MALFORMED_MIME);
            }
            catch (UnsupportedEncodingException e)
            {
                throw new JasenParseException (e, ParseErrorType.UNSUPPORTED_ENCODING);
            }
            catch (MessagingException e)
            {
                throw new JasenParseException (e, ParseErrorType.PARSE_ERROR);
            }

            return message;
        }
        catch (IOException e)
        {
            throw new JasenParseException (e, ParseErrorType.PARSE_ERROR);
        }

    }
View Full Code Here

TOP

Related Classes of org.jasen.error.JasenParseException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.