Package javax.mail

Examples of javax.mail.MessagingException


      oStmt = getConnection().prepareStatement(sSQL+"?",ResultSet.TYPE_FORWARD_ONLY,ResultSet.CONCUR_READ_ONLY);
      oStmt.setString(1, oSrcMsg.getMessageGuid());
      oRSet = oStmt.executeQuery();
      if (!oRSet.next())
        throw new MessagingException("DBFolder.copyMessage() could not find source message " + oSrcMsg.getMessageGuid());
      oPg = oRSet.getBigDecimal(1);
      sId = oRSet.getString(2);
      oPos= oRSet.getBigDecimal(3);
      iLen= oRSet.getInt(4);
      oRSet.close();
      oRSet=null;
      oStmt.close();
      oStmt=null;
    }
    catch (SQLException sqle) {
      try { if (oRSet!=null) oRSet.close(); } catch (Exception ignore) {}
      try { if (oStmt!=null) oStmt.close(); } catch (Exception ignore) {}
      try { getConnection().rollback(); } catch (Exception ignore) {}
      if (DebugFile.trace) {
        DebugFile.writeln("DBFolder.copyMessage() SQLException " + sqle.getMessage());
        DebugFile.decIdent();
      }
      throw new MessagingException("DBFolder.copyMessage() SQLException " + sqle.getMessage(), sqle);
    }

    if (null==oPg) throw new MessagingException("DBFolder.copyMessage() Source Message not found");

    DBFolder oSrcFldr = (DBFolder) oSrcMsg.getFolder();

    MboxFile oMboxSrc = null;
    MimeMessage oMimeSrc;
    String sNewGuid = null;
    try {
      if ((oSrcFldr.mode&MODE_MBOX)!=0) {
        if (DebugFile.trace) DebugFile.writeln("new MboxFile(" + oSrcFldr.getFile() + ", MboxFile.READ_ONLY)");
        oMboxSrc = new MboxFile(oSrcFldr.getFile(), MboxFile.READ_ONLY);
        InputStream oInStrm = oMboxSrc.getMessageAsStream(oPos.longValue(), iLen);
        oMimeSrc = new MimeMessage(Session.getDefaultInstance(new Properties()), oInStrm);
        oInStrm.close();
        oMboxSrc.close();
        oMboxSrc=null;

        String sId2 = oMimeSrc.getMessageID();
        if ((sId!=null) && (sId2!=null)) {
          if (!sId.trim().equals(sId2.trim())) {
            throw new MessagingException("MessageID "+ sId + " at database does not match MessageID " + oMimeSrc.getMessageID() + " at MBOX file " + oSrcFldr.getFile().getName() + " for message index " + oPg.toString());
          }
        } // fi (sId!=null && sId2!=null)

        appendMessage(oMimeSrc);
      }
      else {
        ByteArrayOutputStream oByOutStrm = new ByteArrayOutputStream();
        oSrcMsg.writeTo(oByOutStrm);
        ByteArrayInputStream oByInStrm = new ByteArrayInputStream(oByOutStrm.toByteArray());
        oByOutStrm.close();
        oMimeSrc = new MimeMessage(Session.getDefaultInstance(new Properties()), oByInStrm);
        oByInStrm.close();
        appendMessage(oMimeSrc);
      }
    }
    catch (Exception e) {
      if (oMboxSrc!=null)  { try { oMboxSrc.close()} catch (Exception ignore) {} }
      try { oSrcFldr.getConnection().rollback(); } catch (Exception ignore) {}
      if (DebugFile.trace) {
        DebugFile.writeln("DBFolder.copyMessage() " + e.getClass().getName() + " "+ e.getMessage());
        DebugFile.writeStackTrace(e);
        DebugFile.writeln("");
        DebugFile.decIdent();
      }
      throw new MessagingException(e.getMessage(), e);
    }

    if (DebugFile.trace) {
      DebugFile.decIdent();
      DebugFile.writeln("End DBFolder.copyMessage() : " + sNewGuid);
View Full Code Here


            sSrcCatg = oSrcCatg.getStringNull(DB.gu_category,null);
          }
        }
        if (null==sSrcCatg) {
          DebugFile.decIdent();
          throw new MessagingException("Could not find folder for source message");
        }
        if (DebugFile.trace) DebugFile.writeln("Connection.prepareStatement(UPDATE "+DB.k_categories+" SET "+DB.len_size+"="+DB.len_size+"-"+String.valueOf(iLen)+" WHERE "+DB.gu_category+"='"+sSrcCatg+"')");
      }
      sSrcCatg = ((DBFolder)(oSrcMsg.getFolder())).getCategory().getString(DB.gu_category);
      oStmt = oConn.prepareStatement("UPDATE "+DB.k_categories+" SET "+DB.len_size+"="+DB.len_size+"-"+String.valueOf(iLen)+" WHERE "+DB.gu_category+"=?");
      oStmt.setString(1, sSrcCatg);
      oStmt.executeUpdate();
      oStmt.close();
      oStmt=null;
      if (DebugFile.trace) DebugFile.writeln("Connection.prepareStatement(UPDATE "+DB.k_categories+" SET "+DB.len_size+"="+DB.len_size+"+"+String.valueOf(iLen)+" WHERE "+DB.gu_category+"='"+getCategory().getStringNull(DB.gu_category,"null")+"')");
      oStmt = oConn.prepareStatement("UPDATE "+DB.k_categories+" SET "+DB.len_size+"="+DB.len_size+"+"+String.valueOf(iLen)+" WHERE "+DB.gu_category+"=?");
      oStmt.setString(1, getCategory().getString(DB.gu_category));
      oStmt.executeUpdate();
      oStmt.close();
      oStmt=null;

      if (DebugFile.trace) DebugFile.writeln("JDCConnection.commit()");

      oConn.commit();
    }
    catch (SQLException sqle) {
      if (DebugFile.trace) {
        DebugFile.writeln("SQLException "+sqle.getMessage());
        DebugFile.writeStackTrace(sqle);
      }
      if (null!=oRSet) { try {oRSet.close(); } catch (Exception ignore) {} }
      if (null!=oStmt) { try {oStmt.close(); } catch (Exception ignore) {} }
      if (null!=oConn) { try {oConn.rollback(); } catch (Exception ignore) {} }
      if (!bWasOpen) { try { close(false); } catch (Exception ignore) {} }
      throw new MessagingException(sqle.getMessage(), sqle);
    }

    if (null==oPg) {
      if (!bWasOpen) { try { close(false); } catch (Exception ignore) {} }
      throw new MessagingException("Source message "+oSrcMsg.getMessageGuid()+" not found");
    }

    // If position is null then message is only at the database and not also at
    // an MBOX file so skip moving from one MBOX file to another
    if (null!=oPos) {

      DBFolder oSrcFldr = (DBFolder) oSrcMsg.getFolder();

      MboxFile oMboxSrc = null, oMboxThis = null;
     
      try {
        if (DebugFile.trace) DebugFile.writeln("new MboxFile("+oSrcFldr.getFile().getPath()+", MboxFile.READ_WRITE)");
         
        oMboxSrc = new MboxFile(oSrcFldr.getFile(), MboxFile.READ_WRITE);

        if (DebugFile.trace) DebugFile.writeln("new MboxFile("+getFile().getPath()+", MboxFile.READ_WRITE)");

        oMboxThis = new MboxFile(getFile(), MboxFile.READ_WRITE);

        if (DebugFile.trace) DebugFile.writeln("MboxFile.appendMessage([MboxFile], "+oPos.toString()+","+String.valueOf(iLen)+")");

        oMboxThis.appendMessage(oMboxSrc, oPos.longValue(), iLen);

        oMboxThis.close();
        oMboxThis=null;

        oMboxSrc.purge (new int[]{oPg.intValue()});

        oMboxSrc.close();
        oMboxSrc=null;
      }
      catch (Exception e) {
        if (DebugFile.trace) {
          DebugFile.writeln(e.getClass()+" "+e.getMessage());
          DebugFile.writeStackTrace(e);
        }
        if (oMboxThis!=null) { try { oMboxThis.close(); } catch (Exception ignore) {} }
        if (oMboxSrc!=null)  { try { oMboxSrc.close()} catch (Exception ignore) {} }
        if (!bWasOpen) { try { close(false); } catch (Exception ignore) {} }
        throw new MessagingException(e.getMessage(), e);
      }
    } // fi (oPos)

    try {
      oConn = getConnection();
      oConn.setAutoCommit(false);

      BigDecimal dNext = getNextMessage();

      if (DebugFile.trace)
        DebugFile.writeln("JDCConnection.prepareStatement(UPDATE "+DB.k_mime_msgs+" SET "+DB.gu_category+"='"+sCatGuid+"',"+DB.pg_message+"="+dNext.toString()+" WHERE "+DB.gu_mimemsg+"='"+oSrcMsg.getMessageGuid()+"')");

      oStmt = oConn.prepareStatement("UPDATE "+DB.k_mime_msgs+" SET "+DB.gu_category+"=?,"+DB.pg_message+"=? WHERE "+DB.gu_mimemsg+"=?");
      oStmt.setString(1, sCatGuid);
      oStmt.setBigDecimal(2, dNext);
      oStmt.setString(3, oSrcMsg.getMessageGuid());
      int iAffected = oStmt.executeUpdate();     
      if (DebugFile.trace) DebugFile.writeln(String.valueOf(iAffected)+" updated rows");     
      oStmt.close();
      oStmt=null;

      if (DebugFile.trace) DebugFile.writeln("JDCConnection.commit()");

      oConn.commit();
    }
    catch (SQLException sqle) {

      if (DebugFile.trace) {
        DebugFile.writeln("MessagingException "+sqle.getMessage());
        DebugFile.writeStackTrace(sqle);
      }

      if (null!=oStmt) { try { oStmt.close(); } catch (Exception ignore) {}}
      if (null!=oConn) { try { oConn.rollback(); } catch (Exception ignore) {} }
      if (!bWasOpen) { try { close(false); } catch (Exception ignore) {} }

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

    if (!bWasOpen) close(false);

    if (DebugFile.trace) {
View Full Code Here

    try {
      String sGuid = ((DBStore) getStore()).getUser().getMailFolder(getConnection(),
                     Category.makeName(getConnection(), sFolderName));
      oCatg = new Category(getConnection(), sGuid);
    } catch (SQLException sqle) {
      throw new MessagingException(sqle.getMessage(), sqle);
    }
    return true;
  }
View Full Code Here

      DebugFile.incIdent();
    }

    if ((0==(mode&READ_ONLY)) && (0==(mode&READ_WRITE))) {
      if (DebugFile.trace) DebugFile.decIdent();
      throw new MessagingException("Folder must be opened in either READ_ONLY or READ_WRITE mode");
    }
    else if (ALL_OPTIONS!=(mode|ALL_OPTIONS)) {
      if (DebugFile.trace) DebugFile.decIdent();
      throw new MessagingException("Invalid DBFolder open() option mode");
    } else {
      if ((0==(mode&MODE_MBOX)) && (0==(mode&MODE_BLOB)))
        mode |= MODE_MBOX;

      iOpenMode = mode;
      JDCConnection oConn = null;
      try {
        oConn = getConnection();
      } catch (SQLException sqle) {
        throw new MessagingException(sqle.getMessage(), sqle);
      }
      if ((iOpenMode&MODE_MBOX)!=0) {
        String sFolderUrl;
        try {
          sFolderUrl = Gadgets.chomp(getStore().getURLName().getFile(), File.separator) + oCatg.getPath(oConn);
          if (DebugFile.trace) DebugFile.writeln("mail folder directory is " + sFolderUrl);
          if (sFolderUrl.startsWith("file://"))
            sFolderDir = sFolderUrl.substring(7);
          else
            sFolderDir = sFolderUrl;
          if (File.separator.equals("\\")) sFolderDir = sFolderDir.replace('/','\\');
        } catch (SQLException sqle) {
          iOpenMode = 0;
          oConn = null;
          if (DebugFile.trace) DebugFile.decIdent();
          throw new MessagingException (sqle.getMessage(), sqle);
        }
        try {
          File oDir = new File (sFolderDir);
          if (!oDir.exists()) {
            FileSystem oFS = new FileSystem();
            oFS.mkdirs(sFolderUrl);
          }
        } catch (IOException ioe) {
          iOpenMode = 0;
          oConn = null;
          if (DebugFile.trace) DebugFile.decIdent();
          throw new MessagingException (ioe.getMessage(), ioe);
        } catch (SecurityException se) {
          iOpenMode = 0;
          oConn = null;
          if (DebugFile.trace) DebugFile.decIdent();
          throw new MessagingException (se.getMessage(), se);
        } catch (Exception je) {
          iOpenMode = 0;
          oConn = null;
          if (DebugFile.trace) DebugFile.decIdent();
          throw new MessagingException (je.getMessage(), je);
        }

        // Create a ProductLocation pointing to the MBOX file if it does not exist
        try {
          oConn = getConnection();
        } catch (SQLException sqle) {
          throw new MessagingException(sqle.getMessage(), sqle);
        }
        PreparedStatement oStmt = null;
        ResultSet oRSet = null;
        boolean bHasFilePointer;
        try {
          oStmt = oConn.prepareStatement("SELECT NULL FROM "+DB.k_x_cat_objs+ " WHERE "+DB.gu_category+"=? AND "+DB.id_class+"=15",
                                         ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
          oStmt.setString(1, getCategory().getString(DB.gu_category));
          oRSet = oStmt.executeQuery();
          bHasFilePointer = oRSet.next();
          oRSet.close();
          oRSet = null;
          oStmt.close();
          oStmt = null;

          if (!bHasFilePointer) {
            oConn.setAutoCommit(false);

            Product oProd = new Product();
            oProd.put(DB.gu_owner, oCatg.getString(DB.gu_owner));
            oProd.put(DB.nm_product, oCatg.getString(DB.nm_category));
            oProd.store(oConn);

            ProductLocation oLoca = new ProductLocation();
            oLoca.put(DB.gu_product, oProd.getString(DB.gu_product));
            oLoca.put(DB.gu_owner, oCatg.getString(DB.gu_owner));
            oLoca.put(DB.pg_prod_locat, 1);
            oLoca.put(DB.id_cont_type, 1);
            oLoca.put(DB.id_prod_type, "MBOX");
            oLoca.put(DB.len_file, 0);
            oLoca.put(DB.xprotocol, "file://");
            oLoca.put(DB.xhost, "localhost");
            oLoca.put(DB.xpath, Gadgets.chomp(sFolderDir, File.separator));
            oLoca.put(DB.xfile, oCatg.getString(DB.nm_category)+".mbox");
            oLoca.put(DB.xoriginalfile, oCatg.getString(DB.nm_category)+".mbox");
            oLoca.store(oConn);

            oStmt = oConn.prepareStatement("INSERT INTO "+DB.k_x_cat_objs+" ("+DB.gu_category+","+DB.gu_object+","+DB.id_class+") VALUES (?,?,15)");
            oStmt.setString(1, oCatg.getString(DB.gu_category));
            oStmt.setString(2, oProd.getString(DB.gu_product));
            oStmt.executeUpdate();
            oStmt.close();
            oStmt = null;

            oConn.commit();
          }
        }
        catch (SQLException sqle) {
          if (DebugFile.trace) {
            DebugFile.writeln("SQLException " + sqle.getMessage());
            DebugFile.decIdent();
          }
          if (oStmt!=null) { try { oStmt.close(); } catch (SQLException ignore) {} }
          if (oConn!=null) { try { oConn.rollback(); } catch (SQLException ignore) {} }
          throw new MessagingException(sqle.getMessage(), sqle);
        }
      }
      else {
        sFolderDir = null;
      }
View Full Code Here

  public boolean delete(boolean recurse) throws MessagingException {
    try {
      wipe();
      return oCatg.delete(getConnection());
    } catch (SQLException sqle) {
      throw new MessagingException(sqle.getMessage(), sqle);
    }
  }
View Full Code Here

      oUpdt=null;
      getConnection().commit();
    } catch (SQLException sqle) {
      try { if (null!=oUpdt) oUpdt.close(); } catch (SQLException ignore) {}
      try { getConnection().rollback(); } catch (SQLException ignore) {}
      throw new MessagingException(sqle.getMessage(), sqle);
    }
    return true;
  } // renameTo
