Example #1
0
 /**
  * Method writeMetaFiles. This uses the MailStoreFileManger API to store files remotely.
  *
  * @param message
  */
 private boolean writeMetaFiles(IMessageContext message) {
   String metaContents = createMetaContents(message);
   String metaFileName = new File(message.getStoreFileSubPath()).getName();
   Collection<MailStoreFileManager.MetaMessageDescriptor> msgs =
       new ArrayList<MailStoreFileManager.MetaMessageDescriptor>();
   if (!CollectionsUtils.isNullOrEmpty(message.getResolvedRecipients())) {
     for (ReplicatedRecipient rr : message.getResolvedRecipients()) {
       msgs.add(
           new MailStoreFileManager.MetaMessageDescriptor(
               message.getInternalId(),
               rr.getMaildir(),
               metaFileName,
               message.getEnvelope().getSentDate(),
               message.getEnvelope().getReceivedDate(),
               false,
               rr.getState().toInt()));
     }
   }
   if (message.getResolvedSender() != null) {
     ReplicatedRecipient rr = message.getResolvedSender();
     msgs.add(
         new MailStoreFileManager.MetaMessageDescriptor(
             message.getInternalId(),
             rr.getMaildir(),
             metaFileName,
             message.getEnvelope().getSentDate(),
             message.getEnvelope().getReceivedDate(),
             true,
             rr.getState().toInt()));
   }
   IMailStoreFileManager imsfm = ManagementContainer.getInstance().getMailStoreFileManager();
   if (imsfm.storeMetaMessage(msgs, metaContents)) {
     m_importer.audit(message, getName(), metaFileName);
     return true;
   } else {
     m_importer.getStatComponent().addToValue(STAT_META_STORE_FAILURES, 1);
     m_importer.consumerImportFailed(message, true);
     return false;
   }
 }
Example #2
0
  /**
   * Method writeMetaFile. This uses NFS to store files remotely. Not used in production, mmfs is
   * used instead.
   *
   * @param recpt
   * @param message
   * @param isSender
   * @param metaFileName
   * @param metaContents
   */
  private boolean writeMetaFile(
      ReplicatedRecipient recpt,
      IMessageContext message,
      boolean isSender,
      String metaFileName,
      String metaContents) {
    Envelope env = message.getEnvelope();
    ActiveMailboxFolder folder =
        ActiveMailboxFolder.getFolder(recpt.getMaildir(), env.getSentDate(), isSender);
    folder.initialize();
    File metaMsgDir;
    CustomerState userState = recpt.getState();
    if (userState == CustomerState.ACTIVE || userState == CustomerState.TEST) {
      metaMsgDir = folder.getMeta();
    } else {
      metaMsgDir = folder.getCur();
    }
    if (!metaMsgDir.exists()) {
      m_importer.auditError(
          message, getName(), metaMsgDir + " doesn't exist while trying to create meta-file");
    }
    File metaMsgFile = new File(metaMsgDir, metaFileName);

    BufferedWriter out = null;
    try {
      try {
        out = new BufferedWriter(new FileWriter(metaMsgFile));
        out.write(metaContents);
      } finally {
        if (out != null) out.close();
      }
      // preserve arrival timestamp
      metaMsgFile.setLastModified(env.getReceivedDate().getTime());
      m_importer.audit(message, getName(), metaMsgFile.getAbsolutePath());
    } catch (IOException ex) {
      m_logger.error("Error creating file " + metaMsgFile.getPath(), ex);
      return false;
    }
    return true;
  }