0

I am fetching raw data from Gmail API. I decrypt the data and get the desired contents in basic implementation.

I get the problem when I have an image in my signature and also I am sending some attachments, then the Gmail JSON data gets complex hierarchal structure and as a result, I am not able to get the email message content.

From email message content, I mean the custom message we write such as "Hello, How are you?".

I am getting all the other stuff like sendTo, attachments etc.

I am getting the Gmail API raw data from the chrome app and then I am sending it to my OFBiz server where it is decrypted and processed.

UPDATE: After my searching around, I found out that the problem is the limitation of MimeMessageWrapper.java in OFBiz.

The following code works well upto format partId: 0.0, 0..1 etc.

public String getMessageBody() {
        MimeMessage message = getMessage();
        if (getMainPartCount() == 0) { // single part message
            try {
                Object content = message.getContent();
                return getContentText(content);
            } catch (Exception e) {
                Debug.logError(e, module);
                return null;
            }
        }
        StringBuffer body = new StringBuffer();
        for (int i = 0; i < getMainPartCount(); i++) {
            int subPartCount = getSubPartCount(i);
            String idx = Integer.toString(i);
            if (subPartCount > 0) {
                for (int si = 0; si < subPartCount; si++) {
                    String sidx = idx + "." + Integer.toString(si);
                    if (getPartContentType(sidx) != null && getPartContentType(sidx).toLowerCase(Locale.getDefault()).startsWith("text")) {
                        if (getPartDisposition(sidx) == null || getPartDisposition(sidx).equals(Part.INLINE)) {
                            body.append(getPartText(sidx)).append("\n");
                        }
                    }
                }
            } else {
                if (getPartContentType(idx) != null && getPartContentType(idx).toLowerCase(Locale.getDefault()).startsWith("text")) {
                    // make sure the part isn't an attachment
                    if (getPartDisposition(idx) == null || getPartDisposition(idx).equals(Part.INLINE)) {
                        body.append(getPartText(idx)).append("\n");
                    }
                }
            }
        }
        return body.toString();
    }

Need to improve this code. Please suggest some good way to do so.

Pallavi Goyal
  • 536
  • 1
  • 4
  • 21
  • when you say custom message, do you mean the [payload.body](https://developers.google.com/gmail/api/v1/reference/users/messages) of the message? – ReyAnthonyRenacia Jun 21 '18 at 11:39
  • Yes, by the custom message, I mean the body part of the type 'text/plain' and 'text/html'. – Pallavi Goyal Jun 22 '18 at 05:42
  • 1
    Hi Pallavi, this should be better shared on the OFBiz user ML. Remember the Apache Fundation mentra: if it does not happen on ML it does not happen at all ;) Thanks! http://ofbiz.apache.org/mailing-lists.html – JacquesLeRoux Jun 23 '18 at 07:41
  • Thanks, Jacques, totally agreed. I will post it in ML. :) – Pallavi Goyal Jun 25 '18 at 04:18

0 Answers0