Add textunknownasplain configuration variable to tell the indexer to process text/xxx where xxx is unknown as text/plain

This commit is contained in:
Jean-Francois Dockes 2022-09-09 17:12:49 +02:00
parent 34003390f2
commit 78183a8e00
4 changed files with 37 additions and 13 deletions

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2004 J.F.Dockes
/* Copyright (C) 2004-2022 J.F.Dockes
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
@ -33,14 +33,11 @@
#endif
#include <algorithm>
#include <list>
#include <iostream>
#include <sstream>
#include <fstream>
#include <cstdlib>
#include <cstring>
#include <unordered_map>
#include <iterator>
#include "cstr.h"
#include "pathut.h"
@ -854,6 +851,13 @@ string RclConfig::getMimeHandlerDef(const string &mtype, bool filtertypes, const
}
if (!mimeconf->get(mtype, hs, "index")) {
if (mtype.find("text/") == 0) {
bool alltext{false};
getConfParam("textunknownasplain", &alltext);
if (alltext && mimeconf->get("text/plain", hs, "index")) {
return hs;
}
}
if (mtype != "inode/directory") {
IdxDiags::theDiags().record(IdxDiags::NoHandler, fn, mtype);
LOGDEB1("getMimeHandlerDef: no handler for '" << mtype << "' (fn " << fn << ")\n");
@ -1233,6 +1237,16 @@ string RclConfig::getMimeViewerDef(const string &mtype, const string& apptag, bo
if (apptag.empty() || !mimeview->get(mtype + string("|") + apptag, hs, "view"))
mimeview->get(mtype, hs, "view");
// Last try for text/xxx if alltext is set
if (hs.empty() && mtype.find("text/") == 0 && mtype != "text/plain") {
bool alltext{false};
getConfParam("textunknownasplain", &alltext);
if (alltext) {
return getMimeViewerDef("text/plain", apptag, useall);
}
}
return hs;
}

View File

@ -178,11 +178,12 @@ static RecollFilter *mhFactory(RclConfig *config, const string &mimeOrParams,
MD5String("MimeHandlerNull", id);
return nobuild ? 0 : new MimeHandlerNull(config, id);
} else if (lmime.find("text/") == 0) {
// Try to handle unknown text/xx as text/plain. This
// only happen if the text/xx was defined as "internal" in
// mimeconf, not at random. For programs, for example this
// allows indexing and previewing as text/plain (no filter
// exec) but still opening with a specific editor.
// Try to handle unknown text/xx as text/plain. This only happen if the text/xx was defined
// as "internal" in mimeconf.
// This is historic, because the natural way with the current code would be to specify
// "internal text/plain" instead of just "internal"...
// Also see rclconfig for the textunknownisplain configuration variable which allows
// processing all unknown text/* as text/plain.
LOGDEB2("mhFactory(" << lmime << "): returning MimeHandlerText(x)\n");
MD5String("MimeHandlerText", id);
return nobuild ? 0 : new MimeHandlerText(config, id);

View File

@ -39,6 +39,7 @@
.bas = text/plain
.cpp = text/x-c
.h = text/x-c
.hpp = text/x-c++
.c = text/x-c
.cc = text/x-c
.cxx = text/x-c

View File

@ -15,8 +15,7 @@
# quoted with "double quotes". Double quotes processing is NOT applied to single value parameter,
# and using quotes there will result in bad values.
# <grouptitle id="WHATDOCS">Parameters affecting what documents we
# index</grouptitle>
# <grouptitle id="WHATDOCS">Parameters affecting what documents we index</grouptitle>
# <var name="topdirs" type="string"><brief>Space-separated list of files or
# directories to recursively index.</brief><descr>Default to ~ (indexes
@ -227,6 +226,15 @@ compressedfilemaxkbs = 100000
# disable.</descr></var>
textfilemaxmbs = 20
# <var name="textunknownasplain" type="bool">
# <brief>Process unknown text/xxx files as text/plain</brief>
# <descr>Allows indexing misc. text files identified as text/whatever by 'file' or 'xdg-mime'
# without having to explicitely set config entries for them. This works fine for indexing (but will
# cause processing of a lot of garbage though), but the documents indexed this way will be opened by
# the desktop viewer, even if text/plain has a specific editor.</descr>
# </var>
#textunknownasplain=0
# <var name="indexallfilenames" type="bool"><brief>Index the file names of
# unprocessed files</brief><descr>Index the names of files the contents of
# which we don't index because of an excluded or unsupported MIME