Example usage for javax.mail MessagingException getLocalizedMessage

List of usage examples for javax.mail MessagingException getLocalizedMessage

Introduction

In this page you can find the example usage for javax.mail MessagingException getLocalizedMessage.

Prototype

public String getLocalizedMessage() 

Source Link

Document

Creates a localized description of this throwable.

Usage

From source file:org.sonews.daemon.command.PostCommand.java

/**
 * Process the given line String. line.trim() was called by NNTPConnection.
 *
 * @param conn//w w w .ja v  a  2  s.com
 * @param line
 * @throws java.io.IOException
 * @throws org.sonews.storage.StorageBackendException
 */
@Override
// TODO: Refactor this method to reduce complexity!
public void processLine(NNTPConnection conn, String line, byte[] raw)
        throws IOException, StorageBackendException {
    switch (state) {
    case WaitForLineOne: {
        if (line.equalsIgnoreCase("POST")) {
            conn.println("340 send article to be posted. End with <CR-LF>.<CR-LF>");
            state = PostState.ReadingHeaders;
        } else {
            conn.println("500 invalid command usage");
        }
        break;
    }
    case ReadingHeaders: {
        strHead.append(line);
        strHead.append(SynchronousNNTPConnection.NEWLINE);

        if ("".equals(line) || ".".equals(line)) {
            // we finally met the blank line
            // separating headers from body

            try {
                // Parse the header using the InternetHeader class from
                // JavaMail API
                headers = new InternetHeaders(
                        new ByteArrayInputStream(strHead.toString().trim().getBytes(conn.getCurrentCharset())));

                // add the header entries for the article
                article.setHeaders(headers);
            } catch (MessagingException ex) {
                Log.get().log(Level.INFO, ex.getLocalizedMessage(), ex);
                conn.println("500 posting failed - invalid header");
                state = PostState.Finished;
                break;
            }

            // Change charset for reading body;
            // for multipart messages UTF-8 is returned
            // conn.setCurrentCharset(article.getBodyCharset());

            state = PostState.ReadingBody;

            // WTF: do we need articles without bodies?
            if (".".equals(line)) {
                // Post an article without body
                postArticle(conn, article);
                state = PostState.Finished;
            }
        }
        break;
    }
    case ReadingBody: {
        if (".".equals(line)) {
            // Set some headers needed for Over command
            headers.setHeader(Headers.LINES, Integer.toString(lineCount));
            headers.setHeader(Headers.BYTES, Long.toString(bodySize));

            byte[] body = bufBody.toByteArray();
            if (body.length >= 2) {
                // Remove trailing CRLF
                body = Arrays.copyOf(body, body.length - 2);
            }
            article.setBody(body); // set the article body

            postArticle(conn, article);
            state = PostState.Finished;
        } else {
            bodySize += line.length() + 1;
            lineCount++;

            // Add line to body buffer
            bufBody.write(raw, 0, raw.length);
            bufBody.write(SynchronousNNTPConnection.NEWLINE.getBytes("UTF-8"));

            if (bodySize > maxBodySize) {
                conn.println("500 article is too long");
                state = PostState.Finished;
                break;
            }
        }
        break;
    }
    default: {
        // Should never happen
        Log.get().severe("PostCommand::processLine(): already finished...");
    }
    }
}

From source file:org.sakaiproject.nakamura.smtp.SakaiSmtpServer.java

public void deliver(String from, String recipient, InputStream data) throws TooMuchDataException, IOException {
    LOGGER.info("Got message FROM: " + from + " TO: " + recipient);
    Session session = null;//from w w  w. java  2 s.  c om
    try {
        session = contentRepository.loginAdministrative();

        List<String> paths = getLocalPath(session, recipient);
        if (paths.size() > 0) {
            Map<String, Object> mapProperties = new HashMap<String, Object>();
            mapProperties.put(JcrResourceConstants.SLING_RESOURCE_TYPE_PROPERTY,
                    MessageConstants.SAKAI_MESSAGE_RT);
            mapProperties.put(MessageConstants.PROP_SAKAI_READ, false);
            mapProperties.put(MessageConstants.PROP_SAKAI_FROM, from);
            mapProperties.put(MessageConstants.PROP_SAKAI_MESSAGEBOX, MessageConstants.BOX_INBOX);
            Content createdMessage = writeMessage(session, mapProperties, data, paths.get(0));
            if (createdMessage != null) {
                String messagePath = createdMessage.getPath();
                String messageId = (String) createdMessage.getProperty("message-id");
                LOGGER.info("Created message {} at: {} ", messageId, messagePath);

                // we might want alias expansion
                for (int i = 1; i < paths.size(); i++) {
                    String targetPath = paths.get(i);
                    messagingService.copyMessageNode(createdMessage, targetPath, session);
                }
            }

        }
    } catch (MessagingException e) {
        LOGGER.error("Unable to write message", e);
        throw new IOException("Message can not be written to repository");
    } catch (StorageClientException e) {
        LOGGER.error("Unable to write message", e);
    } catch (AccessDeniedException e) {
        LOGGER.error("Unable to write message", e);
    } finally {
        if (session != null) {
            try {
                session.logout();
            } catch (ClientPoolException e) {
                LOGGER.error(e.getLocalizedMessage(), e);
                throw new RuntimeException("Failed to logout session.", e);
            }
        }
    }
}

