"remove figure tags  REPLACE ALL OCCURRENCES OF REGEX '\[[^\s]+\]' IN lv_body_cont WITH space. "remove HMTL tags <> </> REPLACE ALL OCCURRENCES OF REGEX '<[a-zA-Z\/][^>]*>' IN l_html_string WITH space.
Inbound Email processing for MHT document type
- Receiving E-Mail and processing it with ABAP from Thomas Jung
- Advanced Inbound Email Handling from Christian Drumm
- Offline/External Mail Approval Process without using SAP
Where to get MHT email contents?
DATA: lo_document TYPE REF TO if_document_bcs, lo_mail_content TYPE bcss_dbpc, lt_solix TYPE solix_tab, l_xlength TYPE i, l_html_string TYPE string, l_html_string_c(4000), binary_file type xstring. FIELD-SYMBOLS : <bin_line> TYPE solix. "whole document lo_document = io_sreq->get_document( ). "all email contents lo_mail_content = lo_document->get_body_part_content(). "email contents lt_solix = lo_mail_content-cont_hex. "contents in binary CLEAR binary_file. LOOP AT lt_solix ASSIGNING <bin_line>. CONCATENATE binary_file <bin_line>-line INTO binary_file IN BYTE MODE. ENDLOOP. l_xlength = xstrlen( binary_file ). " get string of Email body from binary CALL FUNCTION 'SCMS_BINARY_TO_STRING' EXPORTING input_length = l_xlength IMPORTING text_buffer = l_html_string " <===what we need TABLES binary_tab = lt_solix.
How to decode the MHT email body?
*----------could mix with text/picture/html~ only collect text part DATA: lo_email_data TYPE REF TO cl_crm_email_data, ls_mht_body TYPE crms_email_mime_struc, lv_body_cont TYPE string, lv_body_cont_c(4000). lo_email_data = cl_crm_email_utility_base=>get_mail_data_from_mime( l_html_string ). LOOP AT lo_email_data->body INTO ls_mht_body. IF ls_mht_body-is_attachment EQ 'X'. "skip attachemnt as only collect comments CONTINUE. ENDIF. IF ls_mht_body-mime_type = 'text/plain'. "only collect comments from this part! lv_body_cont = ls_mht_body-content_ascii. EXIT. ELSEIF ls_mht_body-mime_type = 'text/html'. "... * lv_body_cont = ls_mht_body-CONTENT_ASCII. ELSE. CONTINUE. ENDIF. ENDLOOP.
PS: If SAP Blog provides a private flag, maybe I’ll set it for many of my posts because the same topic has been discussed many times and I couldn’t write a better one compared with the existing one. Still, sometimes it’s difficult to figure the issue out with help of GOOGLE and the community, or it may take hours to validate various solutions. So in most cases, I summarize related details and record my finding as a reminder. I’m glad if it helps others by chance, if it doesn’t, please forgive me keep posting such content without any buzzword.