Example usage for javax.mail.internet InternetHeaders getAllHeaderLines

List of usage examples for javax.mail.internet InternetHeaders getAllHeaderLines

Introduction

In this page you can find the example usage for javax.mail.internet InternetHeaders getAllHeaderLines.

Prototype

public Enumeration<String> getAllHeaderLines() 

Source Link

Document

Return all the header lines as an Enumeration of Strings.

Usage

From source file:com.adaptris.util.text.mime.MultiPartOutput.java

/**
 * Write the internet headers out to the supplied outputstream
 *//* ww w. ja v  a 2  s. c  o m*/
private static void writeHeaders(InternetHeaders header, OutputStream out)
        throws IOException, MessagingException {

    Enumeration e = header.getAllHeaderLines();
    PrintStream p = new PrintStream(out);
    while (e.hasMoreElements()) {
        p.println(e.nextElement().toString());
    }
    p.println("");
    p.flush();
}

From source file:foo.domaintest.email.EmailApiModule.java

@Provides
@RawEmailHeaders/* w  ww.  ja  v a  2s  .co  m*/
@SuppressWarnings("unchecked")
String provideRawEmailHeaders(InternetHeaders headers) {
    return Joiner.on("\r\n").join(Collections.list(headers.getAllHeaderLines()));
}

From source file:com.duroty.service.Mailet.java

/**
 * DOCUMENT ME!/* w w w . j av a2s .  c o m*/
 *
 * @throws Throwable DOCUMENT ME!
 * @throws OutOfMemoryError DOCUMENT ME!
 */
private void flush() throws Exception, Throwable, OutOfMemoryError {
    SessionFactory hfactory = null;
    Session hsession = null;

    try {
        hfactory = (SessionFactory) ctx.lookup(hibernateSessionFactory);
        hsession = hfactory.openSession();

        Users user = getUser(hsession, repositoryName);

        this.saveInReplyTo(messageName, mime);

        Message message = new Message();

        message.setMesBox(getBoxName(mime, user));

        mime.removeHeader("X-DBox");
        mime.saveChanges();

        StringBuffer bodyBuffer = new StringBuffer();
        Vector mailParts = new Vector();

        //Apply label/filter analysis to mimemessage
        LuceneMessage luceneMessage = prepareLuceneMessage(messageName, mime, bodyBuffer, mailParts);

        LuceneFiltersAnalysis luceneFiltersAnalysis = new LuceneFiltersAnalysis(luceneMessage, message);
        luceneFiltersAnalysis.init(null);
        luceneFiltersAnalysis.service(repositoryName, messageName, mime);

        message.setMesReferences(getParentId(messageName, mime));
        message.setUsers(user);
        message.setMesName(messageName);

        String from = "unknown from";

        try {
            from = MessageUtilities.decodeAddresses(mime.getFrom());
        } catch (Exception e) {
        }

        message.setMesFrom(from);

        String to = "unknown to";

        try {
            to = MessageUtilities.decodeAddresses(mime, javax.mail.Message.RecipientType.TO);
        } catch (Exception e) {
        }

        message.setMesTo(to);

        String cc = "unknown cc";

        try {
            cc = MessageUtilities.decodeAddresses(mime, javax.mail.Message.RecipientType.CC);
        } catch (Exception e) {
        }

        message.setMesCc(cc);

        String replyTo = "unknown replyTo";

        try {
            replyTo = MessageUtilities.decodeAddresses(mime.getReplyTo());
        } catch (Exception e) {
            replyTo = from;
        }

        message.setMesReplyTo(replyTo);

        try {
            message.setMesSubject(mime.getSubject());
        } catch (Exception e2) {
            message.setMesSubject("unknown subject");
        }

        message.setMesBody(bodyBuffer.toString());

        if (mime.getSentDate() == null) {
            if (mime.getReceivedDate() == null) {
                message.setMesDate(new Date());
            } else {
                message.setMesDate(mime.getReceivedDate());
            }
        } else {
            message.setMesDate(mime.getSentDate());
        }

        if ((message.getMesBox() != null) && message.getMesBox().equals("SENT")) {
            message.setMesRecent(new Boolean(false));
        } else {
            if (isRecent(mime)) {
                message.setMesRecent(new Boolean(true));
            } else {
                message.setMesRecent(new Boolean(false));
            }
        }

        int size = mime.getSize();
        Enumeration e = mime.getAllHeaders();

        while (e.hasMoreElements()) {
            size += ((Header) e.nextElement()).toString().length();
        }

        message.setMesSize(new Integer(size));

        try {
            InternetHeaders xheaders = MessageUtilities.getHeadersWithFrom(mime);
            Enumeration xenum = xheaders.getAllHeaderLines();
            StringBuffer buff = new StringBuffer();

            while (xenum.hasMoreElements()) {
                buff.append(xenum.nextElement());
                buff.append('\n');
            }

            message.setMesHeaders(buff.toString());
        } catch (Exception e2) {
            message.setMesHeaders("");
        }

        if ((mailParts != null) && (mailParts.size() > 0)) {
            for (int j = 0; j < mailParts.size(); j++) {
                MailPart part = (MailPart) mailParts.get(j);
                Attachment attachment = new Attachment();
                attachment.setAttContentType(part.getContentType());
                attachment.setAttName(part.getName());
                attachment.setAttPart(part.getId());
                attachment.setAttSize(part.getSize());
                attachment.setMessage(message);

                message.addAttachment(attachment);
            }
        }

        if (!message.getMesBox().equals("SPAM")) {
            parseContacts(hsession, user, mime, message.getMesBox());
        }

        //Inserto el dmail message i els attachments corresponents
        hsession.save(message);
        hsession.flush();

        indexerLucene(messageName, luceneMessage, mime);

        try {
            Iterator it = user.getMailPreferenceses().iterator();
            MailPreferences mailPreferences = (MailPreferences) it.next();

            if (mailPreferences.isMaprVacationActive()) {
                sendVacationMessage(repositoryName, from);
            }
        } catch (Exception ex) {
        }
    } finally {
        GeneralOperations.closeHibernateSession(hsession);
    }
}

