Package javax.mail.internet

Examples of javax.mail.internet.AddressException


                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) == '.') {
                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);
                }
                for (int i = 0; i < SPECIAL.length; i++) {
                    if (c == SPECIAL[i]) {
                        throw new AddressException("Invalid character in local-part (user account) at position " + (pos + 1) + " in '" + address + "'",address,pos+1);
                    }
                }
                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);
        }
        return resultSB.toString();
    }
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++;
        }
        return resultSB.toString();
View Full Code Here

                }
                if (d == ']') {
                    break;
                }
                if (d < '0' || d > '9') {
                    throw new AddressException("Invalid number at position " + (pos + 1) + " in '" + address + "'",address,pos+1);
                }
                snumSB.append(d);
                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++;
        return resultSB.toString();
    }
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);
        }
        return result;
    }
View Full Code Here

      throw new IllegalArgumentException("Required parameter 'email' is missing.");
    }
    try {
      new InternetAddress(email, true);
      if (!email.contains("@")) {
        throw new AddressException();
      }
    } catch (AddressException e) {
      throw new IllegalArgumentException(String.format("'%s' is not a valid email address.",
        email));
    }
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 = null;

                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());

                    multipart.addBodyPart(bodypart);

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

                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

            String mimeCharset = MimeUtility.mimeCharset(getJavaCharset(javaCharset));

            for (InternetAddress addr : addrs) {
                // JavaMail 1.4.2���ϣ���parseʱ�ͻᱨempty address�����ڴ˴��жϣ�ʹ�ϵͰ��javamail��Ϊһ�¡�
                if (isEmpty(addr.getAddress())) {
                    throw new AddressException("Empty address");
                }

                addr.setPersonal(trimToNull(addr.getPersonal()), mimeCharset);
            }
        }
View Full Code Here

    }

    private InternetAddress parseAddress(JsonObject jsonMessage, String field, boolean mandatory) throws AddressException {
        String address = jsonMessage.getString(field);
        if (Strings.isNullOrEmpty(address)) {
            if (mandatory) throw new AddressException("Mandatory field " + field + " is missing");
            return null;
        }

        return new InternetAddress(address);
    }
View Full Code Here

        if (address instanceof String) {
            return new InternetAddress[] {parseAddress(jsonMessage, field, mandatory)};
        }

        if (!(address instanceof JsonArray)) {
            if (mandatory) throw new AddressException("Mandatory field " + field + " is missing");
            return null;
        }

        JsonArray addresses = (JsonArray) address;
        InternetAddress[] internetAddresses = new InternetAddress[addresses.size()];
View Full Code Here

      System.exit(1);
    }
   
    try {
      if (!MailUtil.matches(admin.email)) {
          throw new AddressException("Invalid address");
      }
      new InternetAddress(admin.email, true);
    } catch (AddressException ae) {
      System.out.println("Please provide non-empty valid email: '" + admin.email + "' is not valid.");
      System.exit(1);
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.