Package javax.mail

Examples of javax.mail.MessagingException


    JDCConnection oConn = null;
    try {
      oConn = getConnection();
      iEmptyDrafts = oEmptyDrafts.load(oConn, new Object[]{getCategoryGuid(),((DBStore)getStore()).getUser().getString(DB.gu_workarea)});
    } catch (SQLException sqle) {
    throw new MessagingException(sqle.getMessage(), sqle);
    }
   
    if (iEmptyDrafts>0) {
    sSQL = "UPDATE " + DB.k_mime_msgs + " SET " + DB.bo_deleted + "=1 WHERE " + DB.gu_mimemsg + "=?";
   
      if (DebugFile.trace) DebugFile.writeln("Connection.prepareStatement("+sSQL+")");
   
      try {
        oUpdt = oConn.prepareStatement(sSQL);
        for (int d=0; d<iEmptyDrafts; d++) {
          oUpdt.setString(1,oEmptyDrafts.getString(0,d));
        oUpdt.executeUpdate();
        } // next
      oUpdt.close();
      } catch (SQLException sqle) {
      throw new MessagingException(sqle.getMessage(), sqle);
      }
    } // fi

    // ***********************************************
    // Get the list of deleted and not purged messages

    MboxFile oMBox = null;
    DBSubset oDeleted = new DBSubset(DB.k_mime_msgs,
                                     DB.gu_mimemsg+","+DB.pg_message,
                                     DB.bo_deleted+"=1 AND "+DB.gu_category+"='"+oCatg.getString(DB.gu_category)+"'", 100);

    try {
      int iDeleted = oDeleted.load(getConnection());

      File oFile = getFile();

      // *************************************
      // Purge deleted messages from MBOX file

      if (oFile.exists() && iDeleted>0) {
        oMBox = new MboxFile(oFile, MboxFile.READ_WRITE);
        int[] msgnums = new int[iDeleted];
        for (int m=0; m<iDeleted; m++)
          msgnums[m] = oDeleted.getInt(1, m);
        oMBox.purge(msgnums);
        oMBox.close();
      }

      // *********************************************************
      // Remove from disk the files referenced by deleted messages

      oStmt = oConn.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
     
      if (DebugFile.trace) DebugFile.writeln("Connection.executeQuery(SELECT p." + DB.file_name + " FROM " + DB.k_mime_parts + " p," + DB.k_mime_msgs + " m WHERE p." + DB.gu_mimemsg + "=m."+ DB.gu_mimemsg + " AND m." + DB.id_disposition + "='reference' AND m." + DB.bo_deleted + "=1 AND m." + DB.gu_category +"='"+oCatg.getString(DB.gu_category)+"')");

      oRSet = oStmt.executeQuery("SELECT p." + DB.id_part + ",p." + DB.id_type + ",p." + DB.file_name + " FROM " + DB.k_mime_parts + " p," + DB.k_mime_msgs + " m WHERE p." +
                                 DB.gu_mimemsg + "=m."+ DB.gu_mimemsg + " AND m." + DB.id_disposition + "='reference' AND m." +
                                 DB.bo_deleted + "=1 AND m." + DB.gu_category +"='"+oCatg.getString(DB.gu_category)+"'");

      while (oRSet.next()) {
        if (DebugFile.trace) DebugFile.writeln("processing part "+String.valueOf(oRSet.getInt(1))+" "+oRSet.getString(2));
        String sFileName = oRSet.getString(3);
        if (!oRSet.wasNull()) {
          if (DebugFile.trace) DebugFile.writeln("trying to delete file "+sFileName);
          try {
            File oRef = new File(sFileName);
            if (oRef.exists())
              oRef.delete();
            else if (DebugFile.trace)
              DebugFile.writeln("file "+sFileName+" not found");           
          }
          catch (SecurityException se) {
            if (DebugFile.trace) DebugFile.writeln("SecurityException deleting file " + sFileName + " " + se.getMessage());
          }
        }
      } // wend

      oRSet.close();
      oRSet = null;
      oStmt.close();
      oStmt = null;

      // ****************************************************
      // Set Category size to length of MBOX file after purge

      oFile = getFile();
      oStmt = oConn.createStatement();
      oStmt.executeUpdate("UPDATE "+DB.k_categories+" SET "+DB.len_size+"="+String.valueOf(oFile.length())+" WHERE "+DB.gu_category+"='"+getCategory().getString(DB.gu_category)+"'");
      oStmt.close();
      oStmt=null;

      // *********************************************
      // Actually delete messages from database tables

      if (oConn.getDataBaseProduct()==JDCConnection.DBMS_POSTGRESQL) {
        oStmt = oConn.createStatement();
        for (int d=0; d<iDeleted; d++)
          oStmt.executeQuery("SELECT k_sp_del_mime_msg('" + oDeleted.getString(0,d) + "')");
        oStmt.close();
        oStmt=null;
      }
      else {
        oCall = oConn.prepareCall("{ call k_sp_del_mime_msg(?) }");

        for (int d=0; d<iDeleted; d++) {
          oCall.setString(1, oDeleted.getString(0,d));
          oCall.execute();
        } // next
        oCall.close();
        oCall=null;
      }

      if (oFile.exists() && iDeleted>0) {

        // ***********************************************************************
        // Temporary move all messages at k_mime_msgs, k_mime_parts & k_inet_addrs
        // beyond its maximum so they do not clash when progressive identifiers
        // are re-assigned

        BigDecimal oUnit = new BigDecimal(1);
        oStmt = oConn.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
        oRSet = oStmt.executeQuery("SELECT MAX("+DB.pg_message+") FROM "+DB.k_mime_msgs+" WHERE "+DB.gu_category+"='"+getCategory().getString(DB.gu_category)+"'");
        oRSet.next();
        BigDecimal oMaxPg = oRSet.getBigDecimal(1);
        if (oRSet.wasNull()) oMaxPg = new BigDecimal(0);
        oRSet.close();
        oRSet = null;
        oStmt.close();
        oStmt = null;
        oMaxPg = oMaxPg.add(oUnit);

        String sCat = getCategory().getString(DB.gu_category);
        oStmt = oConn.createStatement();
        oStmt.executeUpdate("UPDATE "+DB.k_mime_msgs+" SET "+DB.pg_message+"="+DB.pg_message+"+"+oMaxPg.toString()+" WHERE "+DB.gu_category+"='"+sCat+"'");
        oStmt.close();
        oStmt = null;

        // *********************************************************************************
        // Re-assign ordinal position and byte offset for all messages remaining after purge

        DBSubset oMsgSet = new DBSubset(DB.k_mime_msgs, DB.gu_mimemsg+","+DB.pg_message, DB.gu_category+"='"+getCategory().getString(DB.gu_category)+"' ORDER BY "+DB.pg_message, 1000);
        int iMsgCount = oMsgSet.load(oConn);

        oMBox = new MboxFile(oFile, MboxFile.READ_ONLY);
        long[] aPositions = oMBox.getMessagePositions();
        oMBox.close();

        oMaxPg = new BigDecimal(0);
        oUpdt = oConn.prepareStatement("UPDATE "+DB.k_mime_msgs+" SET "+DB.pg_message+"=?,"+DB.nu_position+"=? WHERE "+DB.gu_mimemsg+"=?");
        oPart = oConn.prepareStatement("UPDATE "+DB.k_mime_parts+" SET "+DB.pg_message+"=? WHERE "+DB.gu_mimemsg+"=?");
        oAddr = oConn.prepareStatement("UPDATE "+DB.k_inet_addrs+" SET "+DB.pg_message+"=? WHERE "+DB.gu_mimemsg+"=?");
        for (int m=0; m<iMsgCount; m++) {
          String sGuMsg = oMsgSet.getString(0,m);
          oUpdt.setBigDecimal(1, oMaxPg);
          oUpdt.setBigDecimal(2, new BigDecimal(aPositions[m]));
          oUpdt.setString(3, sGuMsg);
          oUpdt.executeUpdate();
          oPart.setBigDecimal(1, oMaxPg);
          oPart.setString(2, sGuMsg);
          oPart.executeUpdate();
          oAddr.setBigDecimal(1, oMaxPg);
          oAddr.setString(2, sGuMsg);
          oAddr.executeUpdate();
          oMaxPg = oMaxPg.add(oUnit);
        }
        oUpdt.close();
        oPart.close();
        oAddr.close();
      }
      oConn.commit();
    } catch (SQLException sqle) {
      try { if (oMBox!=null) oMBox.close(); } catch (Exception e) {}
      try { if (oStmt!=null) oStmt.close(); } catch (Exception e) {}
      try { if (oCall!=null) oCall.close(); } catch (Exception e) {}
      try { if (oConn!=null) oConn.rollback(); } catch (Exception e) {}
      throw new MessagingException (sqle.getMessage(), sqle);
    }
    catch (IOException sqle) {
      try { if (oMBox!=null) oMBox.close(); } catch (Exception e) {}
      try { if (oStmt!=null) oStmt.close(); } catch (Exception e) {}
      try { if (oCall!=null) oCall.close(); } catch (Exception e) {}
      try { if (oConn!=null) oConn.rollback(); } catch (Exception e) {}
      throw new MessagingException (sqle.getMessage(), sqle);
    }

    if (DebugFile.trace) {
      DebugFile.decIdent();
      DebugFile.writeln("End DBFolder.expunge()");
View Full Code Here


    } catch (Exception sqle) {
      try { if (oMBox!=null) oMBox.close(); } catch (Exception e) {}
      try { if (oStmt!=null) oStmt.close(); } catch (Exception e) {}
      try { if (oCall!=null) oCall.close(); } catch (Exception e) {}
      try { if (oConn!=null) oConn.rollback(); } catch (Exception e) {}
      throw new MessagingException (sqle.getMessage(), sqle);
    }

    if (DebugFile.trace) {
      DebugFile.decIdent();
      DebugFile.writeln("End DBFolder.wipe()");
View Full Code Here

      }

      try { if (oRSet!=null) oRSet.close(); } catch (SQLException ignore) { }
      try { if (oStmt!=null) oStmt.close(); } catch (SQLException ignore) { }

      throw new MessagingException (sqle.getMessage(), sqle);
    }
    catch (UnsupportedEncodingException uee) {

      if (DebugFile.trace) {
        DebugFile.writeln("UnsupportedEncodingException "+uee.getMessage());
        DebugFile.decIdent();
      }

      try { if (oRSet!=null) oRSet.close(); } catch (SQLException ignore) { }
      try { if (oStmt!=null) oStmt.close(); } catch (SQLException ignore) { }

      throw new MessagingException (uee.getMessage(), uee);
    }

    if (DebugFile.trace) {
        DebugFile.decIdent();
        DebugFile.writeln("End DBFolder.getMessage() : " + (oRetVal!=null ? "[MimeMessage]" : "null"));
View Full Code Here

        DebugFile.decIdent();
      }
      // Ensure that statement is closed and re-throw
      if (null!=oStmt) { try {oStmt.close();} catch (Exception ignore) {} }
      try { if (null!=oConn) oConn.rollback(); } catch (Exception ignore) {}
      throw new MessagingException (e.getMessage(), e);
    }
    catch (IOException e) {
      if (DebugFile.trace) {
        DebugFile.writeln("IOException " + e.getMessage());
        DebugFile.decIdent();
      }
      // Ensure that statement is closed and re-throw
      if (null!=oStmt) { try {oStmt.close();} catch (Exception ignore) {} }
      throw new MessagingException (e.getMessage(), e);
    }
    catch (Exception e) {
      if (DebugFile.trace) {
        DebugFile.writeln(e.getClass().getName() + " " + e.getMessage());
        DebugFile.decIdent();
      }
      // Ensure that statement is closed and re-throw
      if (null!=oStmt) { try {oStmt.close();} catch (Exception ignore) {} }
      throw new MessagingException (e.getMessage(), e);
    }

    if (DebugFile.trace) {
      DebugFile.decIdent();
      DebugFile.writeln("End DBFolder.saveMimeParts()");
View Full Code Here

      oStmt.close();
      oStmt=null;
    } catch (Exception xcpt) {
      try { if (null!=oRSet) oRSet.close(); } catch (Exception ignore) {}
      try { if (null!=oStmt) oStmt.close(); } catch (Exception ignore) {}
      throw new MessagingException(xcpt.getMessage(),xcpt);
    }
    return oNext;
  } // getNextMessage()
