diff --git a/src/utils/idfile.cpp b/src/utils/idfile.cpp index 46626798..050e2204 100644 --- a/src/utils/idfile.cpp +++ b/src/utils/idfile.cpp @@ -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 diff --git a/src/utils/idfile.h b/src/utils/idfile.h index 6d75ffb8..bc484adf 100644 --- a/src/utils/idfile.h +++ b/src/utils/idfile.h @@ -21,10 +21,13 @@ #include #include -// 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 idFileAllTypes();