Package javax.mail.internet

Examples of javax.mail.internet.AddressException


    private int parseUnquotedLocalPartOrThrowException(StringBuffer localPartSB, String address, int pos)
            throws AddressException {
        pos = parseUnquotedLocalPart(localPartSB, address, pos);
        if (localPartSB.toString().length() == 0) {
            throw new AddressException("No local-part (user account) found at position " +
                    (pos + 1) + " in '" + address + "'", address, pos + 1);
        }
        return pos;
    }
View Full Code Here


    private int parseQuotedLocalPartOrThrowException(StringBuffer localPartSB, String address, int pos)
            throws AddressException {
        pos = parseQuotedLocalPart(localPartSB, address, pos);
        if (localPartSB.toString().length() == 2) {
            throw new AddressException("No quoted local-part (user account) found at position " +
                    (pos + 2) + " in '" + address + "'", address, pos + 2);
        }
        return pos;
    }
View Full Code Here

                resultSB.append('\\');
                pos++;
                //<x> ::= any one of the 128 ASCII characters (no exceptions)
                char x = address.charAt(pos);
                if (x < 0 || x > 127) {
                    throw new AddressException("Invalid \\ syntaxed character at position " +
                            (pos + 1) + " in '" + address + "'", address, pos + 1);
                }
                resultSB.append(x);
                pos++;
            } else {
                //<q> ::= any one of the 128 ASCII characters except <CR>,
                //<LF>, quote ("), or backslash (\)
                char q = address.charAt(pos);
                if (q <= 0 || q == '\n' || q == '\r' || q == '\"' || q == '\\') {
                    throw new AddressException("Unquoted local-part (user account) must be one of the 128 ASCI " +
                            "characters exception <CR>, <LF>, quote (\"), or backslash (\\) at position " +
                            (pos + 1) + " in '" + address + "'");
                }
                resultSB.append(q);
                pos++;
View Full Code Here

                resultSB.append('\\');
                pos++;
                //<x> ::= any one of the 128 ASCII characters (no exceptions)
                char x = address.charAt(pos);
                if (x < 0 || x > 127) {
                    throw new AddressException("Invalid \\ syntaxed character at position " + (pos + 1) +
                            " in '" + address + "'", address, pos + 1);
                }
                resultSB.append(x);
                pos++;
                lastCharDot = false;
            } else if (address.charAt(pos) == '.') {
                if (pos == 0) {
                    throw new AddressException("Local part must not start with a '.'");
                }
                resultSB.append('.');
                pos++;
                lastCharDot = true;
            } else if (address.charAt(pos) == '@') {
                //End of local-part
                break;
            } else {
                //<c> ::= any one of the 128 ASCII characters, but not any
                //    <special> or <SP>
                //<special> ::= "<" | ">" | "(" | ")" | "[" | "]" | "\" | "."
                //    | "," | ";" | ":" | "@"  """ | the control
                //    characters (ASCII codes 0 through 31 inclusive and
                //    127)
                //<SP> ::= the space character (ASCII code 32)
                char c = address.charAt(pos);
                if (c <= 31 || c >= 127 || c == ' ') {
                    throw new AddressException("Invalid character in local-part (user account) at position " +
                            (pos + 1) + " in '" + address + "'", address, pos + 1);
                }
                int i = 0;
                while (i < SPECIAL.length) {
                    if (c == SPECIAL[i]) {
                        throw new AddressException("Invalid character in local-part (user account) at position " +
                                (pos + 1) + " in '" + address + "'", address, pos + 1);
                    }
                    i++;
                }
                resultSB.append(c);
                pos++;
                lastCharDot = false;
            }
        }
        if (lastCharDot) {
            throw new AddressException("local-part (user account) ended with a \".\", which is invalid in address '" +
                    address + "'", address, pos);
        }
        lpSB.append(resultSB);
        return pos;
    }
View Full Code Here

            char d = address.charAt(pos);
            if (d == '.') {
                break;
            }
            if (d < '0' || d > '9') {
                throw new AddressException("In domain, did not find a number in # address at position " +
                        (pos + 1) + " in '" + address + "'", address, pos + 1);
            }
            resultSB.append(d);
            pos++;
        }
        if (resultSB.length() < 2) {
            throw new AddressException("In domain, did not find a number in # address at position " +
                    (pos + 1) + " in '" + address + "'", address, pos + 1);
        }
        dSB.append(resultSB);
        return pos;
    }