View Full Code Here

      try { sTrace = com.knowgate.debug.StackTraceUtil.getStackTrace(sqle);
        DebugFile.writeln(sTrace);
      } catch (Exception ignore) {}
      try { if (null!=oStmt) oStmt.close(); oStmt=null; } catch (Exception ignore) {}
      try { if (null!=oConn) oConn.rollback(); } catch (Exception ignore) {}
      throw new MessagingException(DB.k_mime_msgs + " " + sqle.getMessage(), sqle);
    }
    if ((iOpenMode&MODE_BLOB)!=0) {
      // Deallocate byte array containing message body for freeing memory as soon as possible
      try { byOutStrm.close(); } catch (IOException ignore) {}
      byOutStrm = null;
    }

    // *************************************************************************
    // Now that we have saved the main message reference proceed to store
    // its parts into k_mime_parts

    try {
      Object oContent = oMsg.getContent();
      if (oContent instanceof MimeMultipart) {
        try {
          saveMimeParts(oMsg, sMsgCharSeq, sBoundary, sGuMimeMsg, sMessageID, dPgMessage.intValue(), 0);
        } catch (MessagingException msge) {
          // Close Mbox file rollback and re-throw
          try { oConn.rollback(); } catch (Exception ignore) {}
          throw new MessagingException(msge.getMessage(), msge.getNextException());
        }
      } // fi (MimeMultipart)
    } catch (Exception xcpt) {
      try { oConn.rollback(); } catch (Exception ignore) {}
      throw new MessagingException("MimeMessage.getContent() " + xcpt.getMessage(), xcpt);
    }

    // *************************************************************************
    // Store message recipients at k_inet_addrs

    try {
      if (oConn.getDataBaseProduct()==JDCConnection.DBMS_MYSQL)
        sSQL = "SELECT "+DB.gu_contact+","+DB.gu_company+","+DB.tx_name+","+DB.tx_surname+","+DB.tx_surname+" FROM "+DB.k_member_address+" WHERE "+DB.tx_email+"=? AND "+DB.gu_workarea+"=? UNION SELECT "+DB.gu_user+",CONVERT('****************************USER' USING utf8),"+DB.nm_user+","+DB.tx_surname1+","+DB.tx_surname2+" FROM "+DB.k_users+" u WHERE (u."+DB.tx_main_email+"=? OR u."+DB.tx_alt_email+"=? OR EXISTS (SELECT a."+DB.gu_user+" FROM "+DB.k_user_mail+" a WHERE a."+DB.gu_user+"=u."+DB.gu_user+" AND a."+DB.tx_main_email+"=?)) AND "+DB.gu_workarea+"=?";
      else
        sSQL = "SELECT "+DB.gu_contact+","+DB.gu_company+","+DB.tx_name+","+DB.tx_surname+","+DB.tx_surname+" FROM "+DB.k_member_address+" WHERE "+DB.tx_email+"=? AND "+DB.gu_workarea+"=? UNION SELECT "+DB.gu_user+",'****************************USER',"+DB.nm_user+","+DB.tx_surname1+","+DB.tx_surname2+" FROM "+DB.k_users+" u WHERE (u."+DB.tx_main_email+"=? OR u."+DB.tx_alt_email+"=? OR EXISTS (SELECT a."+DB.gu_user+" FROM "+DB.k_user_mail+" a WHERE a."+DB.gu_user+"=u."+DB.gu_user+" AND a."+DB.tx_main_email+"=?)) AND "+DB.gu_workarea+"=?";
    } catch (SQLException sqle) {
      if (DebugFile.trace) DebugFile.writeln("SQLException " + sqle.getMessage());
      sSQL = "SELECT "+DB.gu_contact+","+DB.gu_company+","+DB.tx_name+","+DB.tx_surname+","+DB.tx_surname+" FROM "+DB.k_member_address+" WHERE "+DB.tx_email+"=? AND "+DB.gu_workarea+"=? UNION SELECT "+DB.gu_user+",'****************************USER',"+DB.nm_user+","+DB.tx_surname1+","+DB.tx_surname2+" FROM "+DB.k_users+" u WHERE (u."+DB.tx_main_email+"=? OR u."+DB.tx_alt_email+"=? OR EXISTS (SELECT a."+DB.gu_user+" FROM "+DB.k_user_mail+" a WHERE a."+DB.gu_user+"=u."+DB.gu_user+" AND a."+DB.tx_main_email+"=?)) AND "+DB.gu_workarea+"=?";
    }

    if (DebugFile.trace) DebugFile.writeln("Connection.prepareStatement(" + sSQL + ")");

    PreparedStatement oAddr = null;

    try {
      oAddr = oConn.prepareStatement(sSQL, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
      ResultSet oRSet;

      InternetAddress oInetAdr;
      String sTxEmail, sGuCompany, sGuContact, sTxName, sTxSurname1, sTxSurname2, sTxPersonal;

      // Get From address and keep them into pFrom properties

      if (oFrom!=null) {
        oAddr.setString(1, oFrom.getAddress());
        oAddr.setString(2, sGuWorkArea);
        oAddr.setString(3, oFrom.getAddress());
        oAddr.setString(4, oFrom.getAddress());
        oAddr.setString(5, oFrom.getAddress());
        oAddr.setString(6, sGuWorkArea);

        oRSet = oAddr.executeQuery();
        if (oRSet.next()) {
          sGuContact = oRSet.getString(1);
          if (oRSet.wasNull()) sGuContact = "null";
          sGuCompany = oRSet.getString(2);
          if (oRSet.wasNull()) sGuCompany = "null";

          if (sGuCompany.equals("****************************USER")) {
            sTxName = oRSet.getString(3);
            if (oRSet.wasNull()) sTxName = "";
            sTxSurname1 = oRSet.getString(4);
            if (oRSet.wasNull()) sTxSurname1 = "";
            sTxSurname2 = oRSet.getString(4);
            if (oRSet.wasNull()) sTxSurname2 = "";
            sTxPersonal = Gadgets.left(sTxName+" "+sTxSurname1+" "+sTxSurname2, 254).replace(',',' ').trim();
          }
          else
            sTxPersonal = "null";

          if (DebugFile.trace) DebugFile.writeln("from "+sGuContact+","+sGuCompany+","+sTxPersonal);
          pFrom.put(oFrom.getAddress(), sGuContact+","+sGuCompany+","+sTxPersonal);
        }
        else
          pFrom.put(oFrom.getAddress(), "null,null,null");

      oRSet.close();
      } // fi (oFrom)

      if (DebugFile.trace) DebugFile.writeln("from count = " + pFrom.size());

      // Get TO address and keep them into pTo properties

      if (oTo!=null) {
        for (int t=0; t<oTo.length; t++) {
          oInetAdr = (InternetAddress) oTo[t];
          sTxEmail = Gadgets.left(oInetAdr.getAddress(), 254);

          oAddr.setString(1, sTxEmail);
          oAddr.setString(2, sGuWorkArea);
          oAddr.setString(3, sTxEmail);
          oAddr.setString(4, sTxEmail);
          oAddr.setString(5, sTxEmail);
          oAddr.setString(6, sGuWorkArea);

          oRSet = oAddr.executeQuery();
          if (oRSet.next()) {
            sGuContact = oRSet.getString(1);
            if (oRSet.wasNull()) sGuContact = "null";
            sGuCompany = oRSet.getString(2);
            if (oRSet.wasNull()) sGuCompany = "null";
            if (sGuCompany.equals("****************************USER")) {
              sTxName = oRSet.getString(3);
              if (oRSet.wasNull()) sTxName = "";
              sTxSurname1 = oRSet.getString(4);
              if (oRSet.wasNull()) sTxSurname1 = "";
              sTxSurname2 = oRSet.getString(4);
              if (oRSet.wasNull()) sTxSurname2 = "";
              sTxPersonal = Gadgets.left(sTxName+" "+sTxSurname1+" "+sTxSurname2, 254).replace(',',' ').trim();
            }
            else
              sTxPersonal = "null";

            pTo.put(sTxEmail, sGuContact+","+sGuCompany+","+sTxPersonal);
          } // fi (oRSet.next())
          else
            pTo.put(sTxEmail, "null,null,null");

          oRSet.close();
        } // next (t)
      } // fi (oTo)

      if (DebugFile.trace) DebugFile.writeln("to count = " + pTo.size());

      // Get CC address and keep them into pTo properties

      if (oCC!=null) {
        for (int c=0; c<oCC.length; c++) {
          oInetAdr = (InternetAddress) oCC[c];
          sTxEmail = Gadgets.left(oInetAdr.getAddress(), 254);

          oAddr.setString(1, sTxEmail);
          oAddr.setString(2, sGuWorkArea);
          oAddr.setString(3, sTxEmail);
          oAddr.setString(4, sTxEmail);
          oAddr.setString(5, sTxEmail);
          oAddr.setString(6, sGuWorkArea);

          oRSet = oAddr.executeQuery();
          if (oRSet.next()) {
            sGuContact = oRSet.getString(1);
            if (oRSet.wasNull()) sGuContact = "null";
            sGuCompany = oRSet.getString(2);
            if (oRSet.wasNull()) sGuCompany = "null";
            if (sGuCompany.equals("****************************USER")) {
              sTxName = oRSet.getString(3);
              if (oRSet.wasNull()) sTxName = "";
              sTxSurname1 = oRSet.getString(4);
              if (oRSet.wasNull()) sTxSurname1 = "";
              sTxSurname2 = oRSet.getString(4);
              if (oRSet.wasNull()) sTxSurname2 = "";
              sTxPersonal = Gadgets.left(sTxName+" "+sTxSurname1+" "+sTxSurname2, 254).replace(',',' ').trim();
            }
            else
              sTxPersonal = "null";

            pCC.put(sTxEmail, sGuContact+","+sGuCompany+","+sTxPersonal);
          } // fi (oRSet.next())
          else
            pCC.put(sTxEmail, "null,null,null");

          oRSet.close();
        } // next (c)
      } // fi (oCC)

      if (DebugFile.trace) DebugFile.writeln("cc count = " + pCC.size());

      // Get BCC address and keep them into pTo properties

      if (oBCC!=null) {
        for (int b=0; b<oBCC.length; b++) {
          oInetAdr = (InternetAddress) oBCC[b];
          sTxEmail = Gadgets.left(oInetAdr.getAddress(), 254);

          oAddr.setString(1, sTxEmail);
          oAddr.setString(2, sGuWorkArea);
          oAddr.setString(3, sTxEmail);
          oAddr.setString(4, sTxEmail);
          oAddr.setString(5, sTxEmail);
          oAddr.setString(6, sGuWorkArea);

          oRSet = oAddr.executeQuery();
          if (oRSet.next()) {
            sGuContact = oRSet.getString(1);
            if (oRSet.wasNull()) sGuContact = "null";
            sGuCompany = oRSet.getString(2);
            if (oRSet.wasNull()) sGuCompany = "null";
            if (sGuCompany.equals("****************************USER")) {
              sTxName = oRSet.getString(3);
              if (oRSet.wasNull()) sTxName = "";
              sTxSurname1 = oRSet.getString(4);
              if (oRSet.wasNull()) sTxSurname1 = "";
              sTxSurname2 = oRSet.getString(4);
              if (oRSet.wasNull()) sTxSurname2 = "";
              sTxPersonal = Gadgets.left(sTxName+" "+sTxSurname1+" "+sTxSurname2, 254).replace(',',' ').trim();
            }
            else
              sTxPersonal = "null";

            pBCC.put(sTxEmail, sGuContact+","+sGuCompany);
          } // fi (oRSet.next())
          else
            pBCC.put(sTxEmail, "null,null,null");

          oRSet.close();
        } // next (b)
      } // fi (oCBB)

      if (DebugFile.trace) DebugFile.writeln("bcc count = " + pBCC.size());

      oAddr.close();

      sSQL = "INSERT INTO " + DB.k_inet_addrs + " (gu_mimemsg,id_message,pg_message,tx_email,tp_recipient,gu_user,gu_contact,gu_company,tx_personal) VALUES ('"+sGuMimeMsg+"',?,"+String.valueOf(dPgMessage.intValue())+",?,?,?,?,?,?)";

      if (DebugFile.trace) DebugFile.writeln("Connection.prepareStatement(" + sSQL + ")");

      oStmt = oConn.prepareStatement(sSQL);

      java.util.Enumeration oMailEnum;
      String[] aRecipient;

      if (!pFrom.isEmpty()) {
        oMailEnum = pFrom.keys();
        while (oMailEnum.hasMoreElements()) {
          oStmt.setString(1, sMessageID);
          sTxEmail = (String) oMailEnum.nextElement();
          if (DebugFile.trace) DebugFile.writeln("processing mail address "+sTxEmail);
          aRecipient = Gadgets.split(pFrom.getProperty(sTxEmail),',');

          oStmt.setString(2, sTxEmail);
          oStmt.setString(3, "from");

          if (aRecipient[0].equals("null") && aRecipient[1].equals("null")) {
            oStmt.setNull(4, Types.CHAR);
            oStmt.setNull(5, Types.CHAR);
            oStmt.setNull(6, Types.CHAR);
          }
          else if (aRecipient[1].equals("****************************USER")) {
            oStmt.setString(4, aRecipient[0]);
            oStmt.setNull(5, Types.CHAR);
            oStmt.setNull(6, Types.CHAR);
          }
          else {
            oStmt.setNull(4, Types.CHAR);
            oStmt.setString(5, aRecipient[0].equals("null") ? null : aRecipient[0]);
            oStmt.setString(6, aRecipient[1].equals("null") ? null : aRecipient[1]);
          }

          if (aRecipient[2].equals("null"))
            oStmt.setNull(7, Types.VARCHAR);
          else
            oStmt.setString(7, aRecipient[2]);

          if (DebugFile.trace) DebugFile.writeln("Statement.executeUpdate()");
          oStmt.executeUpdate();
        } // wend
      } // fi (from)

      if (!pTo.isEmpty()) {
        oMailEnum = pTo.keys();
        while (oMailEnum.hasMoreElements()) {
          oStmt.setString(1, sMessageID);
          sTxEmail = (String) oMailEnum.nextElement();
          aRecipient = Gadgets.split(pTo.getProperty(sTxEmail),',');

          oStmt.setString(2, sTxEmail);
          oStmt.setString(3, "to");

          if (aRecipient[0].equals("null") && aRecipient[1].equals("null")) {
            oStmt.setNull(4, Types.CHAR);
            oStmt.setNull(5, Types.CHAR);
            oStmt.setNull(6, Types.CHAR);
          }
          else if (aRecipient[1].equals("****************************USER")) {
            oStmt.setString(4, aRecipient[0]);
            oStmt.setNull(5, Types.CHAR);
            oStmt.setNull(6, Types.CHAR);
          }
          else {
            oStmt.setNull(4, Types.CHAR);
            oStmt.setString(5, aRecipient[0].equals("null") ? null : aRecipient[0]);
            oStmt.setString(6, aRecipient[1].equals("null") ? null : aRecipient[1]);
          }

          if (aRecipient[2].equals("null"))
            oStmt.setNull(7, Types.VARCHAR);
          else
            oStmt.setString(7, aRecipient[2]);

          if (DebugFile.trace) DebugFile.writeln("Statement.executeUpdate()");

          oStmt.executeUpdate();
        } // wend
      } // fi (to)

      if (!pCC.isEmpty()) {
        oMailEnum = pCC.keys();
        while (oMailEnum.hasMoreElements()) {
          oStmt.setString(1, sMessageID);
          sTxEmail = (String) oMailEnum.nextElement();
          aRecipient = Gadgets.split(pCC.getProperty(sTxEmail),',');

          oStmt.setString(2, sTxEmail);
          oStmt.setString(3, "cc");

          if (aRecipient[0].equals("null") && aRecipient[1].equals("null")) {
            oStmt.setNull(4, Types.CHAR);
            oStmt.setNull(5, Types.CHAR);
            oStmt.setNull(6, Types.CHAR);
          }
          else if (aRecipient[1].equals("****************************USER")) {
            oStmt.setString(4, aRecipient[0]);
            oStmt.setString(5, null);
            oStmt.setString(6, null);
          }
          else {
            oStmt.setString(4, null);
            oStmt.setString(5, aRecipient[0].equals("null") ? null : aRecipient[0]);
            oStmt.setString(6, aRecipient[1].equals("null") ? null : aRecipient[1]);
          }

          if (aRecipient[2].equals("null"))
            oStmt.setNull(7, Types.VARCHAR);
          else
            oStmt.setString(7, aRecipient[2]);

          if (DebugFile.trace) DebugFile.writeln("Statement.executeUpdate()");

          oStmt.executeUpdate();
        } // wend
      } // fi (cc)

      if (!pBCC.isEmpty()) {
        oMailEnum = pBCC.keys();
        while (oMailEnum.hasMoreElements()) {
          oStmt.setString(1, sMessageID);
          sTxEmail = (String) oMailEnum.nextElement();
          aRecipient = Gadgets.split(pBCC.getProperty(sTxEmail),',');

          oStmt.setString(2, sTxEmail);
          oStmt.setString(3, "bcc");

          if (aRecipient[0].equals("null") && aRecipient[1].equals("null")) {
            oStmt.setNull(4, Types.CHAR);
            oStmt.setNull(5, Types.CHAR);
            oStmt.setNull(6, Types.CHAR);
          }
          else if (aRecipient[1].equals("****************************USER")) {
            oStmt.setString(4, aRecipient[0]);
            oStmt.setNull(5, Types.CHAR);
            oStmt.setNull(6, Types.CHAR);
          }
          else {
            oStmt.setNull(4, Types.CHAR);
            oStmt.setString(5, aRecipient[0].equals("null") ? null : aRecipient[0]);
            oStmt.setString(6, aRecipient[1].equals("null") ? null : aRecipient[1]);
          }

          if (aRecipient[2].equals("null"))
            oStmt.setNull(7, Types.VARCHAR);
          else
            oStmt.setString(7, aRecipient[2]);

          oStmt.executeUpdate();
        } // wend
      } // fi (bcc)

      oStmt.close();
      oStmt=null;

      oStmt = oConn.prepareStatement("UPDATE "+DB.k_categories+" SET "+DB.len_size+"="+DB.len_size+"+"+String.valueOf(iSize)+" WHERE "+DB.gu_category+"=?");
      oStmt.setString(1, getCategory().getString(DB.gu_category));
      oStmt.executeUpdate();
      oStmt.close();
      oStmt=null;

    } catch (SQLException sqle) {
      try { if (null!=oStmt) oStmt.close(); oStmt=null; } catch (Exception ignore) {}
      try { if (null!=oAddr) oAddr.close(); oAddr=null; } catch (Exception ignore) {}
      if (DebugFile.trace) DebugFile.decIdent();
      throw new MessagingException(sqle.getMessage(), sqle);
    }
    if (DebugFile.trace) {
      DebugFile.decIdent();
      DebugFile.writeln("End DBFolder.indexMessage()");
    }
View Full Code Here

    } catch (OutOfMemoryError oom) {
      try { if (null!=byOutStrm) byOutStrm.close(); } catch (Exception ignore) {}
      try { if (null!=oMBox) oMBox.close(); } catch (Exception ignore) {}
      if (DebugFile.trace) DebugFile.decIdent();
      throw new MessagingException("OutOfMemoryError " + oom.getMessage());
    } catch (Exception xcpt) {
      try { if (null!=byOutStrm) byOutStrm.close(); } catch (Exception ignore) {}
      try { if (oMBox!=null) oMBox.close(); } catch (Exception ignore) {}
      if (DebugFile.trace) {
    DebugFile.writeln(xcpt.getClass().getName() + " " + xcpt.getMessage());
    DebugFile.writeStackTrace(xcpt);
        DebugFile.decIdent();
      }
      throw new MessagingException(xcpt.getClass().getName() + " " + xcpt.getMessage(), xcpt);
    }

    // End Gathering MimeMessage headers
    // *************************************************************************

 