From source file:org.sonatype.nexus.repository.r.internal.RHostedFacetImpl.java

@Override
@TransactionalTouchMetadata// ww  w . ja  va 2 s .  c  om
public Content getPackages(final String packagesPath) {
    checkNotNull(packagesPath);
    try {
        // TODO: Do NOT do this on each request as there is at least some overhead, and memory usage is proportional to
        // the number of packages contained in a particular path. We should be able to generate this when something has
        // changed or via a scheduled task using an approach similar to the Yum implementation rather than this method.
        StorageTx tx = UnitOfWork.currentTx();
        RPackagesBuilder packagesBuilder = new RPackagesBuilder(packagesPath);
        for (Asset asset : tx.browseAssets(tx.findBucket(getRepository()))) {
            packagesBuilder.append(asset);
        }
        CompressorStreamFactory compressorStreamFactory = new CompressorStreamFactory();
        ByteArrayOutputStream os = new ByteArrayOutputStream();
        try (CompressorOutputStream cos = compressorStreamFactory.createCompressorOutputStream(GZIP, os)) {
            try (OutputStreamWriter writer = new OutputStreamWriter(cos, UTF_8)) {
                for (Entry<String, Map<String, String>> eachPackage : packagesBuilder.getPackageInformation()
                        .entrySet()) {
                    Map<String, String> packageInfo = eachPackage.getValue();
                    InternetHeaders headers = new InternetHeaders();
                    headers.addHeader(P_PACKAGE, packageInfo.get(P_PACKAGE));
                    headers.addHeader(P_VERSION, packageInfo.get(P_VERSION));
                    headers.addHeader(P_DEPENDS, packageInfo.get(P_DEPENDS));
                    headers.addHeader(P_IMPORTS, packageInfo.get(P_IMPORTS));
                    headers.addHeader(P_SUGGESTS, packageInfo.get(P_SUGGESTS));
                    headers.addHeader(P_LICENSE, packageInfo.get(P_LICENSE));
                    headers.addHeader(P_NEEDS_COMPILATION, packageInfo.get(P_NEEDS_COMPILATION));
                    Enumeration<String> headerLines = headers.getAllHeaderLines();
                    while (headerLines.hasMoreElements()) {
                        String line = headerLines.nextElement();
                        writer.write(line, 0, line.length());
                        writer.write('\n');
                    }
                    writer.write('\n');
                }
            }
        }
        return new Content(new BytesPayload(os.toByteArray(), "application/x-gzip"));
    } catch (CompressorException | IOException e) {
        throw new RException(packagesPath, e);
    }
}

From source file:org.sonatype.nexus.repository.r.internal.RPackagesUtils.java

static Content buildPackages(final Collection<Map<String, String>> entries) throws IOException {
    CompressorStreamFactory compressorStreamFactory = new CompressorStreamFactory();
    ByteArrayOutputStream os = new ByteArrayOutputStream();
    try (CompressorOutputStream cos = compressorStreamFactory.createCompressorOutputStream(GZIP, os)) {
        try (OutputStreamWriter writer = new OutputStreamWriter(cos, UTF_8)) {
            for (Map<String, String> entry : entries) {
                InternetHeaders headers = new InternetHeaders();
                headers.addHeader(P_PACKAGE, entry.get(P_PACKAGE));
                headers.addHeader(P_VERSION, entry.get(P_VERSION));
                headers.addHeader(P_DEPENDS, entry.get(P_DEPENDS));
                headers.addHeader(P_IMPORTS, entry.get(P_IMPORTS));
                headers.addHeader(P_SUGGESTS, entry.get(P_SUGGESTS));
                headers.addHeader(P_LICENSE, entry.get(P_LICENSE));
                headers.addHeader(P_NEEDS_COMPILATION, entry.get(P_NEEDS_COMPILATION));
                Enumeration<String> headerLines = headers.getAllHeaderLines();
                while (headerLines.hasMoreElements()) {
                    String line = headerLines.nextElement();
                    writer.write(line, 0, line.length());
                    writer.write('\n');
                }/*from  w  w w  .j av  a  2 s. co m*/
                writer.write('\n');
            }
        }
    } catch (CompressorException e) {
        throw new RException(null, e);
    }
    return new Content(new BytesPayload(os.toByteArray(), "application/x-gzip"));
}