View Full Code Here

            for (int digits = 0; digits < 3; digits++) {
                char currentChar = address.charAt(pos);
                if (currentChar == '.' || currentChar == ']') {
                    break;
                } else if (currentChar < '0' || currentChar > '9') {
                    throw new AddressException("Invalid number at position " +
                            (pos + 1) + " in '" + address + "'", address, pos + 1);
                }
                snumSB.append(currentChar);
                pos++;
            }
            if (snumSB.toString().length() == 0) {
                throw new AddressException("Number not found at position " +
                        (pos + 1) + " in '" + address + "'", address, pos + 1);
            }
            try {
                int snum = Integer.parseInt(snumSB.toString());
                if (snum > 255) {
                    throw new AddressException("Invalid number at position " +
                            (pos + 1) + " in '" + address + "'", address, pos + 1);
                }
            } catch (NumberFormatException nfe) {
                throw new AddressException("Invalid number at position " +
                        (pos + 1) + " in '" + address + "'", address, pos + 1);
            }
            resultSB.append(snumSB.toString());
            if (address.charAt(pos) == ']') {
                if (octet < 3) {
                    throw new AddressException("End of number reached too quickly at " +
                            (pos + 1) + " in '" + address + "'", address, pos + 1);
                }
                break;
            }
            if (address.charAt(pos) == '.') {
                resultSB.append('.');
                pos++;
            }
        }
        if (address.charAt(pos) != ']') {
            throw new AddressException("Did not find closing bracket \"]\" in domain at position " +
                    (pos + 1) + " in '" + address + "'", address, pos + 1);
        }
        resultSB.append(']');
        pos++;
        dSB.append(resultSB);
View Full Code Here

                continue;
            }
            if (ch == '.') {
                break;
            }
            throw new AddressException("Invalid character at " + pos + " in '" + address + "'", address, pos);
        }
        String result = resultSB.toString();
        if (result.startsWith("-") || result.endsWith("-")) {
            throw new AddressException("Domain name cannot begin or end with a hyphen \"-\" at position " +
                    (pos + 1) + " in '" + address + "'", address, pos + 1);
        }
        dSB.append(result);
        return pos;
    }