View Full Code Here

        FileSystem oFS = new FileSystem();
        try {
          oFS.mkdirs(url.getFile());
        } catch (Exception e) {
          if (DebugFile.trace) DebugFile.writeln(e.getClass().getName() + " " + e.getMessage());
          throw new MessagingException(e.getMessage(), e);
        }
      }
    }

    oConn = null;
View Full Code Here

      DebugFile.incIdent();
    }

    if (oConn!=null || isConnected()) {
      if (DebugFile.trace) DebugFile.decIdent();
      throw new MessagingException("DBStore is already connected");
    }

    String dburl = Environment.getProfileVar(host, "dburl");
    String dbusr = Environment.getProfileVar(host, "dbuser");
    String dbpwd = Environment.getProfileVar(host, "dbpassword");
    String schema = Environment.getProfileVar(host, "schema", "");

    try {
      if (DebugFile.trace)
        DebugFile.writeln("DriverManager.getConnection("+dburl+", "+dbusr+", ...)");

      if (schema.length()>0)
        oConn = new JDCConnection(DriverManager.getConnection(dburl, dbusr, dbpwd), null, schema);
      else
        oConn = new JDCConnection(DriverManager.getConnection(dburl, dbusr, dbpwd), null);

      short iAuth = ACL.autenticate(oConn, user, password, ACL.PWD_CLEAR_TEXT);

      if (iAuth<0) {
        oConn.close();
        oConn = null;
        if (DebugFile.trace) DebugFile.decIdent();
        throw new AuthenticationFailedException(ACL.getErrorMessage(iAuth) + " (" + user + ")");
      }
      else {
        oUser = new ACLUser(oConn, user);
        setConnected(true);
        oConn.setAutoCommit(false);
      }
    }
    catch (SQLException sqle) {
      if (DebugFile.trace) DebugFile.decIdent();
      throw new MessagingException(sqle.getMessage(), sqle);
    }

    if (DebugFile.trace) {
      try { if (oConn!=null) DebugFile.writeln("Connection process id. is "+oConn.pid()); } catch (Exception ignore ) { }
      DebugFile.decIdent();
View Full Code Here

        if (!oConn.isClosed()) {
          oConn.commit();
        }
      }
    } catch (Exception xcpt) {
      throw new MessagingException(xcpt.getMessage(), xcpt);
    }
  }
View Full Code Here

        oConn=null;
        oUser=null;
        setConnected(false);
      }
      catch (SQLException sqle) {
        throw new MessagingException(sqle.getMessage(), sqle);
      }
    }
    else {
      throw new StoreClosedException(this, "Store already closed");
    }
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.