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.