sup icon indicating copy to clipboard operation
sup copied to clipboard

MIME Type detection when sending attachments

Open ghost opened this issue 11 years ago • 6 comments

Ideally I would like to be able to use sup to communicate with the Linux Kernel Mailing List. This requires being able to send plaintext attachments. I believe that sup currently uses the MIME::Types::type_for function to determine a encoding type from the file extension. Unfortunately this returns Nil for the filename "Makefile" which results in the attachment being base64 encoded. I'm able to work around the issue by modifying line 87 of /sup/lib/sup/util.rb to t = MIME::Types.type_for(bfn).first || MIME::Types.type_for("txt").first however this isn't an appropriate long term solution. It would be nice if sup used a (subjectively) better approach to determining file type. One option may be the ruby-filemagic gem which seems to provide correct results for the Makefile scenario.

ghost avatar Mar 31 '14 05:03 ghost

Agreed, would this be something you could implement? Is the filemagic gem activly developed?

Also, does the new mime-types gem (#182) handle this better?

gauteh avatar Mar 31 '14 08:03 gauteh

Unfortunately my Ruby skills are nonexistant, so I wouldn't be able to implement it any time soon. Having said that I've found a suitable work around using the :r option in vim to insert the attachment inline, so I'll close the issue.

Cheers.

ghost avatar Apr 01 '14 05:04 ghost

please keep the issue open, as it is, after all, still an issue that someone may be able to work on. and, if i understand it correctly, it may even be an easier one that a person new to sup could get started with.

eMBee avatar Apr 03 '14 03:04 eMBee

I think I get the same bug here: https://github.com/sup-heliotrope/sup/issues/369

Did you get to send your patch with sup ?

Regards, Guillaume.

GuillaumeSeren avatar Jan 07 '15 08:01 GuillaumeSeren

filemagic seems to be active, in fact there was a pre release yesterday. However I'm wary of depending on non-ruby stuff.

I tried with mime-types 2.4.3, it didn't recognize the .patch extension. So we need some other way to detect this.

Here's an idea:

  • Try with MIME::Types.type_for first
  • Otherwise scan the whole file. If it's text only, set the attachment to text/plain
  • Otherwise set it to default, application-x-msdos-program (I'm not even sure it's a sensible default, though)

Roughly, something like that, maybe:

mime_type = MIME::Types.type_for(bfn).first
begin
  File.open(bfn) do |f|
    f.each_codepoint{}
  end
rescue ArgumentError # We couldn't iterate over codepoints, it's not a text
  mime_type = MIME::Types.type_for("exe").first
end

rakoo avatar Jan 13 '15 21:01 rakoo

Excerpts from Matthieu Rakotojaona's message of January 13, 2015 22:39:

filemagic seems to be active, in fact there was a pre release yesterday. However I'm wary of depending on non-ruby stuff.

I tried with mime-types 2.4.3, it didn't recognize the .patch extension. So we need some other way to detect this.

Here's an idea:

  • Try with MIME::Types.type_for first
  • Otherwise scan the whole file. If it's text only, set the attachment to text/plain
  • Otherwise set it to default, application-x-msdos-program (I'm not even sure it's a sensible default, though)

I used application/octet-stream as default for potentially mangeled mime-types, see earlier security issue: the mime-type is passed to the shell when opening, allowing an attacker to leave a command in the mime-type.

gauteh avatar Jan 14 '15 09:01 gauteh