--- a
+++ b/src/index/exefetcher.cpp
@@ -0,0 +1,129 @@
+/* Copyright (C) 2016 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
+ *   (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program; if not, write to the
+ *   Free Software Foundation, Inc.,
+ *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ */
+#include "autoconfig.h"
+
+#include <string>
+#include <vector>
+#include <iostream>
+
+#include "exefetcher.h"
+
+#include "debuglog.h"
+#include "pathut.h"
+#include "rclconfig.h"
+#include "execmd.h"
+#include "rcldoc.h"
+
+using namespace std;
+
+class EXEDocFetcher::Internal {
+public:
+    string bckid;
+    vector<string> sfetch;
+    vector<string> smkid;
+    bool docmd(const vector<string>& cmd, const Rcl::Doc& idoc, string& out) {
+        ExecCmd ecmd;
+        // We're always called for preview (or Open)
+        ecmd.putenv("RECOLL_FILTER_FORPREVIEW=yes");
+        string udi;
+        idoc.getmeta(Rcl::Doc::keyudi, &udi);
+        vector<string> args(cmd);
+        args.push_back(udi);
+        args.push_back(idoc.url);
+        args.push_back(idoc.ipath);
+        int status = ecmd.doexec1(args, 0, &out);
+        if (status == 0) {
+            LOGDEB(("EXEDocFetcher::Internal: got [%s]\n", out.c_str()));
+            return true;
+        } else {
+            LOGERR(("EXEDOcFetcher::fetch: %s: %s failed for %s %s %s 0x%u\n",
+                    bckid.c_str(), stringsToString(cmd).c_str(), udi.c_str(),
+                    idoc.url.c_str(), idoc.ipath.c_str()));
+            return false;
+        }
+    }
+};
+
+EXEDocFetcher::EXEDocFetcher(const EXEDocFetcher::Internal& _m)
+{
+    m = new Internal(_m);
+    LOGDEB(("EXEDocFetcher::EXEDocFetcher: fetch is %s\n",
+            stringsToString(m->sfetch).c_str()));
+}
+
+bool EXEDocFetcher::fetch(RclConfig* cnf, const Rcl::Doc& idoc, RawDoc& out)
+{
+    out.kind = RawDoc::RDK_DATADIRECT;
+    return m->docmd(m->sfetch, idoc, out.data);
+}
+
+bool EXEDocFetcher::makesig(RclConfig* cnf, const Rcl::Doc& idoc, string& sig)
+{
+    return m->docmd(m->smkid, idoc, sig);
+}
+
+// Lookup bckid in the config and create an appropriate fetcher.
+EXEDocFetcher *exeDocFetcherMake(RclConfig *config, const string& bckid)
+{
+    EXEDocFetcher *fetcher = 0;
+
+    // The config we only read once, not gonna change.
+    static ConfSimple *bconf;
+    if (!bconf) {
+        string bconfname = path_cat(config->getConfDir(), "backends");
+        LOGDEB(("exeDocFetcherMake: using config in %s\n", bconfname.c_str()));
+        bconf = new ConfSimple(bconfname.c_str(), true);
+        if (!bconf->ok()) {
+            delete bconf;
+            bconf = 0;
+            LOGDEB(("exeDocFetcherMake: bad/no config: %s\n",
+                    bconfname.c_str()));
+            return 0;
+        }
+    }
+
+    EXEDocFetcher::Internal m;
+    m.bckid = bckid;
+
+    string sfetch;
+    if (!bconf->get("fetch", sfetch, bckid) || sfetch.empty()) {
+        LOGERR(("exeDocFetcherMake: no 'fetch' for [%s]\n", bckid.c_str()));
+        return 0;
+    }
+    stringToStrings(sfetch, m.sfetch);
+    // We look up the command as we do for filters for now
+    m.sfetch[0] = config->findFilter(m.sfetch[0]);
+    if (!path_isabsolute(m.sfetch[0])) {
+        LOGERR(("exeDocFetcherMake: %s not found in exec path or filters dir\n",
+                m.sfetch[0].c_str()));
+        return 0;
+    }
+
+    string smkid;
+    if (!bconf->get("makesig", smkid, bckid) || smkid.empty()) {
+        LOGDEB(("exeDocFetcherMake: no 'makesig' for [%s]\n", bckid.c_str()));
+        return 0;
+    }
+    stringToStrings(smkid, m.smkid);
+    m.smkid[0] = config->findFilter(m.smkid[0]);
+    if (!path_isabsolute(m.smkid[0])) {
+        LOGERR(("exeDocFetcherMake: %s not found in exec path or filters dir\n",
+                m.smkid[0].c_str()));
+        return 0;
+    }
+    return new EXEDocFetcher(m);
+}