@prefix str: <http://www.w3.org/2000/10/swap/string#>.
@prefix log: <http://www.w3.org/2000/10/swap/log#>.

@prefix m:   <http://www.w3.org/2000/10/swap/pim/email#> .

# chage from
#   <references rdf:resource="/mid/1093009605.2611.507.camel@cirrustier;reference"/>
# to
#   <references rdf:resource="mid:1093009605.2611.507.camel@cirrustier"/>

{
  ?M1 m:references [ log:uri ?ID ].
  (?ID "/mid/([^;]+);reference") str:scrape ?MID.
  ("mid:" ?MID) str:concatenation [ is log:uri of ?MSG ]
} => { ?M1 m:references ?MSG }.

# should be inReplyTo, no?
{
  ?M1 m:replyTo [ log:uri ?ID ].
  (?ID "/mid/([^;]+);reference") str:scrape ?MID.
  ("mid:" ?MID) str:concatenation [ is log:uri of ?MSG ]
} => { ?M1 m:replyTo ?MSG }.