View Full Code Here

      oStmt=null;
    } catch (SQLException sqle) {
      oCount = new Integer(0);
      try { if (null!=oRSet) oRSet.close(); catch (Exception ignore) {}
      try { if (null!=oStmt) oStmt.close(); catch (Exception ignore) {}
      throw new MessagingException(sqle.getMessage(), sqle);
    }

    if (DebugFile.trace) {
      DebugFile.decIdent();
      DebugFile.writeln("End DBFolder.getMessageCount() : " + oCount.toString());
View Full Code Here

        try {
          oMailTransport.connect();
        }
        catch (NoSuchProviderException nspe) {
          if (DebugFile.trace) DebugFile.writeln("MailTransport.connect() NoSuchProviderException " + nspe.getMessage());
          throw new MessagingException(nspe.getMessage(), nspe);
        }
      } // fi (Session.getInstance())
    } // fi (oMailSession)

    MimeMessage oMsg;
    InternetAddress oFrom, oTo;
    MimeMultipart oAltParts = new MimeMultipart("alternative");
   
    // Set alternative plain/text part to avoid spam filters as much as possible
    MimeBodyPart oMsgTextPart = new MimeBodyPart();
  oMsgTextPart.setText("This message is HTML, but your e-mail client is not capable of rendering HTML messages", "UTF-8", "plain");

    MimeBodyPart oMsgBodyPart = new MimeBodyPart();
 
    try {
      if (null==getParameter("tx_sender"))
        oFrom = new InternetAddress(getParameter("tx_from"));
      else
        oFrom = new InternetAddress(getParameter("tx_from"), getParameter("tx_sender"));

      if (DebugFile.trace) DebugFile.writeln("to: " + oAtm.getStringNull(DB.tx_email, "ERROR Atom[" + String.valueOf(oAtm.getInt(DB.pg_atom)) + "].tx_email is null!"));

      oTo = new InternetAddress(oAtm.getString(DB.tx_email), oAtm.getStringNull(DB.tx_name,"") + " " + oAtm.getStringNull(DB.tx_surname,""));
    }
    catch (AddressException adre) {
      if (DebugFile.trace) DebugFile.writeln("AddressException " + adre.getMessage() + " job " + getString(DB.gu_job) + " atom " + String.valueOf(oAtm.getInt(DB.pg_atom)));

      oFrom = null;
      oTo = null;

      throw new MessagingException ("AddressException " + adre.getMessage() + " job " + getString(DB.gu_job) + " atom " + String.valueOf(oAtm.getInt(DB.pg_atom)));
    }

    if (DebugFile.trace) DebugFile.writeln("new MimeMessage([Session])");

    oMsg = new MimeMessage(oMailSession);

    oMsg.setSubject(getParameter("tx_subject"));

    oMsg.setFrom(oFrom);

    if (DebugFile.trace) DebugFile.writeln("MimeMessage.addRecipient(MimeMessage.RecipientType.TO, " + oTo.getAddress());

    oMsg.addRecipient(MimeMessage.RecipientType.TO, oTo);

    String sSrc = null, sCid = null;

    try {
   
    // Insert Web Beacon just before </BODY> tag
    if (Yes.equals(getParameter("bo_webbeacon"))) {
      int iEndBody = Gadgets.indexOfIgnoreCase(oReplaced, "</body>", 0);
      if (iEndBody>0) {
        String sWebBeaconDir = getProperty("webbeacon");       
        if (sWebBeaconDir==null) {
          sWebBeaconDir = Gadgets.chomp(getParameter("webserver"),'/')+"hipermail/";
        } else if (sWebBeaconDir.trim().length()==0) {
          sWebBeaconDir = Gadgets.chomp(getParameter("webserver"),'/')+"hipermail/";
        }
        oReplaced = oReplaced.substring(0, iEndBody)+"<img src=\""+Gadgets.chomp(sWebBeaconDir,'/')+"web_beacon.jsp?gu_job="+getString(DB.gu_job)+"&pg_atom="+String.valueOf(oAtm.getInt(DB.pg_atom))+"&gu_company="+oAtm.getStringNull(DB.gu_company,"")+"&gu_contact="+oAtm.getStringNull(DB.gu_contact,"")+"&tx_email="+oAtm.getStringNull(DB.tx_email,"")+"\" width=\"1\" height=\"1\" border=\"0\" alt=\"\" />"+oReplaced.substring(iEndBody);         
      } // fi </body>
    } // fi (bo_webbeacon)
     
      // Images may be attached into message or be absolute http source references
      if (Yes.equals(getParameter("bo_attachimages"))) {

        if (DebugFile.trace) DebugFile.writeln("BodyPart.setText("+oReplaced.replace('\n',' ')+",UTF-8,html)");

        oMsgBodyPart.setText(oReplaced, "UTF-8", "html");

        // Create a related multi-part to combine the parts
        MimeMultipart oRelatedMultiPart = new MimeMultipart("related");
        oRelatedMultiPart.addBodyPart(oMsgBodyPart);

        Iterator<String> oImgs = oDocumentImages.keySet().iterator();

        while (oImgs.hasNext()) {
          MimeBodyPart oImgBodyPart = new MimeBodyPart();

          sCid = oImgs.next();
          sSrc = oDocumentImages.get(sCid);

          if (sSrc.startsWith("www."))
            sSrc = "http://" + sSrc;

          if (sSrc.startsWith("http://") || sSrc.startsWith("https://")) {
            oImgBodyPart.setDataHandler(new DataHandler(new URL(sSrc)));
          }
          else {
            oImgBodyPart.setDataHandler(new DataHandler(new FileDataSource(sSrc)));
          }

          oImgBodyPart.setContentID(sCid);
          oImgBodyPart.setDisposition(oImgBodyPart.INLINE);
          oImgBodyPart.setFileName(sCid);

          // Add part to multi-part
          oRelatedMultiPart.addBodyPart(oImgBodyPart);
        } // wend

        MimeBodyPart oTextHtmlRelated = new MimeBodyPart();
        oTextHtmlRelated.setContent(oRelatedMultiPart);

    oAltParts.addBodyPart(oMsgTextPart);
    oAltParts.addBodyPart(oTextHtmlRelated);

      MimeMultipart oSentMsgParts = new MimeMultipart("mixed");
     MimeBodyPart oMixedPart = new MimeBodyPart();
       
        oMixedPart.setContent(oAltParts);
        oSentMsgParts.addBodyPart(oMixedPart);
       
        oMsg.setContent(oSentMsgParts);
      }

      else {

        if (DebugFile.trace) DebugFile.writeln("BodyPart.setText("+oReplaced.replace('\n',' ')+",UTF-8,html)");

    oMsgBodyPart.setText(oReplaced, "UTF-8", "html");

    oAltParts.addBodyPart(oMsgTextPart);
    oAltParts.addBodyPart(oMsgBodyPart);

        oMsg.setContent(oAltParts);

      }

      oMsg.saveChanges();

      if (DebugFile.trace) DebugFile.writeln("Transport.sendMessage([MimeMessage], MimeMessage.getAllRecipients())");

      oMailTransport.sendMessage(oMsg, oMsg.getAllRecipients());

      // ************************************************************
      // Decrement de count of atoms peding of processing at this job
      iPendingAtoms--;
    }
    catch (MalformedURLException urle) {

      if (DebugFile.trace) DebugFile.writeln("MalformedURLException " + sSrc);
      throw new MessagingException("MalformedURLException " + sSrc);
    }

    if (DebugFile.trace) {
      DebugFile.writeln("End EMailSender.process([Job:" + getStringNull(DB.gu_job, "") + ", Atom:" + String.valueOf(oAtm.getInt(DB.pg_atom)) + "])");
      DebugFile.decIdent();
View Full Code Here

        oOutBox = (DBFolder) oStor.getFolder("outbox");
        oOutBox.open(Folder.READ_WRITE);
        String sMsgId = getParameter("message");

        oDraft = oOutBox.getMessageByGuid(sMsgId);
        if (null==oDraft) throw new MessagingException("DBFolder.getMessageByGuid() Message "+sMsgId+" not found");

        oHeaders = oOutBox.getMessageHeaders(sMsgId);
        if (null==oHeaders) throw new MessagingException("DBFolder.getMessageHeaders() Message "+sMsgId+" not found");
        if (null==oHeaders.get(DB.nm_from))
          aFrom = new InternetAddress[]{new InternetAddress(oHeaders.getProperty(DB.tx_email_from))};
        else
          aFrom = new InternetAddress[]{new InternetAddress(oHeaders.getProperty(DB.tx_email_from),
                                                            oHeaders.getProperty(DB.nm_from))};

        if (DebugFile.trace) DebugFile.writeln("tx_email_reply="+oHeaders.getProperty(DB.tx_email_reply));

        aReply = new InternetAddress[]{new InternetAddress(oHeaders.getProperty(DB.tx_email_reply, oHeaders.getProperty(DB.tx_email_from)))};

        sBody = oDraft.getText();
        if (DebugFile.trace) {
          if (null==sBody)
            DebugFile.writeln("Message body: null");
          else
            DebugFile.writeln("Message body: " + Gadgets.left(sBody.replace('\n',' '), 100));
        }

    oOutBox.close(false);
    oOutBox=null;
    oStor.close();
    oStor=null;

        oConn = getDataBaseBind().getConnection("MimeSender.init.2");
        oConn.setAutoCommit(true);

        oUpdt = oConn.prepareStatement("UPDATE "+DB.k_mime_msgs+" SET "+DB.dt_sent+"=? WHERE "+DB.gu_mimemsg+"=?");
        oUpdt.setTimestamp(1, new Timestamp(new Date().getTime()));
      oUpdt.setString(2, sMsgId);
        oUpdt.executeUpdate();
        oUpdt.close();

    DBSubset oBlck = new DBSubset(DB.k_global_black_list, DBBind.Functions.LOWER+"("+DB.tx_email+")",
                                  DB.id_domain+"=? AND "+DB.gu_workarea+" IN (?,'00000000000000000000000000000000')", 1000);
    int nBlacklisted = oBlck.load(oConn, new Object[]{new Integer(iDomainId), getString(DB.gu_workarea)});

    if (nBlacklisted==0) {
      if (getDataBaseBind().exists(oConn, DB.k_grey_list, "U")) {
        DBSubset oGrey = new DBSubset(DB.k_grey_list+" g", DBBind.Functions.LOWER+"("+DB.tx_email+")", null, 1000);
        int nGreylisted = oGrey.load(oConn);
      if (nGreylisted>0) {
          aBlackList = new String[nGreylisted];
          for (int g=0; g<nGreylisted; g++)
            aBlackList[g] = oGrey.getString(0,g);
      } else {
          aBlackList = null;
      }
      } else {
        aBlackList = null;
      }      
    } else {
      aBlackList = new String[nBlacklisted];
      for (int b=0; b<nBlacklisted; b++)
        aBlackList[b] = oBlck.getString(0,b);
      if (getDataBaseBind().exists(oConn, DB.k_grey_list, "U")) {
        DBSubset oGrey = new DBSubset(DB.k_grey_list+" g", DBBind.Functions.LOWER+"("+DB.tx_email+")",
                                      "NOT EXISTS (SELECT "+DB.tx_email+" FROM "+DB.k_global_black_list+" b WHERE b."+DB.tx_email+"=g."+DB.tx_email+" AND b."+DB.id_domain+"=? AND b."+DB.gu_workarea+" IN (?,'00000000000000000000000000000000'))", 1000);
       
        int nGreylisted = oGrey.load(oConn, new Object[]{new Integer(iDomainId), getString(DB.gu_workarea)});
      if (nGreylisted>0) {
          String[] aBlackGrey = new String[nBlacklisted+nGreylisted];
          for (int b=0; b<nBlacklisted; b++)
            aBlackGrey[b] = oBlck.getString(0,b);
          for (int g=0; g<nGreylisted; g++)
            aBlackGrey[g+nBlacklisted] = oGrey.getString(0,g);
          aBlackList = aBlackGrey;
      }
      }
      Arrays.sort(aBlackList);
    } // fi

        Event.trigger(oConn, iDomainId, "initjob", this, getProperties());
                              
        oConn.close("MimeSender.init.2");
        oConn=null;

      } catch (Exception e) {
        if (DebugFile.trace) {
          DebugFile.writeStackTrace(e);
          DebugFile.write("\n");
          DebugFile.decIdent();
          DebugFile.writeln("End MimeSender.init(" + oAtm.getString(DB.gu_job) + ":" + String.valueOf(oAtm.getInt(DB.pg_atom)) + ") : abnormal process termination");
        }
        try { if (oUpdt!=null) oUpdt.close(); } catch (Exception ignore) {}
        try { if (oConn!=null) if (!oConn.isClosed()) oConn.close("MimeSender.init.2"); } catch (Exception ignore) {}
        if (null!=oOutBox) { try { oOutBox.close(false); oOutBox=null; } catch (Exception ignore) {} }
        if (null!=oStor) { try { oStor.close(); oStor=null; } catch (Exception ignore) {} }
        if (null!=oHndlr) { try { oHndlr.close(); oHndlr=null; } catch (Exception ignore) {} }
        throw new MessagingException(e.getMessage(),e);
      }
      if (DebugFile.trace) {
        DebugFile.decIdent();
        DebugFile.writeln("End MimeSender.init()");
      }
View Full Code Here

TOP

Related Classes of javax.mail.MessagingException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.