View Full Code Here

    public void send(SourceResolver resolver)
        throws AddressException, MessagingException {
        List sourcesList = new ArrayList();

        if (this.from == null) {
            throw new AddressException("no from address");
        } else {
            try {
                this.message.setFrom(new InternetAddress(this.from));
            } catch (AddressException e) {
                throw new AddressException(
                    "invalid from address: " + this.from + ": " + e.getMessage());
            }
        }

        if (this.to == null) {
            throw new AddressException("no to address");
        } else {
            try {
                this.message.setRecipients(
                    RecipientType.TO,
                    InternetAddress.parse(this.to));
            } catch (AddressException e) {
                throw new AddressException(
                    "invalid to address: " + this.to + ": " + e.getMessage());
            }
        }

        if (this.cc != null) {
            try {
                this.message.setRecipients(
                    RecipientType.CC,
                    InternetAddress.parse(this.cc));
            } catch (AddressException e) {
                throw new AddressException(
                    "invalid cc address: " + this.cc + ": " + e.getMessage());
            }
        }

        if (this.bcc != null) {
            try {
                this.message.setRecipients(
                    RecipientType.BCC,
                    InternetAddress.parse(this.bcc));
            } catch (AddressException e) {
                throw new AddressException(
                    "invalid bcc address: " + this.bcc + ": " + e.getMessage());
            }
        }

        if (this.subject != null) {
            this.message.setSubject(this.subject);
        }

        message.setSentDate(new Date());

        Attachment a = null;
        try {

            if (this.attachmentList.isEmpty()) {
                if (this.src != null) {
                    DataSource ds = null;

                    Source source = resolver.resolveURI(this.src);
                    sourcesList.add(source);
                    if (source.exists()) {
                        ds =
                            new SourceDataSource(
                                source,
                                (this.srcMimeType == null
                                    ? source.getMimeType()
                                    : this.srcMimeType),
                                this.src.substring(this.src.lastIndexOf('/') + 1));
                    }

                    this.message.setDataHandler(new DataHandler(ds));

                } else if (this.body != null) {
                    if (this.charset != null) {
                        this.message.setText(this.body, this.charset);
                    } else {
                        this.message.setText(this.body);
                    }
                }
            } else {
                Multipart multipart = new MimeMultipart();
                BodyPart bodypart = new MimeBodyPart();
                multipart.addBodyPart(bodypart);
                this.message.setContent(multipart);

                if (this.src != null) {
                    DataSource ds = null;

                    Source source = resolver.resolveURI(this.src);
                    sourcesList.add(source);
                    if (source.exists()) {
                        ds =
                            new SourceDataSource(
                                source,
                                (this.srcMimeType == null
                                    ? source.getMimeType()
                                    : this.srcMimeType),
                                this.src.substring(this.src.lastIndexOf('/') + 1));
                    }

                    bodypart.setDataHandler(new DataHandler(ds));
                    bodypart.setFileName(ds.getName());

                } else if (this.body != null) {
                    bodypart.setText(this.body);
                }

                for (Iterator i = this.attachmentList.iterator(); i.hasNext();) {
                    a = (Attachment) i.next();
                    DataSource ds = null;
                    if (a.isURL) {
                        String name = (String) a.getObject();
                        Source src = resolver.resolveURI(name);
                        sourcesList.add(src);
                        if (src.exists()) {
                            ds =
                                new SourceDataSource(
                                    src,
                                    a.getType(src.getMimeType()),
                                    a.getName(name.substring(name.lastIndexOf('/') + 1)));
                        }
                    } else {
                        if (a.getObject() instanceof Part) {
                            Part part = (Part) a.getObject();
                            ds =
                                new FilePartDataSource(
                                    part,
                                    a.getType(part.getMimeType()),
                                    a.getName(part.getUploadName()));
                        } else {
                            // TODO: other classes?
                            throw new AddressException(
                                "Not yet supported: " + a.getObject());
                        }
                    }

                    bodypart = new MimeBodyPart();
                    bodypart.setDataHandler(new DataHandler(ds));
                    bodypart.setFileName(ds.getName());
                    multipart.addBodyPart(bodypart);
                }
            }

            Transport.send(this.message);
        } catch (MessagingException me) {
            throw new MessagingException(me.getMessage());
        } catch (MalformedURLException e) {
            throw new AddressException(
                "Malformed attachment URL: "
                    + a.getObject()
                    + " error "
                    + e.getMessage());
        } catch (IOException e) {
            throw new AddressException(
                "IOException accessing attachment URL: "
                    + a.getObject()
                    + " error "
                    + e.getMessage());
        } finally {
View Full Code Here

            //parse local-part
            //<local-part> ::= <dot-string> | <quoted-string>
            if (address.charAt(pos) == '\"') {
                localPartSB.append(parseQuotedLocalPart(address));
                if (localPartSB.toString().length() == 2) {
                    throw new AddressException("No quoted local-part (user account) found at position " + (pos + 2) + " in '" + address + "'",address,pos+2);
                }
            } else {
                localPartSB.append(parseUnquotedLocalPart(address));
                if (localPartSB.toString().length() == 0) {
                    throw new AddressException("No local-part (user account) found at position " + (pos + 1) + " in '" + address + "'",address,pos+1);
                }
            }

            //find @
            if (pos >= address.length() || address.charAt(pos) != '@') {
                throw new AddressException("Did not find @ between local-part and domain at position " + (pos + 1) + " in '" + address + "'",address,pos+1);
            }
            pos++;

            //parse domain
            //<domain> ::=  <element> | <element> "." <domain>
            //<element> ::= <name> | "#" <number> | "[" <dotnum> "]"
            while (true) {
                if (address.charAt(pos) == '#') {
                    domainSB.append(parseNumber(address));
                } else if (address.charAt(pos) == '[') {
                    domainSB.append(parseDomainLiteral(address));
                } else {
                    domainSB.append(parseDomain(address));
                }
                if (pos >= address.length()) {
                    break;
                }
                if (address.charAt(pos) == '.') {
                    domainSB.append('.');
                    pos++;
                    continue;
                }
                break;
            }

            if (domainSB.toString().length() == 0) {
                throw new AddressException("No domain found at position " + (pos + 1) + " in '" + address + "'",address,pos+1);
            }
        } catch (IndexOutOfBoundsException ioobe) {
            throw new AddressException("Out of data at position " + (pos + 1) + " in '" + address + "'",address,pos+1);
        }

        localPart = localPartSB.toString();
        domain = domainSB.toString();
    }
View Full Code Here

                resultSB.append('\\');
                pos++;
                //<x> ::= any one of the 128 ASCII characters (no exceptions)
                char x = address.charAt(pos);
                if (x < 0 || x > 127) {
                    throw new AddressException("Invalid \\ syntaxed character at position " + (pos + 1) + " in '" + address + "'",address,pos+1);
                }
                resultSB.append(x);
                pos++;
            } else {
                //<q> ::= any one of the 128 ASCII characters except <CR>,
                //<LF>, quote ("), or backslash (\)
                char q = address.charAt(pos);
                if (q <= 0 || q == '\n' || q == '\r' || q == '\"' || q == '\\') {
                    throw new AddressException("Unquoted local-part (user account) must be one of the 128 ASCI characters exception <CR>, <LF>, quote (\"), or backslash (\\) at position " + (pos + 1) + " in '" + address + "'");
                }
                resultSB.append(q);
                pos++;
            }
        }
View Full Code Here

TOP

Related Classes of javax.mail.internet.AddressException

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.