Just like image(jpg,png,gif) attachment, if you click them on the attachment, you can view it directly.
So I want certain extension also, like .txt to open directly on the browser when click not to download.
The way to approach this would be to create an addon that changes the direct link into a web page that displays the content of the text file. Gotta post a request:
will inform the browser that the PDF should be saved as a file instead. Sure, ultimately it depends on your client and what apps you have installed on your client computer, but there is at least a way to hint the browser of how the file should be opened/downloaded. Not every browser behaves the same, and here is a (somewhat outdated) list with example links of how browsers react to sending inline txt content:
You do this via http headers. Either in your webserver configuration, if you have access, or via software. Unlike vBulletin, xF doesn't allow to change mime settings for individual attachment types, so that would require an add-on.
Hah, if I'd seen that I'd not have bothered writing mine, it's the same idea.
I think my approach is slightly cleaner though, as I always call parent::renderRaw, so there's less duplication of code. Plus it handles multiple mime types now.