Package javax.mail.internet

Examples of javax.mail.internet.AddressException


     * @param name the name this address belongs to
     */
    public void setFrom(String addstr, Object name) {
        try {
            if (addstr.indexOf("@") < 0) {
                throw new AddressException();
            }

            Address address = null;

            if (name != null && name != Undefined.instance) {
View Full Code Here


     */
    private void addRecipient(String addstr,
                              Object name,
                              Message.RecipientType type) throws Exception {
        if (addstr.indexOf("@") < 0) {
            throw new AddressException();
        }

        Address address = null;

        if (name != null && name != Undefined.instance) {
View Full Code Here

    int iRightPar= sAddr.indexOf(')');
    int iLeftQuo = sAddr.indexOf('"');
    int iRightQuo;
    if (iLeftQuo>=0) iRightQuo = sAddr.indexOf('"',iLeftQuo+1); else iRightQuo = -1;

    if (iRightAng<iLeftAng) throw new AddressException("Misplaced right angle");
    if (iLeftAng<0 && iRightAng>=0) throw new AddressException("Missing left angle");
    if (iLeftAng>=0 && iRightAng<0) throw new AddressException("Missing right angle");
    if (iLeftPar<0 && iRightPar>=0) throw new AddressException("Missing left parenthesis");
    if (iLeftPar>=0 && iRightPar<0) throw new AddressException("Missing right parenthesis");
    if (iRightPar<iLeftPar) throw new AddressException("Misplaced right parenthesis");
    if (iLeftQuo>=0 && iRightQuo<0) throw new AddressException("Unclosed quote");

    if (iLeftAng>=0 && iRightAng>=0 && iLeftPar>=0 && iRightPar>=0) {
      // Address is (Name) <user@domain.com> or <user@domain.com> (Name)
      oRetAdr = new InternetAddress(sAddr.substring(iLeftAng+1,iRightAng),sAddr.substring(iLeftPar+1,iRightPar));
    } else if (iLeftAng>=0 && iRightAng>=0 && iLeftQuo>=0 && iRightQuo>=0) {
View Full Code Here

              DistributionList oLst;
              if (sLId.charAt(0)=='{') {
                oLst = new DistributionList(oAdCn, sLId.substring(1,sLId.length()-1), sWorkAreaId);
                if (oLst.isNull(DB.gu_list)) {
                  if (DebugFile.trace) DebugFile.decIdent();
                  throw new AddressException("RecipientsHelper.parseRecipientsList() list "+sLId.substring(1,sLId.length()-1)+" not found");
                }
              } else {
                oLst = new DistributionList(oAdCn, sLId.substring(sLId.indexOf('@')+1,sLId.indexOf('.')));
                if (oLst.isNull(DB.gu_list)) {
                  if (DebugFile.trace) DebugFile.decIdent();
                  throw new AddressException("RecipientsHelper.parseRecipientsList() list "+sLId.substring(sLId.indexOf('@')+1,sLId.indexOf('.'))+" not found");
                }
              }
              String sPer = oLst.getStringNull(DB.de_list,null);
              String sLst = oLst.activeMembers(oAdCn);
              if (sLst.length()>0) {
View Full Code Here

                    getRenderedMailMessage("/org/jboss/seam/example/mail/test/errors2.xhtml");
                }
                catch (FacesException e)
                {
                    Assert.assertTrue(e.getCause() instanceof AddressException);
                    AddressException ae = (AddressException) e.getCause();
                    Assert.assertTrue(ae.getMessage().startsWith("Missing final '@domain'"));
                    exceptionThrown = true;
                }
                Assert.assertTrue(exceptionThrown);
            
            }
View Full Code Here

                    getRenderedMailMessage("/org/jboss/seam/example/mail/test/errors3.xhtml");
                }
                catch (Exception e)
                {
                    Assert.assertTrue(e.getCause() instanceof AddressException);
                    AddressException ae = (AddressException) e.getCause();
                    System.out.println(ae.getMessage());
                    Assert.assertTrue(ae.getMessage().startsWith("Email cannot have more than one Reply-to address"));
                    exceptionThrown = true;
                }
                Assert.assertTrue(exceptionThrown);
            
            }
View Full Code Here

                    getRenderedMailMessage("/org/jboss/seam/example/mail/test/errors4.xhtml");
                }
                catch (FacesException e)
                {
                    Assert.assertTrue(e.getCause() instanceof AddressException);
                    AddressException ae = (AddressException) e.getCause();
                    Assert.assertTrue(ae.getMessage().startsWith("Email cannot have more than one from address"));
                    exceptionThrown = true;
                }
                Assert.assertTrue(exceptionThrown);
            
            }
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.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.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 {
            if (sourcesList != null) {
                for (Iterator j = sourcesList.iterator(); j.hasNext();) {
                    resolver.release((Source) j.next());
View Full Code Here

    throws AddressException, MessagingException {

        final MimeMessage message = new MimeMessage(this.session);

        if (this.from == null) {
            throw new AddressException("No from address");
        } else {
            try {
                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 {
                message.setRecipients(RecipientType.TO,
                                      InternetAddress.parse(this.to));
            } catch (AddressException e) {
                throw new AddressException("Invalid to address: " + this.to + ": " +
                                           e.getMessage());
            }
        }

        if (this.replyTo != null) {
            try {
                message.setReplyTo(InternetAddress.parse(this.replyTo));
            } catch (AddressException e) {
                throw new AddressException("Invalid replyTo address: " + this.replyTo + ": " +
                                           e.getMessage());
            }
        }

        if (this.cc != null) {
            try {
                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 {
                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) {
View Full Code Here

                pos = parseUnquotedLocalPartOrThrowException(localPartSB, address, pos);
            }

            //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) == '#') {
                    pos = parseNumber(domainSB, address, pos);
                } else if (address.charAt(pos) == '[') {
                    pos = parseDomainLiteral(domainSB, address, pos);
                } else {
                    pos = parseDomain(domainSB, address, pos);
                }
                if (pos >= address.length()) {
                    break;
                }
                if (address.charAt(pos) == '.') {
                    char lastChar = address.charAt(pos - 1);
                    if (lastChar == '@' || lastChar == '.') {
                        throw new AddressException("Subdomain expected before '.' or duplicate '.' in " + address);
                    }
                    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

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.