Skip to content

Commit

Permalink
BUG PEC SCAN EMAIL
Browse files Browse the repository at this point in the history
  • Loading branch information
mspasiano committed Sep 5, 2016
1 parent 4d322a3 commit fb1b26a
Showing 1 changed file with 17 additions and 19 deletions.
Expand Up @@ -87,7 +87,8 @@ public class FatturaPassivaElettronicaService implements InitializingBean{
private Boolean pecScanDisable;
private Properties pecMailConf;
private List<String> listaMessageIdAlreadyScanned = new ArrayList<String>();

private Store store;

private String pecHostName, pecURLName, pecSDIAddress, pecSDISubjectFatturaAttivaInvioTerm, pecSDISubjectNotificaPecTerm, pecSDISubjectFatturaPassivaNotificaScartoEsitoTerm,
pecSDIFromStringTerm, pecSDISubjectRiceviFattureTerm, pecSDISubjectFatturaAttivaRicevutaConsegnaTerm, pecSDISubjectFatturaAttivaNotificaScartoTerm, pecSDISubjectFatturaAttivaMancataConsegnaTerm,
pecSDISubjectNotificaEsitoTerm, pecSDISubjectFatturaAttivaDecorrenzaTerminiTerm, pecSDISubjectFatturaAttivaAttestazioneTrasmissioneFatturaTerm, pecHostAddressReturn, pecSDISubjectMancataConsegnaPecTerm;
Expand Down Expand Up @@ -249,7 +250,7 @@ private void riceviFattura(Message message, String userName) throws ComponentExc
}
if (bodyParts.size() > 2) {
logger.warn("Il messaggio con id:"+message.getMessageNumber()+" recuperato dalla casella PEC:"+userName +
" ha più di due file allegati.");
" ha più di due file allegati.");
return;
}
BodyPart bodyPartFattura = null, bodyPartMetadati = null;
Expand Down Expand Up @@ -277,7 +278,7 @@ private void riceviFattura(Message message, String userName) throws ComponentExc
IOUtils.toByteArray(bodyPartMetadati.getInputStream()), bodyPartMetadati.getContentType())));
}
} else {
logger.warn("Il messaggio con id:"+message.getMessageNumber()+" recuperato dalla casella PEC:"+userName + " è stato precessato ma gli allegati presenti non sono conformi.");
logger.warn("Il messaggio con id:"+message.getMessageNumber()+" recuperato dalla casella PEC:"+userName + " è stato precessato ma gli allegati presenti non sono conformi.");
}
} catch (Exception e) {
logger.error("PEC scan error while importing file.", e);
Expand All @@ -288,7 +289,6 @@ private String getReplyTo(Message message) throws MessagingException {
Address[] repliesAddress = message.getReplyTo();
String replyTo = null;
if (repliesAddress != null){
logger.info("Replies: "+repliesAddress.toString());
if (repliesAddress.length > 0){
replyTo = repliesAddress[0].toString();
}
Expand All @@ -315,7 +315,7 @@ private void notificaFatturaPassivaScartoEsito(Message message, String userName)
}
if (bodyParts.size() > 2) {
logger.warn("Il messaggio con id:"+message.getMessageNumber()+" recuperato dalla casella PEC:"+userName +
" ha più di due file allegati.");
" ha pi� di due file allegati.");
return;
}
boolean trovatoFile = false;
Expand All @@ -328,7 +328,7 @@ private void notificaFatturaPassivaScartoEsito(Message message, String userName)
}
}
if (!trovatoFile){
logger.warn("Il messaggio con id:"+message.getMessageNumber()+" recuperato dalla casella PEC:"+userName + " è stato precessato ma gli allegati presenti non sono conformi.");
logger.warn("Il messaggio con id:"+message.getMessageNumber()+" recuperato dalla casella PEC:"+userName + " è stato precessato ma gli allegati presenti non sono conformi.");
SendMail.sendErrorMail("Fatture Elettroniche: Passive: Scarto Esito. Allegati non conformi. Mail:"+userName, message.getDescription());
}
listaMessageIdAlreadyScanned.add(messageIDWithUser);
Expand All @@ -343,8 +343,6 @@ private void notificaFatturaPassivaScartoEsito(Message message, String userName)
}
}


