Entire HTML content of mail not accessible and original mail changes to rich text after retrieving the HTML part of it

泄露秘密 提交于 2020-01-06 05:21:48

问题


The entire HTML content in a Lotus notes mail is not retrievable using some methods that i have tried.I get a part of the HTML which looks like rich text and with a lot of "=A0" s in the content but not the entire content with the CSS and styling. Also after i retrieve this incomplete HTML content, the original mail changes to rich text, event though i set session.setConvertMIME(true);. I have right clicked on the mail to go to document properties and i have seen the entire HTML content in one of the Body attributes of the mail, it is truncated but if i can get a hold of it via code i think my problem will be partially solved.enter image description here I have tried a variant of solution suggested in this question:Unable to fetch HTML content from mail in Lotus Notes, getMIMEEntity() returns a null even after setConvertMIME(false). Using this i was able to get the partial HTML whereas before this i was not even able to access the HTML in the mail. When the same mail is received in Outlook, i am able to access the entire HTML content there via right click context menu and via code (HTMLBody property of mail).

CODE SECTION :

   public static String getHTMLContentFromMailDocument(Document mailDoc){
          Document selectedDoc = mailDoc;
          String htmlBody ="";
            try{
                Database database = selectedDoc.getParentDatabase();
                Session session = database.getParent();

                if (session.isConvertMime()) {
                    // Do not convert MIME to rich text.
                    session.setConvertMIME(false);
                }
                Item item = selectedDoc.getFirstItem("Body");           
                    MIMEEntity mimeEntity = null;                                           
                    if (item != null) {
                        if (item.getType() == Item.RICHTEXT ) {
                    // Convert Notes rich text to MIME                      
                            Stream stream = ShelfSession.getInstance().getSession().createStream();                         
                            Document _tempDocument = database.createDocument();
                            _tempDocument.copyItem(item, "Body");   
                            _tempDocument.convertToMIME(lotus.domino.Document.CVT_RT_TO_PLAINTEXT_AND_HTML, 0);
                            mimeEntity = _tempDocument.getMIMEEntity("Body");
                            mimeEntity.setContentFromText(stream,  "text/html", 1727);
                        } 
                        else if(item.getType()== Item.MIME_PART ){
                            mimeEntity = item.getMIMEEntity();
                        }
                        MIMEEntity currentEntity = null;
                        currentEntity = mimeEntity.getNextEntity();                 
                        while(currentEntity !=null){                        
                            if(currentEntity.getContentSubType().compareTo("html")==0){                         
                                 htmlBody = currentEntity.getContentAsText();                           
                                break;
                            }
                            currentEntity = currentEntity.getNextEntity();
                        }

                        session.setConvertMIME(true);
                        return htmlBody;
                    }

                return "";
            }
            catch(Exception e){
                log.error(e);
                return "";
            }
      }

I have added the expected output and the actual output files in this location : https://sap-my.sharepoint.com/:f:/p/a_ramesh/EhhfOyzQ4RdEovR94S-IXGIBP7AH2ITj9sddvtXR27LUZA?e=Xq4Uvu CurrentProblem : CurrentProblem.html and CurrentProblem.txt files. Expected Result : Outlook.html and OutlookHTMLExpected.txt files.

来源:https://stackoverflow.com/questions/58518245/entire-html-content-of-mail-not-accessible-and-original-mail-changes-to-rich-tex

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!