Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

how to decode Quoted-printable content to plain text

milan_dobias
Explorer
0 Kudos

Hi all,

I need a help with decoding body of incoming email (type MHT).

After reading content of email (body) in Sap Office I get text table with content like this...

But I need to get only a plain text to processing this text ...

Can somebody help me to show how to decode such a content with quoted-printed ?

Thanks a lot for any idea...

Best regards,

MD

Example of email's body (MTH , MHTML)...

Content-Type: multipart/related;

boundary="----=_Part_15_25978208.1277465809718"

-


=_Part_15_25978208.1277465809718

Content-Type: text/plain; charset="utf-8"

Content-Transfer-Encoding: quoted-printable

Dobr=C3=BD den,

p=C5=99=C3=ADlohou tohoto e-mailu jsou data z formul=C3=A1=C5=99e vypln=C4=

=9Bn=C3=A9ho u=C5=BEivatelem na str=C3=A1nk=C3=A1ch www.cez.cz.

typ formul=C3=A1=C5=99e: PLYN

verze formul=C3=A1=C5=99e: DOM_EXT

kampa=C5=88: KAM2

EAN/OM: 1234567890

=C4=8D=C3=A1rov=C3=BD k=C3=B3d: 5E5200ZZ02-90003246=20

-


=_Part_15_25978208.1277465809718--

1 ACCEPTED SOLUTION

Sandra_Rossi
Active Contributor
0 Kudos

Remark: if you receive mails from outside SAP (as it seems here), you can decode the mail initially by creating a custom class (interface IF_INBOUND_EXIT_BCS) + doing some customizing in transaction SO50. You receive an object of type CL_SEND_REQUEST_BCS. See [sap library|http://help.sap.com/saphelp_nw70/helpdata/EN/f8/5f633acc19a33be10000000a11402f/frameset.htm] for more information.

> reading content of email (body) in Sap Office

What do you use to read it? Maybe you use the wrong method? (or not a one which fits the best)

Anyhow, if you want to decode the mime data, here is the general algorithm:

1) Use CALL METHOD cl_bcom_mime=>as_reference as the first command to parse mime data.

2) This method returns an object (probably of type cl_bcom_mime_multi_related as your example states a multipart/related mime object) that you can work with (especially using get_bodypart_as_reference_list method).

4 REPLIES 4

Jelena
Active Contributor
0 Kudos

Search for the function modules / classes that would convert MHTML to plain text. Otherwise, it should be possible to call an external program for that.

I'm also curious why do you need to do this whole thing... What are you trying to achieve?

Sandra_Rossi
Active Contributor
0 Kudos

Remark: if you receive mails from outside SAP (as it seems here), you can decode the mail initially by creating a custom class (interface IF_INBOUND_EXIT_BCS) + doing some customizing in transaction SO50. You receive an object of type CL_SEND_REQUEST_BCS. See [sap library|http://help.sap.com/saphelp_nw70/helpdata/EN/f8/5f633acc19a33be10000000a11402f/frameset.htm] for more information.

> reading content of email (body) in Sap Office

What do you use to read it? Maybe you use the wrong method? (or not a one which fits the best)

Anyhow, if you want to decode the mime data, here is the general algorithm:

1) Use CALL METHOD cl_bcom_mime=>as_reference as the first command to parse mime data.

2) This method returns an object (probably of type cl_bcom_mime_multi_related as your example states a multipart/related mime object) that you can work with (especially using get_bodypart_as_reference_list method).

0 Kudos

Hi,

reason, why I need to get a plain text of incomming emails from SapOffice, is that our customer needs a functionality to send automatically answer (as email) for incomming emails. That is a reason why I need to get a plain text to create answer ..

I solved my problem using class cl_crm_email_utility_base....There is an example of my solution.

Thanks a lot for Your answer...

Best regards,

Milan Dobias

DATA: lo_mail_object TYPE REF TO cl_crm_email_data,

lv_content_plain TYPE string,

OBJCONT type table of SOLI.

FIELD-SYMBOLS: <fs_body> TYPE crms_email_mime_struc.

CALL METHOD cl_crm_email_utility_base=>get_mail_data_from_so

EXPORTING

iv_folder_id = folder_id

iv_object_id = object_id

  • iv_send_request_id =

RECEIVING

er_mail_data = lo_mail_object

EXCEPTIONS

not_found = 1

OTHERS = 2

.

IF sy-subrc <> 0.

MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4

RAISING x_error.

ENDIF.

IF lo_mail_object IS BOUND.

LOOP AT lo_mail_object->body ASSIGNING <fs_body>

WHERE is_attachment IS INITIAL.

lv_content_plain = <fs_body>-content_ascii.

EXIT.

ENDLOOP.

ENDIF.

REFRESH: objcont.

SPLIT lv_content_plain AT cl_abap_char_utilities=>cr_lf INTO TABLE objcont.

0 Kudos

Hi Milan,

thank you for the feedback and for the solution.

I think that, ideally, you should have used the user exit I mentioned above.

Well, if it works now, that's fine!

Sandra