IT-Hock / xarf-report-generator

Generates XARF reports from multiple sources.
GNU Affero General Public License v3.0
3 stars 2 forks source link

Emailing XARF(content-type) #14

Open NXTwoThou opened 5 days ago

NXTwoThou commented 5 days ago

I was trying to add XARF email reporting to my own software and haven't been able to figure out how to switch the MailMessage Content-Type from "multipart/mixed" to "multipart/report; report-type=feedback-report". I came across yours and I'm not seeing it either. Are you doing it through another mechanism I'm not seeing or do whom you've reported to not care?

Subtixx commented 5 days ago

Actually no, we do not add this email header to the files. If it would, it would be in here

I read up on that quickly and the easiest way I think could be to just use: message.Headers.Add("Content-Type", "multipart/report; report-type=abuse"); in combination with

AlternateView reportView = new AlternateView("report.txt", "text/plain");                                 

for the human-readable format.

NXTwoThou commented 5 days ago

Thanks for the reply. I wasn't sure if I was missing something in your implementation. I guess you haven't had any problems sending reports? XARF via SMTP made it seem like it was important.

Unfortunately, Headers.Add doesn't do anything when it comes to Content-Type(it was the first thing I tried).

Subtixx commented 5 days ago

We didn't had problems no. But we only received replies from those companies however:

Hmm Do you use C# in your application?

EDIT: Seems like other projects use the "Content-type" header with no issues? https://github.com/mjl-/mox/blob/7e54280a9d9df32db894ff11b45fcaeb7c1d24da/dsn/dsn.go#L142

Maybe this is just an issue with C#/.NET/System.Net.Mail

This seems like it does support it under C#: https://github.com/jstedfast/MimeKit aka https://github.com/jstedfast/MailKit does support it.

Also to be honest, I wouldn't count on System.Net.Mail in 2024, rather use Mailkit for example.

NXTwoThou commented 5 days ago

The only group I'm having any issues reporting to right now is DigitalOcean. I'm getting dozens a day and using their reporting form is extremely annoying. They accept XARF. It's encouraging that you haven't had any issues reporting to others without the headers that are mentioned required in the format.

Yes, I'm using C#. That first link isn't C# so unfortunately, it's not relevant. Likely is an issue with System.Net.Mail. I'm gone ahead and added MailKit and the only thing I'm missing is the "report-type=feedback-report;" bit after multipart/report. Looking into it now.

Thanks a bunch!

EDIT: All done. Easy pleasey. Just had to give up on System.Net.Mail. These chunks give me identical to what Abusix shows.

` string userAgent = "BlockGenie/1.0"; MemoryStream memoryStreamFeedbackType = new MemoryStream(ASCIIEncoding.ASCII.GetBytes("Feedback-Type: xarf\nUser-Agent: " + userAgent + "\nVersion: 1"));

var multipartBody = new TextPart("plain") { Text = body }; var multipartFeedbackType = new MimePart("message", "feedback-report") { Content = new MimeContent(memoryStreamFeedbackType), ContentDisposition = new ContentDisposition(ContentDisposition.Inline) }; var multipartAttachmentXARF = new MimePart("application", "json") { Content = new MimeContent(memoryStreamXARF), ContentDisposition = new ContentDisposition(ContentDisposition.Attachment), ContentTransferEncoding = ContentEncoding.Base64, FileName = "xarf.json" };

var multipart = new Multipart("report; report-type=feedback-report"); multipart.Add(multipartBody); multipart.Add(multipartFeedbackType); multipart.Add(multipartAttachmentXARF); message.Body = multipart; `