From source file:output.ExcelM3Upgrad.java

public boolean save() {
    dialStatus();/*w ww  .j a  v  a  2s  .  c  om*/
    try {
        if (workbook instanceof HSSFWorkbook) {
            if (!filepath.endsWith("xls")) {
                filepath += ".xls";
            }
        } else if (workbook instanceof XSSFWorkbook) {
            if (!filepath.endsWith("xlsx")) {
                filepath += ".xlsx";
            }
        }
        busyDial.setText("Sauvegarde du fichier " + filepath);
        FileOutputStream out = new FileOutputStream(new File(filepath));
        workbook.write(out);
        out.close();
        if (endFile) {
            Object[] options = { i18n.Language.getLabel(140), i18n.Language.getLabel(23),
                    i18n.Language.getLabel(130) };
            int n = JOptionPane.showOptionDialog(busyDial, i18n.Language.getLabel(213), "Excel",
                    JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[0]);

            if (n == 0) {
                busyDial.setText(i18n.Language.getLabel(214) + "...");
                Desktop dt = Desktop.getDesktop();
                dt.open(new File(filepath));
            } else if (n == 1) {
                try {
                    busyDial.setText(i18n.Language.getLabel(215) + "...");
                    GmailTLS mail = new GmailTLS();
                    Message msg = mail.writeMail("j.chaut@3kles-consulting.com", "M3Upgrader",
                            "Rsultat de M3Upgrader");
                    msg = mail.addAttachment(msg, new File(filepath));
                    busyDial.setText(i18n.Language.getLabel(216) + "...");
                    mail.sendMail(msg);
                } catch (MessagingException ex) {
                    Ressource.logger.error(ex.getLocalizedMessage(), ex);
                }
            }
            in.close();
        }
    } catch (IOException e) {
        error(e.getMessage());
        return false;
    }
    return true;
}

From source file:trendplot.TrendPlot.java

private void testEmail() {
    Properties fMailServerConfig;
    fMailServerConfig = new Properties();
    fMailServerConfig.setProperty("mail.host", "ldas-cit.ligo.caltech.edu");
    fMailServerConfig.setProperty("mail.smtp.host", "ldas-cit.ligo.caltech.edu");

    Session session = Session.getDefaultInstance(fMailServerConfig, null);
    MimeMessage message = new MimeMessage(session);
    try {//w  w w  .  j a  v a2s  . c  o m
        //the "from" address may be set in code, or set in the
        //config file under "mail.from" ; here, the latter style is used
        message.setFrom(new InternetAddress("areeda@ligo.caltech.edu"));
        String email = "joe@areeda.com";

        message.addRecipient(Message.RecipientType.TO, new InternetAddress(email));
        String msg = "<h3>this is a test</h3>";
        message.setSubject("Test email");
        message.setText(msg, "utf-8", "html");
        Transport.send(message);
        System.out.format("Email sent to %1$s\n", email);
    } catch (MessagingException ex) {
        System.err.format("Exception: %1$s: %2$s", ex.getClass().getSimpleName(), ex.getLocalizedMessage());
    }

}

From source file:yoyo.framework.enterprise.infra.messaging.MailServiceImpl.java

@Override
public void send(final String from, final String to, final String subject, final Object objectBody,
        final String contentType) throws EnterpriseException {
    try {//from w w w  .  j  a  va  2 s  .  c om
        final Message message = createMessage(from, to, subject);
        message.setContent(objectBody, contentType);
        send(message);
    } catch (final MessagingException e) {
        throw new EnterpriseException(e.getLocalizedMessage());
    }
}

From source file:yoyo.framework.enterprise.infra.messaging.MailServiceImpl.java

@Override
public void send(final String from, final String to, final String subject, final String textBody)
        throws EnterpriseException {
    try {//from  www  .j a  va 2s .  co  m
        final Message message = createMessage(from, to, subject);
        message.setContent(textBody, "text/plain");
        send(message);
    } catch (final MessagingException e) {
        throw new EnterpriseException(e.getLocalizedMessage());
    }
}

From source file:yoyo.framework.enterprise.infra.messaging.MailServiceImpl.java

@Override
public void send(final String from, final String to, final String subject, final Multipart multipartBody)
        throws EnterpriseException {
    try {//from w w  w . ja v a 2 s . c o  m
        final Message message = createMessage(from, to, subject);
        message.setContent(multipartBody);
        send(message);
    } catch (final MessagingException e) {
        throw new EnterpriseException(e.getLocalizedMessage());
    }
}

From source file:yoyo.framework.enterprise.infra.messaging.MailServiceImpl.java

/**
 * ?/*w  ww.  j  a  va2s  . c  o m*/
 * @param message 
 * @throws EnterpriseException ?
 */
private static void send(final Message message) throws EnterpriseException {
    try {
        Transport.send(message);
    } catch (final MessagingException e) {
        throw new EnterpriseException(e.getLocalizedMessage());
    }
}