Results 1 to 7 of 7

Thread: Get Email details from Message Object ( Message.java or ParsedMessage.java)

Hybrid View

  1. #1
    Join Date
    Oct 2007
    Posts
    6
    Rep Power
    7

    Default Get Email details from Message Object ( Message.java or ParsedMessage.java)

    How do I get email details like

    # Text Body
    # HTML Body

    from Message object (Message.java or ParsedMessage.java) ?.

  2. #2
    Join Date
    Aug 2005
    Posts
    1,433
    Rep Power
    12

    Default

    Look at ToXML.java and the functions in Mime.java that they call.
    Bugzilla - Wiki - Downloads - Before posting... Search!

  3. #3
    Join Date
    Oct 2007
    Posts
    6
    Rep Power
    7

    Default

    Thanks for the reply. So I did following to get the text content out the email

    List<MPartInfo> parts = Mime.getParts(mMimeMessage);
    MPartInfo body = Mime.getTextBody(parts, false);
    InputStream is = body.getMimePart().getInputStream();
    String emailBody = getStringContent(is); //custom method to extract String out of inputstream.

    Now I have another problem here. when I look at the email body string I see encoded characters like "=E2=80=99" in the whole body. e.g.

    "Word on the street is that Best Buy - which already had photo-sharing throu=
    gh Kodak - didn=E2=80=99t ......"

    Now This is a problem when I have to take this String and save it to the DB via some persistance layer like Hibernate or so. Hibernate pukes out when it sees these characters and if I manually remove these characters data gets saved just fine. Any idea on what level I should be decoding these characters. Infact this comes out in Mime itself. so right from the email source text comes like this.

    -regards,

  4. #4
    Join Date
    Aug 2005
    Posts
    1,433
    Rep Power
    12

    Default

    I think you have a broken test message. The "=EF" characters you're seeing are quoted-printable-encoded characters. JavaMail says that Part.getInputStream() should do the following:
    Return an input stream for this part's "content". Any mail-specific transfer encodings will be decoded before the input stream is provided.
    So if you're seeing QP-encoded characters, my guess is that either (a) your message is missing the Content-Transfer-Encoding: quoted-printable header line, or (b) you're calling MimeBodyPart.getContentStream() method instead.
    Bugzilla - Wiki - Downloads - Before posting... Search!

  5. #5
    Join Date
    Oct 2007
    Posts
    6
    Rep Power
    7

    Default

    Let me answer your questions first in >>>

    So if you're seeing QP-encoded characters, my guess is that either (a) your message is missing the Content-Transfer-Encoding: quoted-printable header line, or
    >>> Email message has the Content-Transfer-Encoding: quoted-printable, The header looks something like this in the email file

    Content-Type: text/plain; charset=utf-8
    Content-Transfer-Encoding: quoted-printable



    (b) you're calling MimeBodyPart.getContentStream() method instead.
    >>> Infact Im using Zimbra's ByteUtil.getContent(is, 0) to get the String out of Inputstream. I tried changing it to Mime.getStringContent(<mimepart>); not much luck either.


    Now this is what I'm doing.

    # I have Zimbra (client and server) installed on my laptop (mac os x)
    # I went to some random web page on the net, took at block of text , opened the Zimbra Mail client , created a new mail (HTML enabled: by selecting 'Format as HTML' under 'Options'), pasted the copied text from the webpage

    # Sent an email to some address.
    # Because I have server on the same machine, I capture the email sent out and that email has a body which has those =E2=80=99 characters.

    (e.g The copied text from the web page on the internet was something like Mydeo’s which gets looks like Mydeo=E2=80=99s in the email message file)

    Now this is via Zimbra client.

    Now If I try same thing with something like GMAIL , it works fine and email message file is encoded properly. the word looks like Mydeo's in Gmail email message file. and I see following in GMail mail message file

    Content-Type: text/plain; charset=ISO-8859-1
    Content-Transfer-Encoding: 7bit

    So how do I resolve this issue?

    regards,

  6. #6
    Join Date
    Aug 2005
    Posts
    1,433
    Rep Power
    12

    Default

    Quote Originally Posted by legalizenet View Post
    (b) you're calling MimeBodyPart.getContentStream() method instead.
    >>> Infact Im using Zimbra's ByteUtil.getContent(is, 0) to get the String out of Inputstream. I tried changing it to Mime.getStringContent(<mimepart>); not much luck either.
    I'd need to see a copy of your message to reproduce this. This seems odd, however, as the same code path is used to render the message in the web client. If you don't see the "=E2=80=99" when you view the message in the web client, there's probably something off in your code...
    Quote Originally Posted by legalizenet View Post
    Now If I try same thing with something like GMAIL , it works fine and email message file is encoded properly. the word looks like Mydeo's in Gmail email message file. and I see following in GMail mail message file

    Content-Type: text/plain; charset=ISO-8859-1
    Content-Transfer-Encoding: 7bit
    Zimbra defaults to utf-8 as the charset for outbound mail (though you can override this in 5.0). Gmail apparently defaults to iso-8859-1. Had you pasted in some chinese characters, Gmail would have used utf-8 as well.
    Bugzilla - Wiki - Downloads - Before posting... Search!

Similar Threads

  1. One account not receving email
    By EnglishDude in forum Administrators
    Replies: 12
    Last Post: 04-30-2010, 06:19 AM
  2. Email Message will not display
    By jwilso2 in forum Developers
    Replies: 3
    Last Post: 08-02-2009, 10:47 PM
  3. need advice on configuring zimbra to work with fax server
    By pheonix1t in forum Administrators
    Replies: 0
    Last Post: 07-11-2007, 07:46 PM
  4. upgrade to 4.0.3 antispam does'nt work
    By lucanannipieri in forum Administrators
    Replies: 14
    Last Post: 11-07-2006, 02:56 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •