Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8431831
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T05:57:44+00:00 2026-06-10T05:57:44+00:00

I need to let users submit an email to an address which will be

  • 0

I need to let users submit an email to an address which will be used to populate entities in my database. My program will periodically check the inbox for new mail and when it finds a new mail item, I need to use the subject, from, sent date, attachments and body to populate DB entities. I have been able to get all of the fields, but I am having trouble with the body when it contains html. I just need to store the text of the email. I would like to strip out all tags, signatures, etc. from the body. Is there a better way to do this other than regex?

Here is the function I am using to get the body text. My problem lies when the mimetype hits the “multipart/*” case in the last part of the function. The function returns the html message. What can I do to strip the tags in that section other than regex?

    /**
 * Return the primary text content of the message.
 */
private String getText(Part p) throws MessagingException, IOException {
    if (p.isMimeType("text/*")) {
        String s = (String)p.getContent();
        textIsHtml = p.isMimeType("text/html");
        return s;
    }

    if (p.isMimeType("multipart/alternative")) {
        // prefer html text over plain text
        Multipart mp = (Multipart)p.getContent();
        String text = null;
        for (int i = 0; i < mp.getCount(); i++) {
            Part bp = mp.getBodyPart(i);
            if (bp.isMimeType("text/plain")) {
                if (text == null){
                    text = getText(bp);
                }
                continue;
            } 
            else if (bp.isMimeType("text/html")) {
                String s = getText(bp);
                if (s != null){
                    return s;
                }
            } 
            else {
                return getText(bp);
            }
        }
        return text;
    } 
    else if (p.isMimeType("multipart/*")) {
        Multipart mp = (Multipart)p.getContent();
        for (int i = 0; i < mp.getCount(); i++) {
            String s = getText(mp.getBodyPart(i));
            if (s != null)
                return s;
        }
    }
    return null;
}

Any and all help is much appreciated.

I’ve been trying the following, but it is resulting in the spanish á problem I have commented about below.

 else if (p.isMimeType("multipart/*")) {
        Multipart mp = (Multipart)p.getContent();
        for (int i = 0; i < mp.getCount(); i++) {
            String s = getText(mp.getBodyPart(i));
            Document doc = Jsoup.parse(s);
            String retText = doc.text();
            retText.replaceAll("[0%d0%a]", "<br />");
            if (retText != null)
                return retText;
        }
    }

I have also tried [\r\n] and [\n] as my regex.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T05:57:45+00:00Added an answer on June 10, 2026 at 5:57 am

    You can use some HTML parser like jsoup to traverse the HTML code and extract just the text that you want.

    Take a look:

    • http://jsoup.org/cookbook/introduction/parsing-a-document
    • http://jsoup.org/apidocs
    • http://jsoup.org/apidocs/org/jsoup/Jsoup.html
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to let users of an application open a folder by clicking a
I have a cart on my website and I need to let users easily
In my web application, I need to let users (mostly IE browsers) to click
In my project I need to write small WYSIWYG editor (just let users make
I have a simple application in which I need to let the user select
I have a C# project using windows forms. I need to let the user
Basically in order to have a profile Block u need - let's say profile
Let's say I need to upload files to a server programmatically using uploading a
Let's say I need to take names of movies the person likes. I don't
Let me explain: I need to sort a list in ascending order, while results

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.