@SuppressWarnings("unchecked")
public void pecScan(String userName, String password) throws ComponentException {
logger.info("PEC SCAN for ricevi Fatture email: "+userName + "pwd :" +password);
Properties props = System.getProperties();
Expand All @@ -357,12 +355,13 @@ public void pecScan(String userName, String password) throws ComponentException
}
final Session session = Session.getInstance(props);
URLName urlName = new URLName(pecURLName);
final Store store = session.getStore(urlName);
store.connect(userName, password);
if (store == null)
store = session.getStore(urlName);
if (!store.isConnected())
store.connect(userName, password);
searchMailFromPec(userName, password, store);
searchMailFromSdi(userName, store);
searchMailFromReturn(userName, store);
store.close();
} catch (AuthenticationFailedException e) {
logger.error("Error while scan PEC email:" +userName + " - password:"+password);
} catch (NoSuchProviderException e) {
Expand All @@ -379,7 +378,7 @@ private void searchMailFromPec(String userName, String password, final Store sto
}
for (Folder folder : folders) {
if (folder.exists()) {
folder.open(Folder.READ_WRITE);
folder.open(Folder.READ_ONLY);
processingMailFromHostPec(folder, userName, password);
folder.close(true);
}
Expand All @@ -393,7 +392,7 @@ private void searchMailFromSdi(String userName, final Store store)
}
for (Folder folder : folders) {
if (folder.exists()) {
folder.open(Folder.READ_WRITE);
folder.open(Folder.READ_ONLY);
processingMailFromSdi(folder, userName);
folder.close(true);
}
Expand All @@ -408,7 +407,7 @@ private void searchMailFromReturn(String userName, final Store store)
}
for (Folder folder : folders) {
if (folder.exists()) {
folder.open(Folder.READ_WRITE);
folder.open(Folder.READ_ONLY);
processingMailFromReturn(folder, userName);
folder.close(true);
}
Expand Down Expand Up @@ -666,7 +665,7 @@ private boolean isBodyPartMetadati(BodyPart bodyPart) {
}

private void notificaFatturaAttivaAvvenutaTrasmissioneNonRecapitata(Message message) throws ComponentException {
logger.info("Fatture Elettroniche: Attive: Inizio Avvenuta Trasmissione con impossibilità di recapito.");
logger.info("Fatture Elettroniche: Attive: Inizio Avvenuta Trasmissione con impossibilit� di recapito.");
try {
BodyPart bodyPartZip = estraiBodyPartZipNotificaFatturaAttiva(message);
if (bodyPartZip != null){
Expand Down Expand Up @@ -830,7 +829,7 @@ public void notificaEsito(String userName, String password, DocumentoEleTestataB
email.setFrom(userName, userName);
email.setSubject(" Notifica di esito " + bulk.getIdentificativoSdi());
email.setMsg("Il file trasmesso con identificativo SdI:" + bulk.getIdentificativoSdi() +
(bulk.isRifiutata() ? " è stato Rifiutato (EC02) poichè " + bulk.getMotivoRifiuto() :" è stato Accettato (EC01)") +
(bulk.isRifiutata() ? " è stato Rifiutato (EC02) poiché " + bulk.getMotivoRifiuto() :" É stato Accettato (EC01)") +
", in allegato la notifica di esito.");

// add the attachment
Expand Down Expand Up @@ -883,8 +882,7 @@ private void estraiParte(Object obj, List<BodyPart> bodyParts, Boolean perAllega
try {
ricezioneFattureService.notificaScartoMailNotificaNonRicevibile(mimemessage, identificativoSdi, getSystemDate());
} catch (ComponentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
logger.error("NotificaScartoMailNotificaNonRicevibile", e);
}
} else {
forwardedEmail(mimemessage.getContent(), bodyParts, perAllegati);
Expand Down Expand Up @@ -919,4 +917,4 @@ public void afterPropertiesSet() throws Exception {
new Integer(java.util.Calendar.getInstance().get(java.util.Calendar.YEAR)),
null,null,null);
}
}
}

0 comments on commit fb1b26a

Please sign in to comment.