select distinct ?r ?reqProp1
where {
  {
    { 
      ?r <http://www.semanticdesktop.org/ontologies/2007/03/22/nmo#plainTextMessageContent> ?v1 .
      ?v1 bif:contains "'foo'" .
    } UNION { 
      ?r <http://www.semanticdesktop.org/ontologies/2007/01/19/nie#isPartOf> ?v2 . 
      ?v2 <http://www.semanticdesktop.org/ontologies/2007/03/22/nmo#plainTextMessageContent> ?v3 .
      ?v3 bif:contains "'foo'" .
    } .
    ?r a ?v4 .
    ?v4 <http://www.w3.org/2000/01/rdf-schema#subClassOf> <http://www.semanticdesktop.org/ontologies/2007/03/22/nmo#Email> .
  } .
  ?r <http://akonadi-project.org/ontologies/aneo#akonadiItemId> ?reqProp1 .
}
