How to get email attachment MIME type by file extension? - c++

I'm trying to write a class that would use Mandrill APIs to send an email with an attachment. To do that I need to provide MIME type of the attachment for the base-64 encoded attachment contents. The question is how to get it, assuming using the file extension of the attachment?
PS. I was hoping for something better than a long switch/case situation. But if that's my only option, where can I get the most exhaustive list of such associations?

You can look in the Registry, under either:
HKEY_CLASSES_ROOT\<file extension>\ and see if it has a "Content Type" value.
HKEY_CLASSES_ROOT\MIME\Database\Content Type\, enumerating each subkey until you find one whose "Extension" value contains the file extension.
There is also a FindMimeFromData() function.
If you don't find a matching content type, you can always use application/octet-stream.

Apart to what was suggested in a different answer, here's a hard-coded list of file-extension-to-MIME-types associations that I converted from this Ruby project's JSON list into a C-struct.
Oops, can't post it here. It's too long. Here's the file instead.

Related

JMeter - How to extract values from a response which has been decoded from base64 and stored in a variable? All under the same sampler

I am trying to test a webservice's performance, and having a few issues with using and passing variables. There are multiple sequential requests, which depend on some data coming from a previous response. All requests need to be encoded to base64 and placed in a SOAP envelope namespace before sending it to the endpoint. It returns and encoded response which needs to be decoded to see the xml values which need to be used for the next request. What I have done so far is:
1) Beanshell preprocessor added to first sample to encode the payload which is called from a file.
2) Regex to pull the encoded response bit from whole response.
3) Beanshell post processor to decode the response and write to a file (just in case). I have stored the decoded response in a variable 'Output' and I know this works since it writes the response to file correctly.
4) After this, I have added 4 regex extractors and tried various things such as apply to different parts, check different fields, check JMeter variable etc. However, it doesn't seem to work.
This is what my tree is looking like.
JMeter Tree
I am storing the decoded response to 'Output' variable like this and it works since it's writing to file properly:
import org.apache.commons.io.FileUtils;
import org.apache.commons.codec.binary.Base64;
String Createresponse= vars.get("Createregex");
vars.put("response",new String(Base64.decodeBase64(Createresponse.getBytes("UTF-8"))));
Output = vars.get("response");
f = new FileOutputStream("filepath/Createresponse.txt");
p = new PrintStream(f);
this.interpreter.setOut(p);
print(Output);
f.close();
And this is how I using Regex after that, I have tried different options:
Regex settings
Unfortunately though, the regex is not picking up these values from 'Output' variable. I basically need them saved so i can use ${docID} in the payload file for next request.
Any help on this is appreciated! Also happy to provide more detail if needed.
EDIT:
I had a follow up question. I am trying to run this with multiple users. I have a field ${searchuser} in my payload xml file called in the pre-processor here.
The CSV Data set above it looks like this:
However, it is not picking up the values from CSV and substituting in the payload file. Any help is appreciated!
You have 2 problems with your Regular Expression Extractor configuration:
Apply to: needs to be response
Field to check: needs to be Body, Body as a Document is being used for binary file formants like PDF or Word.
By the way, you can do Base64 decoding and encoding using __base64Decode() and __base64Encode() functions available via JMeter Plugins. The plugins in their turn can be installed in one click using Plugin Manager

Type "p" Annotations with Plain Text files

I am trying to understand whether GATE is able to extract annotations of type "p" from plain text files which are UTF-8 encoded.
HTML files and PDF files work just fine and "p" annotations are added when these 2 file types are being analysed.
I tried using different PRs but i do not seem to be able to get type "p" annotations under Original Markups.
Is there a way to achieve this for Plain Text files?
I think you should use Annotation Set Transfer PR which will move "p" annotations from Original Markups to Default set. Then you will be able to use them according to your requirements.

Is there any way to detect PDF/email in NetSuite Advanced PDFs?

Is there any way to detect if an advanced PDF is being used as a PDF or an email in NetSuite?
I would like to format accordingly.
Something like:
<#if current_format=="email">Show some html stuff.<#else>PDF version</#if>
There is no 'state' information available in to the template generator that I can think of. All it knows is the record context you(or NetSuite) gave it.
The output of the advanced template is XML regardless of its final destination. It's converted to PDF or HTMl output after having been generated. (See: nlapiCreateTemplateRenderer() and nlapiXMLToPDF() documentation in NetSuite for more info.)
If you need to format the content differently, the simplest method is probably to use 2 separate forms.

How to use the original filename in a multi file template in resharper?

I have a multi file template in resharper and I can use $NAME$ macro to get the name of the original file to use to name the other files in the template. But I also want to use the $NAME$ of the original file in the content of the other file template.
Is this possible? I can't see a macro which seems suitable for the internal variables as onlt the Current File Name seems available.
Anyone know if this is possible or how I might workaround this?
As a workaround, you may create a parameter $FILENAME$ (macro "Current file name without extension") in the first file e.g. in the comments, like:
class Foo
{
//$FILENAME$
}
Then you may call this parameter in other files of the multifile template - this parameter will contain the name of the first file since the first file will be generated before other ones.
Unfortunately, there isn't a macro that will give you this. I've added a feature request that you can vote on and track (and more specific detail as to what your requirements are would be useful) - http://youtrack.jetbrains.com/issue/RSRP-415055
It is possible to write your own macros as part of a plugin, but there isn't a sure-fire way of getting the name of the first document in the created file set. The IHotspotSessionContext instance that is passed to the macro via IHotspotSession.Context property includes an enumerable of IDocument, from which you can get IDocument.Moniker, which will be the full path for file based documents. However, there's no guarantee of the order of the enumerable - it's backed by a hashset. You might be able to rely on implementation details (small set, no removes) to be able to use the first document as the original, but there is really no guarantee of this.

How does one obtain the type of an uploaded file in Django forms?

I have tried:
self.data['uploaded_file'].content_type
However, this gives an error that says the object lacks a content_type attribute.
Any ideas as to why? Thank you.
What is the best way to verify file type in Django forms?
The content_type attribute is only present on the UploadedFile instances contained in request.FILES; you will need to get the content type from that, or use magic to get it from the raw file data.
How could you tell a file is binary file or text or some other stuff?
Perhaps using the file extension is a way, but not always makes sense.