(*BuildInboxGraphcreatesadirectedgraphusingmessageidentifiersandoriginatingdateswithgraphpartitioncoloringbysubgraphaddressparticipation.*)Options[BuildInboxGraph]={"FilePath"SystemDialogInput["FileOpen"],"UseTimeSeries"True,"ShowTimeSeries"False,"VertexSizeRange"{0.25,1.0}};BuildInboxGraph[OptionsPattern[]]:=((*Fieldstoimport.*)fields={"MessageID","OriginatingDate","Subject","Body","ReplyToMessageID","FromAddress","ToAddressList","CcAddressList","BccAddressList","ReplyToAddressList"};(*Importmailbox.*)mboxData=<||>;AssociateTo[mboxData,(*KeybyMessageID.*)(#[[1]]AssociationThread[fields,#])&/@Transpose[Import[OptionValue["FilePath"],{"MBOX",fields}]]];(*AddNLPFeatureEngineering:Sentimentclassification.*)mboxData=AssociationMap[#[[1]]Join[#[[2]],<|"Sentiment"Classify["Sentiment",#[[2]]["Body"]]|>]&,mboxData];(*Buildtimeseriesbackbone.*)vDates=DateObject[#,"Day"]&/@Sort[DeleteDuplicates[#[fields[[2]]]&/@Values[mboxData]]]//DeleteDuplicates;eDates=MapIndexed[vDates[[#2[[1]]]]#1&,vDates[[2;;]]];sDates=MapIndexed[vDates[[#2[[1]]]]0.0&,vDates[[2;;]]];vDatesColors=MapIndexed[vDates[[#2[[1]]]]Gray&,vDates[[2;;]]];vDatesShapes=MapIndexed[vDates[[#2[[1]]]]If[OptionValue["ShowTimeSeries"],(*Optionaltimeseriesbackbonevisualization.*)"Circle",None]&,vDates[[2;;]]];(*Buildmessagethreadedges.*)vMsgs=Keys[mboxData];lMsgs=Flatten[{#->Placed[mboxData[#],Tooltip]}&/@vMsgs];eMsgs=Values[Map[#ReplyToMessageID#MessageID&,Select[mboxData,#ReplyToMessageID=!=None&&MemberQ[vMsgs,#ReplyToMessageID]&]]];gMsgs=Graph[vMsgs,eMsgs];(*Connectmessageverticestorelevanttimeseriesanchorvertices.*)eMsgDates=Flatten[{DateObject[mboxData[#][fields[[2]]],"Day"]#}&/@vMsgs];(*CalculatemessageimportancebyVertexDegree*)g=Graph[vMsgs,eMsgs];sMsgs=KeyValueMap[##2&,AssociationThread[VertexList[g],(*ScalevaluesusingVertexSizeRangeparm.*)Rescale[VertexDegree[gMsgs]]*(OptionValue["VertexSizeRange"][[2]]-OptionValue["VertexSizeRange"][[1]])+OptionValue["VertexSizeRange"][[1]]]];(*GetParticipantsreturnsalloftheparticipantsforagivenlistofmessageIDs.*)GetParticipants[msgIDs_]:=(Flatten[Select[Values[KeySelect[mboxData[#],MemberQ[Select[fields,StringContainsQ[#,"Address"]&],#]&]]//Flatten,StringQ(*Validateaddressformatting.*)]&/@msgIDs]//DeleteDuplicates);(*Partitioncommunitybysubgraphco-occuranceedgeweightminimization.*)communitySubgroups=GetGraphPartitionGroups[GetParticipants/@WeaklyConnectedComponents[g]];(*Perceptually-uniformpalettegenerationwithLightness/Chroma/Hueselection.*)communitySubgroupColors=Map[LCHColor[0.5,1,#/Length[communitySubgroups]]&,Range[Length[communitySubgroups]]];(*Createalookuptableforeachaddresscolor.*)communityAddressToColor=<||>;AssociateTo[communityAddressToColor,Flatten[MapIndexed[Function[{community,communityIdx},{#communitySubgroupColors[[communityIdx[[1]]]]}&/@community][#1,#2]&,communitySubgroups]]];(*Colorbythemostcommoncommunityparticipationonamessage.*)vMsgsColors=KeyValueMap[##2&,AssociationThread[vMsgs,Commonest[Flatten[communityAddressToColor/@GetParticipants[{#}]]][[1]]&/@vMsgs]];(*Constructinboxgraph.*)v=vMsgs;l=lMsgs;e=eMsgs;s=sMsgs;c=vMsgsColors;If[OptionValue["UseTimeSeries"],(*Anchormessagestoalineartimeseriesbackbone.*)v=Join[vDates,v];c=Join[vDatesColors,c];e=Join[eDates,eMsgDates,e];s=Join[sDates,s];];(*Colormessagethreadroutingwithoptionaltimeseriesvisualization.*)edgeStyle=If[MatchQ[#[[1]],_DateObject],#If[OptionValue["ShowTimeSeries"],Gray,Transparent],#If[OptionValue["ShowTimeSeries"],Blue,Black]]&/@e;Graph[v,e,VertexLabelsl,VertexSizes,VertexStylec,VertexShapeFunctionvDatesShapes,EdgeStyleedgeStyle,GraphLayout"LayeredDigraphEmbedding"])(*RenderInboxGraphvisualization.*)BuildInboxGraph[UseTimeSeriesTrue,ShowTimeSeriesFalse]