I am working with OpenAS2Server-1.3.3 library.
There sending a single document is working fine..
Now I wanted to modify it to send document with attachments, like we do with emails. In this scenario, all the decription work well, but signature verification failed (MIC is not matched)
This is how I am tring to send attachments with main doc:
Create a MimeMultipart and add two MimeBodyPart into it. (main document and the attachment)
Finally wrap the MimeMultipart within a MimeBodyPart (I am not sure this is the way to do this, but anyway Bouncycastle do not have API to sign MimeMultipart )
Could anyone tell me the correct way to sign a message with attachment ?
MimeBodyPart mainBody = new MimeBodyPart();
mainBody.setDataHandler(new DataHandler(byteSource));
MimeBodyPart attachemt1 = new MimeBodyPart();
attachemt1.attachFile("/home/user/Desktop/Test1.txt");
Multipart multipart = new MimeMultipart();
multipart.addBodyPart(mainBody);
multipart.addBodyPart(attachemt1);
MimeBodyPart body = new MimeBodyPart();
body.setContent(multipart);
body.setHeader("Content-Type", multipart.getContentType());
logger.info("--------------Attaching the file... Done");
I was able to get the issue and solution. I am just putting it here for anyone else who will try to do this kind of work.
I just dump the data that use for calculating MIC, at both sending side and receiving side. So the attached image will show the problem clearly.
So I added those header fields manually for all the attachments and main doc, at the sending side, as bellow.
mainBody.setHeader("Content-Type", "application/EDI-X12");
mainBody.setHeader("Content-Transfer-Encoding", "7bit");
Now it solved and "MIC is matched".
Related
I have this bit of code that creates a calendar for a specific delivery, and then attaches it to an e-mail to be send. The problem is, when I attach the .ics file, the template breaks (no text, no pictures... nothing). Only the calendar file gets send (even though it does get send to the right e-mail).
const event = await this.calendarService.getEventForDelivery(deliveryId);
await this.sendMailjetTemplate('4069368', d.email, [{contentType: 'text/calendar', content: event}], {
ASN: d.identifier,
});
I fixed my issue by specifying a "text" attribute to my mail.
As an experiment, I was trying to find whether I could read files that were entered as attachments into chat eg: image files, txt, etc.
I've been looking around for a long while and I have still found no information on it.
So it possible to do this using Discord.js? If so, how would I go about doing it?
This can be done using the attachments property of a Message to find the attachment and consequently its URL. You can then download the URL using the http and fs modules. It would look something like this:
dClient.on('message', msg => {
if (msg.attachments) {
for (var key in msg.attachments) {
let attachment = msg.attachments[key];
download(attachment.url);
}
}
});
I'm working on project which can access all the pictures in g-mail.I've tried the G-mail API using node which can fetch all required attachments.But that requires to download the whole image.I can access the attachment id and message id using the API.Is there any way to generate the url of attachment (to view) so that i can provide a link to the required image from my project.
I actually found this related issue, Issue #134, and you may want to try the suggested solution.
You may fetch email attachments using this:
https://mail.google.com/mail/u/0/?ui=2&ik={ik_value}&view=att&th={message_id}&attid=0.{atachment_index}&disp=safe&zw
wherein, attachmment_index is just the index of the attachment. If there are 3 attachments and you want to get the 3rd file, the index value will be 3. This URL is a 302 header that acts like a link shortener for the download file. Opening this link will lead you to the attachment data
var ik = gmail.tracker.ik;
var id = gmail.get.email_id();
var aid = "1"; // gets the first attachment
var url = "https://mail.google.com/mail/u/0/?ui=2&ik=" + ik + "&view=att&th=" + id + "&attid=0." + aid + "&disp=safe&zw";
console.log(url);
I am currently doing a POST to a Web Api method and am posting an array of objects. When I get to the method, my parameters are resolved properly, and I make a call to the DB and return a list of records.
I then take those records and convert them to a MemoryStream to be downloaded by the browser as an Excel spreasheet. From there, I create an HttpResponseMessage object and set properties so that the browser will recognize this response as a spreadsheet.
public HttpResponseMessage ExportSpreadsheet([FromBody]CustomWrapperClass request){
var result = new HttpResponseMessage();
var recordsFromDB = _service.GetRecords(request);
MemoryStream export = recordsFromDB.ToExcel(); //custom ToExcel() extension method
result.Content = new StreamContent(export);
result.Content.Headers.ContentType = new MediaTypeHeaderValue("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
result.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment");
result.Content.Headers.ContentDisposition.Name = "formName";
result.Content.Headers.ContentDisposition.FileName = "test.xlsx";
return result;
}
Instead of seeing the spreadsheet being downloaded, nothing seems to happen. When I check the developer tools (for any browser), I see the Response Headers below while the Response tab just shows binary data. Does anyone know what I might be missing here?
How are you doing your POST? It sounds like you might be trying to this via a javascript AJAX call, which cannot be done (https://stackoverflow.com/a/9970672/405180).
I would instead make this a GET request for starters, and use something like window.location="download.action?para1=value1....". Generally web api Post requests are made to create a file/entry, not retrieve one.
Alternatively, you could use a HTML Form with hidden elements corresponding to your query parameters, and use javascript to submit the form.
I have a document library setup to recieve emails. The emails coming in have a single picture and a csv file which I use for some processing.
The override emailrecieved works perfectly but of course as I override I lose the nice SharePoint functionaliy that saves the incomming email as configured in the settings.
It was my understanding that I could call MyBase.EmailRecieved in my event for the underlying functionality to still work. This however is not working and no record of the email coming in is getting retained.
For now I am explicitly creating an audit trail but I would like to rely on SharePoints existing functionality as I believe it will be more robust.
What am I doing wrong with the MyBase.EmailRecieved call? Or what can I do instead if this doesnt work?
Thanks in advance.
When writing your own EmailReceived event receiver you will loose the default functionality.
What you will have to do is to implement this default functionality yourself. Let me give you a simple example. The following example saves all mail attachments to the list if they are *.csv files. You can do the same with the emailMessage and save it to the list as well. As you can see it is as easy as to add Files.Add to add a file to a document library.
public override void EmailReceived(SPList list, SPEmailMessage emailMessage, string receiverData)
{
SPFolder folder = list.RootFolder;
//save attachments to list
foreach (SPEmailAttachment attachment in emailMessage.Attachments)
{
if (attachment.FileName.EndsWith(".csv"))
{
var attachmentFileName = attachment.FileName;
folder.Files.Add(folder.Url + "/" + attachmentFileName, attachment.ContentStream, true);
}
}
list.Update();
}