In our application we are reading the emails from Gmail using iMap and saving in DB, In email there are two attachments (one is pdf file and other is digital signature file). For first file (pdf) I am getting disposition null and not able to process the attachment but for second file (p7s) getting right disposition value as attachment.
Following is header information of attachments:
------=_NextPart_001_0025_01D03944.5B3A2140
Content-Type: application/pdf;
name="USXMS III Draft PUS - VOPR # 15-814.pdf"
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
filename="USXMS III Draft PUS - VOPR # 15-814.pdf"
------=_NextPart_000_0024_01D03944.5B3A2140
Content-Type: application/pkcs7-signature; name="smime.p7s"
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="smime.p7s"
Following is relevant code to process the attachments of email:
//Process attchements of email
protected processAttachments(def workItem, def message) {
int attachmentCount = 0
def content = message.content
if (content instanceof Multipart) {
for (cntr in 0..(content.count - 1)) {
def bodyPart = content.getBodyPart(cntr)
def disposition = bodyPart.getDisposition()
println("Disposition is " + disposition + ".");// returns null for pdf
if (Part.ATTACHMENT.equalsIgnoreCase(disposition)) {
if (this.saveAttachments(workItem, bodyPart)) {
attachmentCount++
}
}
}
}
return attachmentCount
}
So in above code getDisposition returns null for pdf file. Please let me know if you need more information.
Issue resolved as it was nested content. In case of disposition is null I have to loop through the content to find attachment(s).
Related
I want to send email after post build action in jenkins. Hence I have write jenkinsfile as follows. But i want to send mail with pdf attachment.
Note: Please don't suggest email plugin procedure & configuration. I preferred Jenkins file method configuration
post {
success {
script {
echo "Success!! e-mailing scan results url to ${emailRecipients}"
mail(from: emailFrom, subject: emailSubjectCDSuccess + COMMIT, to: emailRecipients, body: emailBodyCheckmarx)
}
}
failure {
script {
echo "Failure :( !! e-mailing scan results url to ${emailRecipients}"
mail(from: emailFrom, subject: emailSubjectCDFailure, to: emailRecipients, body: emailBodyCD)
}
}
}
Instead of the default Email step, use the Email Extension Plugin, which allows you to add attachments.
emailext(
subject: "SUBJECT",
attachLog: true, attachmentsPattern: "**/*.txt",compressLog: true,
body: "Test Email" ,to: adress#g.com)
not an answer
try approximately the following parameters of mail step:
def boundary = '----------12345'
def attachment = 'hello world'.bytes.encodeBase64() //read bytes from file and encode as base64
def body = 'hello body'.getBytes('UTF-8').encodeBase64()
mail(
...
mimeType: "multipart/mixed; boundary=${boundary}",
//you can't add extra-spaces or drop empty lines in following string
body: """
${boundary}
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: base64
${body}
${boundary}
Content-Type: application/octet-stream; name="my-attachment.txt"
Content-Disposition: attachment
Content-Transfer-Encoding: base64
${attachment}
${boundary}--
""".trim()
)
I am fairly new to angular and i am trying to send a name and image file to my server which is written in rails. But the data i am being received on my server is not correct and i have tried many fixes but nothing seems to be working. The request payload that being sent is this
-----WebKitFormBoundaryhRvQy5dRArcb6BfP
Content-Disposition: form-data; name="project[logo]"; filename="badge.png"
Content-Type: image/png
------WebKitFormBoundaryhRvQy5dRArcb6BfP
Content-Disposition: form-data; name="project[name]"
abc
------WebKitFormBoundaryhRvQy5dRArcb6BfP--
This is not being accepted in rails server and returns me a bunch of gibberish in the console/log
��2˾F
2ƺx���;p}}�0���'�C�F
��b7�Ӡ�}��c��Ii���W8��I#�<dy���}4�|���{c��5�iV�#�����*�����'��
:ظ�<+�I5��^��ԓk�qi���R91R��pi7QZϢ�����V�m��� �(��8�m�c%OGN#�k��k2�>_O�����^Ya��+�����1������^�����K�3�07q���{7�ܶ0+��&sZ����w7�>f�^��A�/����d�����g�i�
PG?_��u�����5�i2��F$��\7(�ԟ�t8e9�3�9=Lk�#��ֽ��3��%FJ�QjI����f���qmI4֍4�^��P|�S���)Ԋ0Җ�AEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPE�����͊O6c��>y?횜����5�Z��Nuf��qr}ݶK�N�K�k̨BU'E^Ri/�W���G/�C�W?f��
RT������ׯ!�8a\�z�_^���Z�ݺEm�(��|��GJ�iS�8�k�{��ۻ��#��+"(��(�`��+��(��(��(��$��"��
2:�V��G��j���K`�S�LI���s�C�����+�����-h)[��q�
��/�^洫T��NMw[�^�z?]���%��ki
z�ͭ��f+��T��a���� S��H:��dz���{2���5
���A#���qڇ��t�D�D2LGz�q��`��nM|�/)�B�z���K��^p__�
���
This is my service.ts
postCreateProject(logo, name)
{
const formData: FormData = new FormData();
const url = EndPoints.BASE_URL + EndPoints.Projects;
formData.append('project[logo]', logo);
formData.append('project[name]', name)
console.log(formData.get('project[logo]'))
return this.httpService.postFileUpload(url, formData);
This is my postFileUpload in the httpService
postFileUpload(url: string, fmd: FormData): Observable<any> {
console.log('post file upload')
const headers = new HttpHeaders();
headers.append('Form-Data','FileUpload');
// headers.set('Content-Type', 'multipart/form-data');
// headers.set('Accept', 'application/json');
return this.http.post(url, fmd, {headers : headers});
}
If you need additional files please ask. Thanks for helping.
If you're using rails 5+ and angular 4+, you might try excluding the headers and just having
return this.http.post(url, fmd).
That's what I do (rails 6 with angular 10) and the data on the rails end is correct.
I am new in Spring 5 and Reactive Programming. My problem is creating the export feature for the database by a rest API.
User hits GET request -> Server reads data and returns data as a zip file. Because zip file is large, so I need to stream these data.
My code as below:
#GetMapping(
value = "/export",
produces = ["application/octet-stream"],
headers = [
"Content-Disposition: attachment; filename=\"result.zip\"",
"Content-Type: application/zip"])
fun streamData(): Flux<Resource> = service.export()
I use curl as below:
curl http://localhost/export -H "Accept: application/octet-stream"
But it always returns 406 Not Acceptable.
Anyone helps?
Thank you so much
The headers attribute of the #GetMapping annotation are not headers that should be written to the HTTP response, but mapping headers. This means that your #GetMapping annotation requires the HTTP request to contain the headers you've listed. This is why the request is actually not mapped to your controller handler.
Now your handler return type does not look right - Flux<Resource> means that you intend to return 0..* Resource instances and that they should be serialized. In this case, a return type like ResponseEntity<Resource> is probably a better choice since you'll be able to set response headers on the ResponseEntity and set its body with a Resource.
Is it right, man? I still feel it's not good with this solution at the last line when using blockLast.
#GetMapping("/vehicle/gpsevent", produces = ["application/octet-stream"])
fun streamToZip(): ResponseEntity<FileSystemResource> {
val zipFile = FileSystemResource("result.zip")
val out = ZipOutputStream(FileOutputStream(zipFile.file))
return ResponseEntity
.ok().cacheControl(CacheControl.noCache())
.header("Content-Type", "application/octet-stream")
.header("Content-Disposition", "attachment; filename=result.zip")
.body(ieService.export()
.doOnNext { print(it.key.vehicleId) }
.doOnNext { it -> out.putNextEntry(ZipEntry(it.key.vehicleId.toString() + ".json")) }
.doOnNext { out.write(it.toJsonString().toByteArray(charset("UTF-8"))) }
.doOnNext { out.flush() }
.doOnNext { out.closeEntry() }
.map { zipFile }
.doOnComplete { out.close() }
.log()
.blockLast()
)
}
I have an ASP.net application that allows the users to report bugs and attach files. The bug together with its detail and attachments should be saved in FogBugz.
I have managed to create everything except the file attachment part.
here is my code:
private void NewCaseWithFile()
{
string fbUrl = "https://test.fogbugz.com/api.asp";
string fbToken = logInFogBugz();
string param = "";
param += "cmd=new";
param += "&token=" + fbToken;
param += "&sTags=" + "OnlineService,";
param += "&sTitle=" + "Testing";
param += "&sEvent=" + "This case is being created from Visual Studio";
param += "&nFileCount=" + "1";
param += "&File1=" + "Picture.png";
HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(fbUrl + "?" + param);
httpWebRequest.Method = WebRequestMethods.Http.Post;
httpWebRequest.ContentType = "multipart/form-data";
httpWebRequest.Accept = "application/xml";
httpWebRequest.ContentLength = 0;
HttpWebResponse response = (HttpWebResponse)httpWebRequest.GetResponse();
StreamReader streamReader = new StreamReader(response.GetResponseStream());
XDocument doc = XDocument.Load(streamReader);
}
I have tried all instructions under "Editing Cases" but it did not help. In fact I have no idea what are File 1, File 2 and how to send them to FogBugz.
Can anyone help me with this?
Many thanks!
File1 should be specified in the body of your multipart/form-data post (not as a querystring parameter).
You actually have to specify all the bytes in the file.
There's an answer on fogbugz.stackexchange.com as well as a C# FogBugz API wrapper that will handle all the parts for you.
The form parts in the body of your post would look like
--sdfjdsjsdflk SOME BOUNDARY--
Content-Disposition: form-data; name="File1"; filename="foo.jpg"
Content-Transfer-Encoding: base64
Content-Type: image/png
slfkajdflksjflajfdj
sldfjsd;aljfds
these are actual data bytes from the foo.jpg file
slfkjdsfljds
sdflajsdfs
Or you can look at this question which points to an RFC with an example.
I'm trying to develop a Mule application with inbound IMAP connector. It works fine when the incoming mail is plain text but when it's HTML or Rich Text there's no text in the payload. How to make the application independent of the incoming mail type?
HTML or Rich Text are most probably MIME multipart emails. In that case, Mule tries to extract the text has payload only if the multipart email contains a first part that is has a content type starting with text/ (like text/plain). I reckon that in your case, the multipart email doesn't match this rule, thus Mule doesn't know what to do with it.
I suggest you use a choice router to deal with the case when there's no text in the payload after the email has been received. In that case, use whatever logic that is relevant to you to extract the content from one of the inbound attachments into which the different parts have been transferred.
I've been able to write some Java-code that bring out the text-part of a multipart message but I can't find a way to get this working with Mule. MUle wants to load the class with a String even though it's a multi part message.
The code I've written is below:
import javax.activation.DataHandler;
import javax.mail.*;
public class ReadMultipartMail3 {
public String stringback(Part payload) throws Exception {
String answer ="";
if(payload.isMimeType("text/plain") || payload.isMimeType("text/html"))
{
answer=(payload.getContent().toString());
}
else{
Multipart multipart = (Multipart) payload.getContent();
for (int x = 0; x < multipart.getCount(); x++) {
Part p = multipart.getBodyPart(x);
System.out.println("Content Type: "+p.getContentType());
BodyPart bodyPart = multipart.getBodyPart(x);
String disposition = bodyPart.getDisposition();
if (disposition != null && (disposition.equals(BodyPart.ATTACHMENT))) {
System.out.println("Mail have some attachment : ");
DataHandler handler = bodyPart.getDataHandler();
System.out.println("file name : " + handler.getName());
} else {
if(p.isMimeType("text/plain") || p.isMimeType("text/html"))
{
answer = (p.getContent().toString());
}
else if (p.isMimeType("multipart/alternative"))
{
Multipart mp = (Multipart)p.getContent();
int partsCount = mp.getCount();
for (int z = 0; z < partsCount; z++) {
System.out.println("Content Type: "+z+" "+mp.getBodyPart(z).getContentType());
if(mp.getBodyPart(z).getContentType().contains("text/plain"))
{answer = (String) mp.getBodyPart(z).getContent();}
}
}
}
}
}
return answer;}}