+// ----------------------------------------------------------------------------
+// UNIX mailcap files parsing
+// ----------------------------------------------------------------------------
+
+// the data for a single MIME type
+struct MailcapLineData
+{
+ // field values
+ wxString type,
+ cmdOpen,
+ test,
+ icon,
+ desc;
+
+ wxArrayString verbs,
+ commands;
+
+ // flags
+ bool testfailed,
+ needsterminal,
+ copiousoutput;
+
+ MailcapLineData() { testfailed = needsterminal = copiousoutput = FALSE; }
+};
+
+// process a non-standard (i.e. not the first or second one) mailcap field
+bool
+wxMimeTypesManagerImpl::ProcessOtherMailcapField(MailcapLineData& data,
+ const wxString& curField)
+{
+ if ( curField.empty() )
+ {
+ // we don't care
+ return TRUE;
+ }
+
+ // is this something of the form foo=bar?
+ const wxChar *pEq = wxStrchr(curField, wxT('='));
+ if ( pEq != NULL )
+ {
+ // split "LHS = RHS" in 2
+ wxString lhs = curField.BeforeFirst(wxT('=')),
+ rhs = curField.AfterFirst(wxT('='));
+
+ lhs.Trim(TRUE); // from right
+ rhs.Trim(FALSE); // from left
+
+ // it might be quoted
+ if ( !rhs.empty() && rhs[0u] == wxT('"') && rhs.Last() == wxT('"') )
+ {
+ rhs = rhs.Mid(1, rhs.length() - 2);
+ }
+
+ // is it a command verb or something else?
+ if ( lhs == wxT("test") )
+ {
+ if ( wxSystem(rhs) == 0 )
+ {
+ // ok, test passed
+ wxLogTrace(TRACE_MIME_TEST,
+ wxT("Test '%s' for mime type '%s' succeeded."),
+ rhs.c_str(), data.type.c_str());
+
+ }
+ else
+ {
+ wxLogTrace(TRACE_MIME_TEST,
+ wxT("Test '%s' for mime type '%s' failed, skipping."),
+ rhs.c_str(), data.type.c_str());
+
+ data.testfailed = TRUE;
+ }
+ }
+ else if ( lhs == wxT("desc") )
+ {
+ data.desc = rhs;
+ }
+ else if ( lhs == wxT("x11-bitmap") )
+ {
+ data.icon = rhs;
+ }
+ else if ( lhs == wxT("notes") )
+ {
+ // ignore
+ }
+ else // not a (recognized) special case, must be a verb (e.g. "print")
+ {
+ data.verbs.Add(lhs);
+ data.commands.Add(rhs);
+ }
+ }
+ else // '=' not found
+ {
+ // so it must be a simple flag
+ if ( curField == wxT("needsterminal") )
+ {
+ data.needsterminal = TRUE;
+ }
+ else if ( curField == wxT("copiousoutput"))
+ {
+ // copiousoutput impies that the viewer is a console program
+ data.needsterminal =
+ data.copiousoutput = TRUE;
+ }
+ else if ( !IsKnownUnimportantField(curField) )
+ {
+ return FALSE;
+ }
+ }
+
+ return TRUE;
+}
+