List of usage examples for javax.mail Address toString
@Override public abstract String toString();
From source file:com.crawlersick.nettool.GetattchmentFromMail1.java
public boolean fetchmailforattch() throws IOException, MessagingException { boolean fetchtest = false; Properties props = new Properties(); props.setProperty("mail.store.protocol", "imaps"); try {/* ww w.j av a2s . c o m*/ Session session = Session.getInstance(props, null); Store store = session.getStore(); store.connect(IMapHost, MailId, MailPassword); Folder inbox = store.getFolder("INBOX"); inbox.open(Folder.READ_ONLY); totalmailcount = inbox.getMessageCount(); Message msg = null; for (int i = totalmailcount; i > 0; i--) { fromadd = ""; msg = inbox.getMessage(i); Address[] in = msg.getFrom(); for (Address address : in) { fromadd = address.toString() + fromadd; //System.out.println("FROM:" + address.toString()); } if (fromadd.matches("admin@cronmailservice.appspotmail.com") && msg.getSubject().matches( "ThanksToTsukuba_World-on-my-shoulders-as-I-run-back-to-this-8-Mile-Road_cronmailservice")) break; } if (fromadd.equals("'")) { log.log(Level.SEVERE, "Error: no related mail found!" + this.MailId); return fetchtest; } // Multipart mp = (Multipart) msg.getContent(); // BodyPart bp = mp.getBodyPart(0); sentdate = msg.getSentDate().toString(); subject = msg.getSubject(); Content = msg.getContent().toString(); log.log(Level.INFO, Content); log.log(Level.INFO, sentdate); localIntent.putExtra("213123", "Got Server latest update at : " + sentdate + " , Reading the Data..."); LocalBroadcastManager.getInstance(myis).sendBroadcast(localIntent); Multipart multipart = (Multipart) msg.getContent(); for (int i = 0; i < multipart.getCount(); i++) { BodyPart bodyPart = multipart.getBodyPart(i); if (!Part.ATTACHMENT.equalsIgnoreCase(bodyPart.getDisposition()) && (bodyPart.getFileName() == null || !bodyPart.getFileName().equals("dataforvgendwithudp.gzip"))) { continue; // dealing with attachments only } ByteArrayOutputStream buffer = new ByteArrayOutputStream(); InputStream is = bodyPart.getInputStream(); //validvgbinary = IOUtils.toByteArray(is); int nRead; byte[] data = new byte[5000000]; while ((nRead = is.read(data, 0, data.length)) != -1) { buffer.write(data, 0, nRead); } buffer.flush(); validvgbinary = buffer.toByteArray(); break; } fetchtest = true; } catch (Exception mex) { mex.printStackTrace(); } return fetchtest; }
From source file:org.apache.hupa.server.handler.AbstractFetchMessagesHandler.java
protected ArrayList<org.apache.hupa.shared.data.Message> convert(int offset, com.sun.mail.imap.IMAPFolder folder, Message[] messages) throws MessagingException { ArrayList<org.apache.hupa.shared.data.Message> mList = new ArrayList<org.apache.hupa.shared.data.Message>(); // Setup fetchprofile to limit the stuff which is fetched FetchProfile fp = new FetchProfile(); fp.add(FetchProfile.Item.ENVELOPE);// w w w. jav a2 s .c o m fp.add(FetchProfile.Item.FLAGS); fp.add(FetchProfile.Item.CONTENT_INFO); fp.add(UIDFolder.FetchProfileItem.UID); folder.fetch(messages, fp); // loop over the fetched messages for (int i = 0; i < messages.length && i < offset; i++) { org.apache.hupa.shared.data.Message msg = new org.apache.hupa.shared.data.Message(); Message m = messages[i]; String from = null; if (m.getFrom() != null && m.getFrom().length > 0) { from = MessageUtils.decodeText(m.getFrom()[0].toString()); } msg.setFrom(from); String replyto = null; if (m.getReplyTo() != null && m.getReplyTo().length > 0) { replyto = MessageUtils.decodeText(m.getReplyTo()[0].toString()); } msg.setReplyto(replyto); ArrayList<String> to = new ArrayList<String>(); // Add to addresses Address[] toArray = m.getRecipients(RecipientType.TO); if (toArray != null) { for (Address addr : toArray) { String mailTo = MessageUtils.decodeText(addr.toString()); to.add(mailTo); } } msg.setTo(to); // Check if a subject exist and if so decode it String subject = m.getSubject(); if (subject != null) { subject = MessageUtils.decodeText(subject); } msg.setSubject(subject); // Add cc addresses Address[] ccArray = m.getRecipients(RecipientType.CC); ArrayList<String> cc = new ArrayList<String>(); if (ccArray != null) { for (Address addr : ccArray) { String mailCc = MessageUtils.decodeText(addr.toString()); cc.add(mailCc); } } msg.setCc(cc); userPreferences.addContact(from); userPreferences.addContact(to); userPreferences.addContact(replyto); userPreferences.addContact(cc); // Using sentDate since received date is not useful in the view when using fetchmail msg.setReceivedDate(m.getSentDate()); // Add flags ArrayList<IMAPFlag> iFlags = JavamailUtil.convert(m.getFlags()); ArrayList<Tag> tags = new ArrayList<Tag>(); for (String flag : m.getFlags().getUserFlags()) { if (flag.startsWith(Tag.PREFIX)) { tags.add(new Tag(flag.substring(Tag.PREFIX.length()))); } } msg.setUid(folder.getUID(m)); msg.setFlags(iFlags); msg.setTags(tags); try { msg.setHasAttachments(hasAttachment(m)); } catch (MessagingException e) { logger.debug("Unable to identify attachments in message UID:" + msg.getUid() + " subject:" + msg.getSubject() + " cause:" + e.getMessage()); logger.info(""); } mList.add(0, msg); } return mList; }
From source file:org.sourceforge.net.javamail4ews.transport.EwsTransport.java
private void createAddresses(EmailMessage pEmailMessage, Message pMessage, Address[] pToAddresses, Address[] pCcAddresses, Address[] pBccAddresses) throws Exception { if (pMessage instanceof MimeMessage) { MimeMessage lMimeMessage = (MimeMessage) pMessage; if (pToAddresses.length <= 0) { pToAddresses = lMimeMessage.getRecipients(javax.mail.Message.RecipientType.TO); }/*from www . j a va 2s.c om*/ if (pCcAddresses.length <= 0) { pCcAddresses = lMimeMessage.getRecipients(javax.mail.Message.RecipientType.CC); } if (pBccAddresses.length <= 0) { pBccAddresses = lMimeMessage.getRecipients(javax.mail.Message.RecipientType.BCC); } } Address[] from = pMessage.getFrom(); if (from != null && from.length > 0) { pEmailMessage.setFrom(emailAddressFromInternetAddress(from[0])); } for (Address aAddress : pToAddresses) { logger.info("Adding adress {} as TO recepient", aAddress.toString()); pEmailMessage.getToRecipients().add(emailAddressFromInternetAddress(aAddress)); } if (pCcAddresses != null) { for (Address aAddress : pCcAddresses) { logger.info("Adding adress {} as CC recepient", aAddress.toString()); pEmailMessage.getCcRecipients().add(emailAddressFromInternetAddress(aAddress)); } } if (pBccAddresses != null) { for (Address aAddress : pBccAddresses) { logger.info("Adding adress {} as BCC recepient", aAddress.toString()); pEmailMessage.getBccRecipients().add(emailAddressFromInternetAddress(aAddress)); } } }
From source file:hornet.framework.mail.MailServiceImpl.java
/** * Converti l'exception fourni en {@link BusinessException}. * * @param mse//from w w w .java 2 s. c om * MailSendException * @return Une {@link BusinessException} */ protected BusinessException toBusinessException(final MailSendException mse) { MailServiceImpl.LOG.debug("Conversion d'une erreur d'envoi de courriel"); final List<String> adressesInvalides = new ArrayList<String>(); for (final Exception exception : mse.getMessageExceptions()) { if (exception instanceof SendFailedException) { final SendFailedException sendFailedEx = (SendFailedException) exception; for (final Address adresseInvalide : sendFailedEx.getInvalidAddresses()) { adressesInvalides.add(adresseInvalide.toString()); MailServiceImpl.LOG.debug(String.format("adresse invalide : %s", adresseInvalide)); } } else if (exception instanceof AuthenticationFailedException) { final AuthenticationFailedException authenticationFailedEx = (AuthenticationFailedException) exception; return new BusinessException("erreur.envoi.courriel.authentification", authenticationFailedEx); } } if (adressesInvalides.isEmpty()) { return new BusinessException("erreur.envoi.courriel", mse); } else { return new BusinessException("erreur.envoi.courriel.addressesInvalides", new String[] { StringUtils.join(adressesInvalides, ", ") }, mse); } }
From source file:org.alfresco.email.server.impl.subetha.SubethaEmailMessage.java
private void processMimeMessage(MimeMessage mimeMessage) { if (from == null) { Address[] addresses = null;//w ww .jav a2 s . c om try { addresses = mimeMessage.getFrom(); } catch (MessagingException e) { throw new EmailMessageException(ERR_EXTRACTING_FROM_ADDRESS, e.getMessage()); } if (addresses == null || addresses.length == 0) { //throw new EmailMessageException(ERR_NO_FROM_ADDRESS); } else { if (addresses[0] instanceof InternetAddress) { from = ((InternetAddress) addresses[0]).getAddress(); } else { from = addresses[0].toString(); } } } if (to == null) { Address[] addresses = null; try { addresses = mimeMessage.getAllRecipients(); } catch (MessagingException e) { throw new EmailMessageException(ERR_EXTRACTING_TO_ADDRESS, e.getMessage()); } if (addresses == null || addresses.length == 0) { //throw new EmailMessageException(ERR_NO_TO_ADDRESS); } else { if (addresses[0] instanceof InternetAddress) { to = ((InternetAddress) addresses[0]).getAddress(); } else { to = addresses[0].toString(); } } } if (cc == null) { try { ArrayList<String> list = new ArrayList<String>(); Address[] cca = mimeMessage.getRecipients(RecipientType.CC); if (cca != null) { for (Address a : cca) { list.add(a.toString()); } } cc = list; } catch (MessagingException e) { // Do nothing - this is not a show-stopper. cc = null; } } try { subject = mimeMessage.getSubject(); //subject = encodeSubject(mimeMessage.getSubject()); } catch (MessagingException e) { throw new EmailMessageException(ERR_EXTRACTING_SUBJECT, e.getMessage()); } //if (subject == null) //{ // subject = ""; // Just anti-null stub :) //} try { sentDate = mimeMessage.getSentDate(); } catch (MessagingException e) { throw new EmailMessageException(ERR_EXTRACTING_SENT_DATE, e.getMessage()); } if (sentDate == null) { sentDate = new Date(); // Just anti-null stub :) } parseMessagePart(mimeMessage); attachments = new EmailMessagePart[attachmentList.size()]; attachmentList.toArray(attachments); attachmentList = null; }
From source file:edu.stanford.muse.util.EmailUtils.java
/** * best effort to toString something about the given message. * use only for diagnostics, not for user-visible messages. * treads defensively, this can be called to report on a badly formatted message. */// w w w. java 2s.c o m public static String formatMessageHeader(MimeMessage m) throws MessagingException { StringBuilder sb = new StringBuilder(); sb.append("To: "); if (m == null) { log.warn("Trying to format null message!?"); return "Null message"; } try { Address[] tos = m.getAllRecipients(); if (tos != null) for (Address a : tos) sb.append(a.toString() + " "); sb.append("\n"); } catch (Exception e) { Util.print_exception(e, log); } sb.append("From: "); try { Address[] froms = m.getFrom(); if (froms != null) for (Address a : froms) sb.append(a.toString() + " "); sb.append("\n"); } catch (Exception e) { Util.print_exception(e, log); } try { sb.append("Subject: " + m.getSubject()); sb.append("Message-ID: " + m.getMessageID()); } catch (Exception e) { Util.print_exception(e, log); } return sb.toString(); }
From source file:mitm.application.djigzo.james.mailets.MailAttributes.java
private void copyMailAddresses(Address[] source, Collection<String> target) throws ParseException { if (source != null) { for (Address address : source) { if (address != null) { target.add(address.toString()); }/* w w w . ja v a 2 s. c o m*/ } } }
From source file:com.angstoverseer.service.mail.MailServiceImpl.java
private void sendResponseMail(final Address sender, final String answer, final String subject) throws Exception { Properties props = new Properties(); Session session = Session.getDefaultInstance(props, null); Message mimeMessage = new MimeMessage(session); mimeMessage.setFrom(new InternetAddress("overseer@thenewoverseer.appspotmail.com", "Overseer")); mimeMessage.addRecipient(Message.RecipientType.TO, new InternetAddress(sender.toString())); mimeMessage.setSubject("Re: " + subject); mimeMessage.setText(answer);//from w w w . ja va 2 s .com Transport.send(mimeMessage); }
From source file:org.apache.solr.handler.dataimport.FsMailEntityProcessor.java
private void addAddressToList(Address[] adresses, List<String> to) throws AddressException { for (Address address : adresses) { to.add(address.toString()); InternetAddress ia = (InternetAddress) address; if (ia.isGroup()) { InternetAddress[] group = ia.getGroup(false); for (InternetAddress member : group) { to.add(member.toString()); }//from w w w. java2s . c o m } } }
From source file:TIG055st2014.mailmaster.Activities.ComposeActivity.java
/** * Makes sure there are separators between the addresses to send to. * Also adds a comma at the end of the last address, since that is the * character our autocomplete looks for when determining if a new * "word" has been started./*from w w w . jav a 2 s . co m*/ */ private void addAddresses(Address[] addresses, EditText et) { if (addresses != null) { for (Address a : addresses) { et.setText(et.getText() + a.toString() + ","); } } }