BizTalk incorrect request (multipart form data) - multipartform-data

We need to send a file of xbrl format (a type of xml) to a receiving system. However, the receiving system requires that we are sending some form data as well. Regarding the xbrl file we need to send with it a form data, name="data".
Regarding the second part, we need to send an email to the system via form data. And that is name="email".
(I'll be the first to admit that I really do not understand form data at all so I cant explain much better than this).
I have a custom pipeline and in the encode stage I have put my pipeline component (the entire Execute method is down below) and after that a MIME/SMIME component (standard Microsoft).
Take a look at how the request looks like when it is being sent from Postman (and fully accepted by the receiving system):
Content-Type: multipart/form-data; boundary=--------------------------035085236562027409735938
Content-Length: 299420
----------------------------035085236562027409735938
Content-Disposition: form-data; name="data"; filename="Dk_{5AA9547A-E103-40CD-A2F4-6B77F010E570}.xbrl"
Content-Type: application/xml
<?xml version="1.0" encoding="utf-8"?>
<!- ---- Lots of removed xbrl ---- ->
</xbrli:xbrl>
----------------------------035085236562027409735938
Content-Disposition: form-data; name="email"
Content-Type: text/plain
test#test.com
----------------------------035085236562027409735938--
Now what you see below is what we have managed to achieve this far:
MIME-Version: 1.0
Content-Type: multipart/mixed;
boundary="_E9E8D52C-4722-488D-9FEC-713446D4A5C4_"
--_E9E8D52C-4722-488D-9FEC-713446D4A5C4_
MIME-Version: 1.0
Content-Type: application/xml; charset="UTF-8"
Content-Transfer-Encoding: 7bit
Content-ID: {E8CA3F1A-F953-4FFB-A054-DEB8466A5D86}
Content-Description: body
<?xml version="1.0" encoding="utf-8"?>
<!- ---- Lots of removed xbrl ---- ->
</xbrli:xbrl>
--_E9E8D52C-4722-488D-9FEC-713446D4A5C4_
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 7bit
Content-ID: {3B35ECAC-990D-458C-8E7E-9C178CA99988}
Content-Description: email
Content-Disposition: attachment; filename="=?utf-8?B?QXR0YWPobWVudDF=?="
test#test.com
--_E9E8D52C-4722-488D-9FEC-713446D4A5C4_--
Now, a quick comparison reveals that we are closing in on the solution. The first important issue must be that the Content-Type (first part below MIME-version: 1.0) is becoming multipart/mixed when we need multipart/form-data.
Second issue is in the Content-Disposition which for both parts does not, at all, look like expected.
Please take a look at my pipeline component. What you see is the entire code from the Execute. Since formDataPart.Data only takes a stream I have a method that translates a string to a stream (MemoryStream).
// Variables
var outMsg = pContext.GetMessageFactory().CreateMessage();
outMsg.Context = PipelineUtil.CloneMessageContext(pInMsg.Context);
outMsg.Context.Promote("ContentType", "http://schemas.microsoft.com/BizTalk/2003/http-properties", "multipart/form-data;");
// Process xbrl file
var msgPart = pContext.GetMessageFactory().CreateMessagePart();
msgPart.PartProperties.Write("FileName", "http://schemas.microsoft.com/BizTalk/2003/mime-properties", "SomeID.xbrl");
msgPart.PartProperties.Write("ContentDescription", "http://schemas.microsoft.com/BizTalk/2003/mime-properties", "xml");
//msgPart.PartProperties.Write("ContentTransferEncoding", "http://schemas.microsoft.com/BizTalk/2003/mime-properties", "7bit");
msgPart.Data = pInMsg.BodyPart.Data;
msgPart.ContentType = "application/xml";
msgPart.Charset = "UTF-8";
outMsg.AddPart("data", msgPart, true);
// Form data (email)
var formDataPart = pContext.GetMessageFactory().CreateMessagePart();
formDataPart.ContentType = "text/plain";
formDataPart.Charset = "utf-8";
formDataPart.PartProperties.Write("ContentType", "http://schemas.microsoft.com/BizTalk/2003/http-properties", "form-data;");
formDataPart.Data = GenerateStreamFromString("test#test.com");
outMsg.AddPart("email", formDataPart, false);
return outMsg;
Does anybody know whow we can achieve this? I can also mention that we are using the MIME/SMIME component after this custom pipeline component.
I really think that the solution from Greg Forsythe would be the best solution since I would have total control over the message but I have no idea how to translate that into actual code.
Greg_suggestion
UPDATE: After so many trials and not coming anywhere we decided to ditch the above solution and go with Gregs solution instead. There is an issue there so I hope some C# guru can help us out. Please take a look at the new question if you are struggling with the form data request issue.
Second attempt here

Related

How do I create a request in Swagger Inspector that accepts multiple data types?

I am currently trying to submit a request using the Swagger Inspector using multipart/form-data header to allow the submission of a file in conjunction with json data.
The JSON body of my request looks like:
And the headers with file upload look like:
For requests where I am just sending json to the server the Content-Type header is set to application/json and it is able to read from the body box. However I do not understand how this interface allows me to specify that the information coming from the body field is json and despite there being files on on the request.
I have seen requests that define multiple data types using the Conetent-Disspostion header, that look this this (reffenced from this Stack Overflow Post):
POST / HTTP/1.1
[[ Less interesting headers ... ]]
Content-Type: multipart/form-data; boundary=---------------------------735323031399963166993862150
Content-Length: 834
-----------------------------735323031399963166993862150
Content-Disposition: form-data; name="text1"
text default
-----------------------------735323031399963166993862150
Content-Disposition: form-data; name="text2"
aωb
-----------------------------735323031399963166993862150
Content-Disposition: form-data; name="file1"; filename="a.txt"
Content-Type: text/plain
Content of a.txt.
-----------------------------735323031399963166993862150
Content-Disposition: form-data; name="file2"; filename="a.html"
Content-Type: text/html
<!DOCTYPE html><title>Content of a.html.</title>
-----------------------------735323031399963166993862150
Content-Disposition: form-data; name="file3"; filename="binary"
Content-Type: application/octet-stream
aωb
-----------------------------735323031399963166993862150--
My question would be how do I create a request in swagger inspector that accepts multiple data types? It seems like I would need to set mulple sections in the body separated by boundaries with multiple Content-Disposition and Content-Type's for each. Would there be a cleaner way to do that through the Swagger Inspector interface? Or am I going about this in the wrong way?
Thanks!
Swagger Inspector currently supports multipart/form-data requests containing one or more files. It does not support arbitrary body parts in multipart requests (e.g. a file + JSON or text data). You'll need to use another HTTP client to test such requests.
You can submit feature request for Swagger Inspector here:
https://community.smartbear.com/t5/Swagger-Inspector-Feature/idb-p/SwaggerInspectorFeatureRequests

Gmail API still replaces text/plain alternative body part with automatically generated one from HTML

I'm using GMail API to send a MIME email. The text part of the email always gets regenerated from the HTML part.
I have tried various variations in MIME and how I structure the headers. Another man reported the same problem a few years back:
Gmail API replaces text/plain alternative body part with automatically generated one from HTML
The message shows correctly in GMail interface "Sent" items, if I view the original of the message. However, the message arrives at the destination with text part replaced with HTML part. I tested it with several destinations, including Yahoo Mail.
The relevant part of the input multipart message is:
--0000000000d81f74059447a2ad02
Content-type: text/plain; charset=UTF-8
Hello plain text
--0000000000d81f74059447a2ad02
Content-type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<b>Hello html</b>
--0000000000d81f74059447a2ad02--
Viewing the raw message at the target (Yahoo Mail) shows this:
--00000000000046bd1105948482e9
Content-Type: multipart/alternative; boundary="00000000000046bd0e05948482e7"
--00000000000046bd0e05948482e7
Content-Type: text/plain; charset="UTF-8"
*Hello html*
--00000000000046bd0e05948482e7
Content-Type: text/html; charset="UTF-8"
<b>Hello html</b>
--00000000000046bd0e05948482e7--
Here's the full test case,
https://gist.github.com/borisreitman/448e2699c267221ebbf430b64346baaa
Notice that the text part now contains "Hello html" instead of the original "Hello plain text".
The proper syntax for the message composition is confusing
You need to past your plain text content BOTH in the text/plain and text/html part of the message.
Modify your code message body as following and it will work as a charm:
--0000000000d81f74059447a2ad02
Content-type: text/plain; charset=UTF-8
Hello plain text
*Hello html*
--0000000000d81f74059447a2ad02
Content-type: text/html; charset=UTF-8
<div dir="ltr">Hello plain text<br><div><br></div><div><b>Hello html</b><br></div></div>
--0000000000d81f74059447a2ad02--

The parsing of an eml with javamail doesn't recognize properly nested messages

I'm implementing an .eml parser using Javamail 1.5.6, I've started copying from msghow.java a sample provided within javamail.
I'm testing an eml which contains as attachment another eml, this is an extract:
MIME-Version: 1.0
Date: Tue, 30 Apr 2019 16:20:45 +0200
Message-ID: <CA+fLqEW8TUfSxih9DTp2WXa63pS7wf1eZiro_9k1XS4AShN5Zg#mail.gmail.com>
Subject: Message with an eml as attachment
From: a b <ab#gmail.com>
To: cd#pec.cd.it
Content-Type: multipart/mixed; boundary="00000000000057f76c0587c01bc9"
--00000000000057f76c0587c01bc9
Content-Type: multipart/alternative; boundary="00000000000057f7670587c01bc7"
--00000000000057f7670587c01bc7
Content-Type: text/plain; charset="UTF-8"
Hello guys,
this is a simple message from a not certified account, it contains only one
attachment, an eml message
--00000000000057f7670587c01bc7
Content-Type: text/html; charset="UTF-8"
<div dir="ltr">Hello guys,<div><br></div><div>this is a simple message from a not certified account, it contains only one attachment, an eml message</div></div>
--00000000000057f76c0587c01bc9
Content-Type: message/rfc822; name="Cena zerebao.eml"
Content-Disposition: attachment; filename="Cena zerebao.eml"
Content-Transfer-Encoding: base64
X-Attachment-Id: f_jv3vpu760
Content-ID: <f_jv3vpu760>
WC1Ob3Rlcy1JdGVtOiBGcmksIDYgSnVsIDIwMTggMTc6NDA6MDAgKzAyMDA7DQogdHlwZT00MDA7
IG5hbWU9T3JpZ2luYWxNb2RUaW1lDQpYLU5vdGVzLUl0ZW06IE1lbW87DQogbmFtZT1Gb3JtDQpY
LU5vdGVzLUl0ZW06IFN0ZE5vdGVzTHRyMjU7DQo.... and so on
Javamail recognizes that eml but when I get its subject, date, body, attachments and so on, they all are null.
msghow.java itself doesn't see them.
Before javamail I implemented my parser with mime4j and I haven't this problem, but now I would like to parse emls using only javamail if possible
From the javadocs describing the mail.mime.allowencodedmessages property:
The MIME spec does not allow body parts of type message/* to be encoded. The Content-Transfer-Encoding header is ignored in this case. Some versions of Microsoft Outlook will incorrectly encode message attachments. Setting this System property to "true" will cause the Content-Transfer-Encoding header to be honored for message attachments. The default value of this property is false.

GMime multipart content

I am using the c version of the gmime library and having problems parsing and extracting content that seems to be already in multipart form. I thought parsing content as is gmime will figure out how to construct the multipart correctly so that simply performing
g_mime_multipart_get_part(mimeMessage, 0)
will return the soap-xml part. Clearly I'm wrong and my limited understanding of mime and gmime library is killing me. Please assist. Thanking you in advance.
GMimeStream * mimeStream = g_mime_stream_mem_new_with_buffer(incoming, n);
GMimeParser * mimeParser = g_mime_parser_new_with_stream(mimeStream);
g_object_unref(mimeStream);
GMimeMessage * mimeMessage = g_mime_parser_construct_message(mimeParser);
g_object_unref(mimeParser);
**RAW Content below*
------=_Part_5896175_1217116888.1478087584633
Content-Type: text/xml
<soap-env:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
...
</soap-env:Envelope>
------=_Part_5896175_1217116888.1478087584633
Content-Type: multipart/related;Start="<smil>";Type="application/smil";
boundary="----=_Part_5896174_292278572.1478087584547"
Content-ID: /mms/mm7/mm7client
------=_Part_5896174_292278572.1478087584547
Content-Type: application/smil;Name=smil.xml
Content-Transfer-Encoding: 7bit
Content-ID:<smil>
Content-Location:smil.xml
<smil><head><layout><root-layout width="320px" height="480px"/><region id="Text" left="0" top="320" width="320px" height="160px" fit="meet"/></layout></head><body><par dur="0ms"><text src="text_0.txt" region="Text"/></par></body></smil>
------=_Part_5896174_292278572.1478087584547
Content-Type: text/plain;Name=text_0.txt;Charset=utf-8
Content-Transfer-Encoding: 7bit
Content-ID:<text_0>
Content-Location:text_0.txt
Your MMS was read 02 Nov 2016 13:53
------=_Part_5896174_292278572.1478087584547--
------=_Part_5896175_1217116888.1478087584633--
GMime can't parse that because it's incomplete. How can the parser know what the multiparty boundary is if the content doesn't start with a Content-Type header that defines the boundary?

multipart/mixed decryption on blackberry 10

I am writing an app that decrypts encrypted emails for a client.
The encrypted data is in the form of an email attachment, which, when decrypted, looks like this :
Content-Type: multipart/mixed;
boundary="PGP_Universal_830ECF7A_AFB087B4_241DE401_9BE7FFD1"
--PGP_Universal_830ECF7A_AFB087B4_241DE401_9BE7FFD1
Content-Type: multipart/alternative;
boundary="PGP_Universal_904F5C3F_3A8C9E07_A3A24D11_F0FB260C"
--PGP_Universal_904F5C3F_3A8C9E07_A3A24D11_F0FB260C
Content-Type: text/plain;
charset="us-ascii"
Content-Transfer-Encoding: 7BIT
[snip]
--PGP_Universal_904F5C3F_3A8C9E07_A3A24D11_F0FB260C
Content-Type: text/html;
charset=us-ascii
Content-Transfer-Encoding: QUOTED-PRINTABLE
[html content]
--PGP_Universal_904F5C3F_3A8C9E07_A3A24D11_F0FB260C--
--PGP_Universal_830ECF7A_AFB087B4_241DE401_9BE7FFD1
Content-Type: application/pdf;
name="BB_FW_60_Manual_Key.Enrollment_Final_v1.pdf"
Content-Transfer-Encoding: BASE64
Content-Disposition: attachment;
filename="BB_FW_60_Manual_Key.Enrollment_Final_v1.pdf"
[base64 data]
--PGP_Universal_830ECF7A_AFB087B4_241DE401_9BE7FFD1--
I am writing the app in Cascades. As I cannot find a native way of transforming this data into an email, to let the email client deal with the attached base64-encoded file and so on, I am hoping to find a C++ class (it can optionally depend upon Qt, obviously) that I can use on the BB10 which can parse these kind of multipart messages.
It is possible to get SPMIME to compile on BB10. It is LGPL so it might need to be compiled seperately and linked to if your app is not GPL.

Resources