allow working on memory string

This commit is contained in:
dockes 2009-10-13 17:32:09 +00:00
parent 24d8fbf7f2
commit 3fcde55ff4
2 changed files with 24 additions and 11 deletions

View File

@ -57,20 +57,14 @@ static const int nmh = sizeof(mailhs) / sizeof(char *);
const int wantnhead = 3;
string idFile(const char *fn)
// fn is for message printing
static string idFileInternal(istream& input, const char *fn)
{
static int treat_mbox_as_rfc822;
if (treat_mbox_as_rfc822 == 0) {
treat_mbox_as_rfc822 = getenv("RECOLL_TREAT_MBOX_AS_RFC822") ? 1 : -1;
}
ifstream input;
input.open(fn, ios::in);
if (!input.is_open()) {
LOGERR(("idFile: could not open [%s]\n", fn));
return string();
}
bool line1HasFrom = false;
bool gotnonempty = false;
int lookslikemail = 0;
@ -162,6 +156,22 @@ string idFile(const char *fn)
return string();
}
string idFile(const char *fn)
{
ifstream input;
input.open(fn, ios::in);
if (!input.is_open()) {
LOGERR(("idFile: could not open [%s]\n", fn));
return string();
}
return idFileInternal(input, fn);
}
string idFileMem(const string& data)
{
stringstream s(data, stringstream::in);
return idFileInternal(s, "");
}
#else

View File

@ -21,10 +21,13 @@
#include <string>
#include <list>
// Return mime type for file or empty string. The system's file utility does
// a bad job on mail folders. idFile only looks for mail file types for now,
// but this may change
// Look at data inside file or string, and return mime type or empty string.
//
// The system's file utility does a bad job on mail folders. idFile
// only looks for mail file types for now, but this may change
extern std::string idFile(const char *fn);
extern std::string idFileMem(const std::string& data);
// Return all types known to us
extern std::list<std::string> idFileAllTypes();