Lettura delle proprietà di un e-mail da file .MSG o .EML

 

' Il seguente snippet può essere utilizzato per leggere le proprietà di un e-mail salvata in formato .MSG o .EML tramite il componente MsgReader presente a partire dalla release 2015.17.2p
' L'esempio si riferisce alla generazione di un ticket a partire da una e-mail, determinando il codice del cliente utilizzando il dominio del mittente della e-mail stessa.
dim path as string=<inserire qui il percorso del file .MSG o .EML>
  dim q as qwtable
  
  form.findcontrol("TICKET").Value="TT"+form.findcontrol("TIPO_CONT").Value+"-"+form.findcontrol("NUMERO").Value
  
  dim msg As new MsgReader.Outlook.Storage.Message(path)
  
  q = new qwtable
  q.database=form.form_state.dmd_ref.DB
  q.sql="select TOP 1 c.CODICE,c.RAGSOC,o.DESCPER,o.EMAIL,o.TELINT,o.DESCRUO from ORGCF o join CLIFOR c on o.CODICE=c.CODICE where o.EMAIL=:EMAIL and (c.CLIENTE=:VERO) and left(c.CODICE,1)<>'*' and left(c.CODICE,1)<>'R' order by c.CODICE desc"
  q.requestlive=false
  q.params("VERO")=true
  q.requestlive=false

  ' Cerca nell"organigramma l"indirizzo del sender
  q.params("EMAIL")=msg.sender.email
  q.active=true
  if q.rowset.first()
	form.findcontrol("Cliente").Value=q.rowset.fields("CODICE").value
	form.findcontrol("SEGN").Value=q.rowset.fields("DESCPER").value+" ("+q.rowset.fields("DESCRUO").value+")"
	form.findcontrol("SEGN_MAIL").value=q.rowset.fields("EMAIL").value
	form.findcontrol("SEGN_TEL").value=q.rowset.fields("TELINT").value
  else
	form.findcontrol("SEGN").Value=msg.sender.displayname
	form.findcontrol("SEGN_MAIL").value=msg.sender.email
  End If
  q.active=false

  if empty(form.findcontrol("Cliente").Value) and dbdollar("@",msg.sender.email)
	' Prova con il dominio
	q.sql="select CODICE,RAGSOC from CLIFOR c where EMAIL like '%'+:EMAIL and (CLIENTE=:VERO)  and left(c.CODICE,1)<>'*'"
	q.params("VERO")=true
	q.params("EMAIL")=substr2(msg.sender.email,at("@",msg.sender.email)+1)
	q.active=true
	if q.rowset.first()
	   form.findcontrol("Cliente").Value=q.rowset.fields("CODICE").value
	End If
	q.active=false
  End If	
	 
  if not empty(form.findcontrol("Cliente").Value)
	 form.SetAssigned(form.findcontrol("Cliente"),true)
	 Cliente_Change(form,form.findcontrol("Cliente"))
  else
	 form.findcontrol("SEGN_MAIL").value=msg.sender.email	 
  End If
	
  dim cc as string=""
	
  dim r as integer
  for r=0 to msg.recipients.count-1
 	 if msg.recipients.item(r).type=2
		cc+=iif(cc<>"",";","")+msg.recipients.item(r).email
	 End If
  next
	 
 form.findcontrol("CC").value=cc
		  
 dim d as date=ctype(msg.ReceivedOn,date)
 form.findcontrol("DSEGN").Value=new date(d.year,d.month,d.day)
 form.findcontrol("HSEGN").Value=Transform(d.hour,"@L 99")+transform(d.minute,"@L 99")
 
 form.findcontrol("Notebook1").controls(0).findcontrol("SEGN_TESTO").value=msg.BodyText
 
 if not dbdollar("Richiesta di assistenza",msg.subject)
	form.findcontrol("TITOLO").Value=msg.subject+" (#"+form.findcontrol("TICKET").value+") - "+form.findcontrol("Cliente").value
 else
	form.findcontrol("TITOLO").Value=msg.subject+" (#"+form.findcontrol("TICKET").value+")"
 End If
	 
 form.Save()