Sub Initialize On Error Goto errore Dim session As New NotesSession Dim db As NotesDatabase Dim doc As NotesDocument Dim object As NotesEmbeddedObject Dim object1 As NotesEmbeddedObject Dim object2 As NotesEmbeddedObject Dim object3 As NotesEmbeddedObject Dim objectName As String Dim dc As NotesDocumentCollection Dim idx As Long Set db = session.currentdatabase Set doc = session.DocumentContext ' ************ PEC Multipla *********** Dim acl As NotesACL Dim aclentry As NotesACLEntry Set acl = db.ACL Set aclentry = acl.GetFirstEntry While Not aclentry Is Nothing 'MsgBox "------------------->" + CStr(aclentry.name) BigString$ = CStr(aclentry.name) LittleString$ = "GestorePosta_" positionOfChar& = InStr(BigString$, LittleString$) If positionOfChar&>0 Then RP = aclentry.Name End If Set aclentry = acl.GetNextEntry( aclentry ) Wend ' ************ PEC Multipla *********** Dim dbAdmin As NotesDatabase Dim viPar As NotesView Dim param As NotesDocument Dim emailIst As Variant Dim emailPEC As Variant Dim sep As String sep = "/" If session.Platform = "UNIX" Or session.Platform = "Linux" Then sep = "/" Else sep = "\" End If Set dbAdmin = session.GetDatabase( db.server, LeftBack(db.FilePath,sep) + sep + "aed-admin.nsf" ) Set viPar = dbAdmin.getView("key-parametri") Set param = viPar.getFirstDocument 'If param.getItemValue("EmailIstituzionale")(0) <> "" Then If param.getItemValue("EmailProtocollo")(0) <> "" Then emailIst = Evaluate(|@trim(@explode(EmailIstituzionale; ","))|, param) emailPEC = Evaluate(|@trim(@explode(EmailProtocollo; ","))|, param) End If Dim CaselleIst List As String 'Msgbox "********************" + emailPEC(0) If emailist(0) <> "" Then Forall ri In emailIst 'Msgbox "caselleist" & ri If ri <>"" Then CaselleIst(ri) = ri End If End Forall End If Dim CasellePEC List As String Forall ri In emailPEC 'Msgbox "casellepec" & ri If ri <>"" Then CasellePEC(ri) = ri End If End Forall ' Bisogna aggiungere la casella IST e PEC privato del servizio, altrimenti non ce la farà mai a smistare! ' Devo scorrere tutti i funzionari e prendere tutte le caselle di posta PEC e IST configurate Set dbBase = session.GetDatabase( db.server, LeftBack(db.FilePath,sep) + sep + "aed-base.nsf" ) Set viFunz = dbBase.getView("key-listaFU-nome-cognome") Set funz = viFunz.getFirstDocument While Not ( funz Is Nothing ) If funz.hasItem("IndirizzoPECServizio") And funz.IndirizzoPECServizio(0) <>"" Then CasellePEC(funz.IndirizzoPECServizio(0)) = funz.IndirizzoPECServizio(0) End If If funz.hasItem("IndirizzoISTServizio") And funz.IndirizzoISTServizio(0) <>"" Then CaselleIst(funz.IndirizzoISTServizio(0)) = funz.IndirizzoISTServizio(0) End If Set funz = viFunz.GetNextDocument( funz ) Wend 'Print "Email istituzionatle: "+emailIst ' Inizializzo i campi Dim PeANumero As NotesItem Dim PeAAnno As NotesItem Dim subject As String Dim formName As String Dim patt1 As String Dim patt2 As String Dim patt3 As String Dim patt4 As String Dim positionPatt1 As Long Dim positionPatt2 As Long Dim positionPatt3 As Long Dim positionPatt4 As Long patt1$ = "ACCETTAZIONE" patt2$ = "CONSEGNA" patt3$ = "ANOMALIA MESSAGGIO" patt4$ = "NonDelivery Report" Dim sendtoM As String Dim copytoM As String Dim blindcopytoM As String Dim retVal As Variant Set dc = db.UnprocessedDocuments For j = 1 To dc.Count Set doc = dc.GetNthDocument(j) subject$ = doc.Subject(0) formName$ = doc.Form(0) 'Msgbox "->" + Cstr(j) + ">>>>" + subject$ + "<>" + formName$ ' ************ PEC Multipla *********** If (RP <> "") Then doc.RP = RP End If ' ************ PEC Multipla *********** r1 = Evaluate( |SendTo|, doc) r2 = Evaluate( |CopyTo|, doc) r3 = Evaluate( |Delivered_To|, doc) r4 = Evaluate( |BlindCopyTo|, doc) Dim something As Boolean something = False Dim R List As String Erase R Forall ri In r1 'Msgbox "->R1" + ri If ri <>"" Then something = True R(ri) = ri End If End Forall Forall ri In r2 'Msgbox "->R2" + ri If ri <>"" Then something = True R(ri)=ri End If End Forall Forall ri In r3 'Msgbox "->R3" + ri If ri <> "" Then something = True R(ri)=ri End If End Forall Forall ri In r4 'Msgbox "->R4" + ri If ri <> "" Then something = True R(ri)=ri End If End Forall daCasellaIs = False daCasellaPEC = False ' Per gestire i gruppi di inoltro Call ReSequenceField(doc, "Received") ' Per gestire quei casi in cui arrivano mail che non hanno nessuno dei campi "SendTo", "CopyTo", "Delivered_To", "BlindCopyTo" valorizzati ' bisogna comunque gestire il campo "Received" *************************************************************************************************************** If Not something Then Forall k In CaselleIst ' elenco caselle istituzionali ' Per gestire i gruppi di inoltro Forall a In doc.Received 'Msgbox "CASELLE IST->a:" + a + "<>" + Cstr(CaselleIst(k)) 'If InStr(a,CStr(CaselleIst(k))) Then If IsElement(CaselleIst(a)) Then 'Msgbox "TROVATA CASELLA IST!!!!!" daCasellaIs = True End If End Forall End Forall Forall k In CasellePEC ' elenco caselle PEC ' Per gestire i gruppi di inoltro Forall a In doc.Received 'Msgbox "CASELLE PEC->a:" + a + "<>" + Cstr(CasellePEC(k)) 'If Instr(a,Cstr(CasellePEC(k))) Then If IsElement(CasellePEC(a)) Then daCasellaPEC = True End If End Forall End Forall End If ' Per gestire quei casi in cui arrivano mail che non hanno nessuno dei campi "SendTo", "CopyTo", "Delivered_To", "BlindCopyTo" valorizzati ' bisogna comunque gestire il campo "Received" *************************************************************************************************************** ' Per la gestione dei delivery failure ***************************************************************************** If formName$ = "NonDelivery Report" Then Call ReSequenceField(doc, "SMTPDSNDeliveryStatus") Forall k In CaselleIst ' elenco caselle istituzionali ' Per gestire i gruppi di inoltro Forall a In doc.SMTPDSNDeliveryStatus 'Msgbox "CASELLE IST->a:" + a + "<>" + Cstr(CaselleIst(k)) 'If Instr(a,Cstr(CaselleIst(k))) Then If IsElement(CaselleIst(a)) Then 'Msgbox "TROVATA CASELLA IST!!!!!" daCasellaIs = True End If End Forall End Forall Forall k In CasellePEC ' elenco caselle PEC ' Per gestire i gruppi di inoltro Forall a In doc.SMTPDSNDeliveryStatus 'Msgbox "CASELLE PEC->a:" + a + "<>" + Cstr(CasellePEC(k)) 'If Instr(a,Cstr(CasellePEC(k))) Then If IsElement(CasellePEC(a)) Then 'Msgbox "TROVATA CASELLA PEC!!!!!" daCasellaPEC = True End If End Forall End Forall End If ' Per la gestione dei delivery failure ***************************************************************************** Forall i In R ' elenco to cc e bcc Forall k In CaselleIst ' elenco caselle istituzionali Msgbox R(i) + "=" + CaselleIst(k) + IsElement(R(CStr(CaselleIst(k)))) If IsElement(R(CStr(CaselleIst(k)))) Then 'If Instr(Cstr(R(i)),Cstr(CaselleIst(k))) Then daCasellaIs = True End If ' Per gestire i gruppi di inoltro Forall a In doc.Received 'Msgbox ">" +a + "<>" + Cstr(CaselleIst(k)) If IsElement(CaselleIst(a)) Then 'If Instr(a,Cstr(CaselleIst(k))) Then 'Msgbox "TROVATA CASELLAIST" daCasellaIs = True End If End Forall 'Msgbox daCasellaIs End Forall End Forall Forall i In R ' elenco to cc e bcc Forall k In CasellePEC ' elenco caselle PEC 'Msgbox R(i) + "=" + CaselleIst(k) If IsElement(R(CStr(CasellePEC(k)))) Then 'If Instr(Cstr(R(i)),Cstr(CasellePEC(k))) Then daCasellaPEC = True End If ' Per gestire i gruppi di inoltro Forall a In doc.Received If IsElement(CasellePEC(a)) Then 'If Instr(a,Cstr(CasellePEC(k))) Then daCasellaPEC = True End If End Forall 'Msgbox daCasellaIs End Forall End Forall ' Mette il campo body in un temporaryField 'Set rtitem = doc.GetFirstItem( "Body" ) 'Dim vB As Variant 'vB = Evaluate(|@Abstract( [TEXTONLY]; 65000; ""; body )|,doc) Set rtitemBody = doc.GetFirstItem( "Body" ) If ( rtitemBody.Type = RICHTEXT ) Then plainText = rtitemBody.GetFormattedText( False, 0 ) Call doc.ReplaceItemValue("tmpBody",plainText) Call doc.save(True,True) End If If daCasellaIs = True Then Call doc.ReplaceItemValue( "Casella", "IST") Call doc.PutInFolder("PeAIstRicevuti") Call doc.RemoveFromFolder( "($Inbox)" ) Call doc.save(True,True) Elseif daCasellaPEC = True Then Call doc.ReplaceItemValue( "Casella", "PEC") Call doc.save(True,True) End If ' idx = Instr(1,doc.From(0)," 0) Or (positionPatt2& > 0)) Then ' ricerco la stringa con formato [Prot. 0000000/0000] all'interno del subject per poi salvare ' i dati nei campi corrispondenti del memo Dim pos As Long Dim strProt As String Dim subj As String Dim pattern As String subj$ = doc.Subject(0) pattern$ = "[Prot" ' [Proposta: 0000021/2012] ssssss tmpSubj = Split(subj$,": [") tmpSubj = tmpSubj(1) tmpSubj = Split(tmpSubj,"]") tmpSubj = tmpSubj(0) tmpSubj = Split(tmpSubj,": ") tmpSubj = tmpSubj(1) tmpSubj = Split(tmpSubj,"/") tmpNumero = tmpSubj(0) tmpAnno = tmpSubj(1) ' Trovo dove comincia la string a che mi interessa... 'pos& = Instr(1, subj$, pattern$) ' Prendo i 20 caratteri a destra a partire da quello trovato se lo trovo 'If pos& > 0 Then 'strProt$ = Mid$(subj$, pos&, 20) ' creo i campi se ho trovato la stringa ' Considera tutto.... 'If strProt$ <> "" Then 'Set PeANumero = doc.ReplaceItemValue("PeANumero",Mid$(strProt$,8,7)) 'Set PeAAnno = doc.ReplaceItemValue("PeAAnno",Mid$(strProt$,16,4)) If CStr(tmpAnno)="0" And CStr(tmpNumero)="0000000" Then 'MsgBox "doc.Subject(0):" + doc.Subject(0) tmpNumero = Right$(doc.Subject(0),19) tmpAnno = "Sedute" End If 'MsgBox "Anno:" + tmpAnno 'MsgBox "Numero:" + tmpNumero Set PeANumero = doc.ReplaceItemValue("PeANumero",tmpNumero) Set PeAAnno = doc.ReplaceItemValue("PeAAnno",tmpAnno) ' ...e salvo il documento Call doc.save(True,True) 'End If 'End If Call doc.PutInFolder("MessaggiPECRicevuti") Call doc.RemoveFromFolder( "($Inbox)" ) Call doc.save(True,True) Else ' Sposta le eventuali "ANOMALIA" e "DELIVERY FAILURE" dalla inbox positionPatt3& = Instr(subject$, patt3$) positionPatt4& = Instr( formName$, patt4$) If ((positionPatt3& > 0) Or (positionPatt4& > 0)) Then Call doc.PutInFolder("MessaggiPECRicevuti") Call doc.RemoveFromFolder( "($Inbox)" ) Call doc.save(True,True) End If End If End If Next Exit Sub errore : Print "Error" & Str(Err) & ": " & Error$ & " Linea:" & Cstr(Erl) Resume Next End Sub