예제 #1
0
 public boolean flagsChanged() {
   if (modifiedFlags.getSystemFlags().length > 0 || modifiedFlags.getUserFlags().length > 0) {
     return true;
   } else {
     return false;
   }
 }
예제 #2
0
 @Override
 public int hashCode() {
   int result = (int) (uid ^ (uid >>> 32));
   result = 31 * result + (oldFlags != null ? oldFlags.hashCode() : 0);
   result = 31 * result + (newFlags != null ? newFlags.hashCode() : 0);
   result = 31 * result + (int) (modSeq ^ (modSeq >>> 32));
   return result;
 }
예제 #3
0
 public static boolean flagsChanged(Flags flagsOld, Flags flagsNew) {
   Flags modifiedFlags = new Flags();
   addModifiedSystemFlags(flagsOld, flagsNew, modifiedFlags);
   addModifiedUserFlags(flagsOld, flagsNew, modifiedFlags);
   if (modifiedFlags.getSystemFlags().length > 0 || modifiedFlags.getUserFlags().length > 0) {
     return true;
   } else {
     return false;
   }
 }
  public static void dumpEnvelope(Message m) throws Exception {
    pr("This is the message envelope");
    pr("---------------------------");
    Address[] a;
    // FROM
    if ((a = m.getFrom()) != null) {
      for (int j = 0; j < a.length; j++) pr("FROM: " + a[j].toString());
    }

    // TO
    if ((a = m.getRecipients(Message.RecipientType.TO)) != null) {
      for (int j = 0; j < a.length; j++) pr("TO: " + a[j].toString());
    }

    // SUBJECT
    pr("SUBJECT: " + m.getSubject());

    // DATE
    Date d = m.getSentDate();
    pr("SendDate: " + (d != null ? d.toString() : "UNKNOWN"));

    // FLAGS
    Flags flags = m.getFlags();
    StringBuffer sb = new StringBuffer();
    Flags.Flag[] sf = flags.getSystemFlags(); // get the system flags

    boolean first = true;
    for (int i = 0; i < sf.length; i++) {
      String s;
      Flags.Flag f = sf[i];
      if (f == Flags.Flag.ANSWERED) s = "\\Answered";
      else if (f == Flags.Flag.DELETED) s = "\\Deleted";
      else if (f == Flags.Flag.DRAFT) s = "\\Draft";
      else if (f == Flags.Flag.FLAGGED) s = "\\Flagged";
      else if (f == Flags.Flag.RECENT) s = "\\Recent";
      else if (f == Flags.Flag.SEEN) s = "\\Seen";
      else continue; // skip it
      if (first) first = false;
      else sb.append(' ');
      sb.append(s);
    }

    String[] uf = flags.getUserFlags(); // get the user flag strings
    for (int i = 0; i < uf.length; i++) {
      if (first) first = false;
      else sb.append(' ');
      sb.append(uf[i]);
    }
    pr("FLAGS: " + sb.toString());

    // X-MAILER
    String[] hdrs = m.getHeader("X-Mailer");
    if (hdrs != null) pr("X-Mailer: " + hdrs[0]);
    else pr("X-Mailer NOT available");
  }
예제 #5
0
 private static void addModifiedUserFlags(
     Flags oldFlags, Flags newFlags, String[] userflags, Flags modifiedFlags) {
   for (String userFlag : userflags) {
     if (isChanged(oldFlags, newFlags, userFlag)) {
       modifiedFlags.add(userFlag);
     }
   }
 }
 @Override
 public int hashCode() {
   int ret = 19 * 37;
   ret = ret * 37 + exception.hashCode();
   ret = ret * 37 + internalDate.hashCode();
   ret = ret * 37 + (int) size;
   ret = ret * 37 + (int) uid;
   ret = ret * 37 + flags.hashCode();
   ret = ret * 37 + (int) modSeq;
   return ret;
 }
  public Flags applyToState(boolean isSeen, boolean isAnswered, boolean isFlagged) {
    Flags newStateFlags = new Flags();

    boolean shouldMessageBeFlagged =
        isFlagged().isPresent() && isFlagged().get() || (!isFlagged().isPresent() && isFlagged);
    if (shouldMessageBeFlagged) {
      newStateFlags.add(Flags.Flag.FLAGGED);
    }
    boolean shouldMessageBeMarkAnswered =
        isAnswered().isPresent() && isAnswered().get() || (!isAnswered().isPresent() && isAnswered);
    if (shouldMessageBeMarkAnswered) {
      newStateFlags.add(Flags.Flag.ANSWERED);
    }
    boolean shouldMessageBeMarkSeen =
        isUnread().isPresent() && !isUnread().get() || (!isUnread().isPresent() && isSeen);
    if (shouldMessageBeMarkSeen) {
      newStateFlags.add(Flags.Flag.SEEN);
    }
    return newStateFlags;
  }
예제 #8
0
  private boolean isRead(Message msg, String context) {
    boolean readFlag = false;
    try {
      if (msg.isExpunged()) {
        readFlag = true;
      } else {
        Flags flags = msg.getFlags();
        Flags.Flag[] flag = flags.getSystemFlags();
        for (Flags.Flag aFlag : flag) {
          if (aFlag == Flags.Flag.SEEN) {
            readFlag = true;
            break;
          }
        }
      }
    } catch (MessagingException e) {
      log.debug(String.format("failed to get SEEN FLAG for %s", context), e);
    }

    return readFlag;
  }
예제 #9
0
  @Override
  public boolean equals(Object other) {
    if (this == other) {
      return true;
    }
    if (!(other instanceof UpdatedFlags)) {
      return false;
    }

    UpdatedFlags that = (UpdatedFlags) other;

    if (uid != that.uid) {
      return false;
    }
    if (modSeq != that.modSeq) {
      return false;
    }
    if (oldFlags != null ? !oldFlags.equals(that.oldFlags) : that.oldFlags != null) {
      return false;
    }
    return !(newFlags != null ? !newFlags.equals(that.newFlags) : that.newFlags != null);
  }
예제 #10
0
 @Test
 public void flagsShouldBeSetIntoMessage() throws Exception {
   Flags flags = new Flags();
   flags.add(Flag.ANSWERED);
   flags.add(Flag.FLAGGED);
   flags.add(Flag.DRAFT);
   MetaDataWithContent testMail =
       MetaDataWithContent.builder()
           .uid(MessageUid.of(2))
           .flags(flags)
           .size(0)
           .internalDate(INTERNAL_DATE)
           .content(new ByteArrayInputStream("".getBytes(Charsets.UTF_8)))
           .attachments(ImmutableList.of())
           .mailboxId(MAILBOX_ID)
           .messageId(MessageId.of("test|test|2"))
           .build();
   Message testee = messageFactory.fromMetaDataWithContent(testMail);
   assertThat(testee)
       .extracting(
           Message::isIsUnread, Message::isIsFlagged, Message::isIsAnswered, Message::isIsDraft)
       .containsExactly(true, true, true, true);
 }
  public void testGetFlags() throws Exception {
    NavigableMap<Long, FileInfo> fis =
        imapService.getFolderStatus(
                authenticationService.getCurrentUserName(),
                testImapFolderNodeRef,
                ImapViewMode.ARCHIVE)
            .search;
    if (fis != null && fis.size() > 0) {
      FileInfo messageFileInfo = fis.firstEntry().getValue();

      reauthenticate(USER_NAME, USER_PASSWORD);

      permissionService.setPermission(
          testImapFolderNodeRef, anotherUserName, PermissionService.WRITE, true);

      imapService.setFlags(messageFileInfo, flags, true);

      reauthenticate(anotherUserName, anotherUserName);

      Flags fl = imapService.getFlags(messageFileInfo);
      assertTrue(fl.contains(flags));
    }
  }
 @Override
 public boolean equals(Object obj) {
   if (this == obj) {
     return true;
   }
   if (obj instanceof UnloadedMessageResult) {
     @SuppressWarnings("unchecked")
     UnloadedMessageResult<Id> that = (UnloadedMessageResult<Id>) obj;
     return (size == that.size)
         && (uid == that.uid)
         && (modSeq == that.modSeq)
         && exception.equals(that.exception)
         && internalDate.equals(that.internalDate)
         && flags.equals(that.flags);
   }
   return false;
 }
예제 #13
0
 private static void addModifiedSystemFlags(Flags oldFlags, Flags newFlags, Flags modifiedFlags) {
   if (isChanged(oldFlags, newFlags, Flags.Flag.ANSWERED)) {
     modifiedFlags.add(Flags.Flag.ANSWERED);
   }
   if (isChanged(oldFlags, newFlags, Flags.Flag.DELETED)) {
     modifiedFlags.add(Flags.Flag.DELETED);
   }
   if (isChanged(oldFlags, newFlags, Flags.Flag.DRAFT)) {
     modifiedFlags.add(Flags.Flag.DRAFT);
   }
   if (isChanged(oldFlags, newFlags, Flags.Flag.FLAGGED)) {
     modifiedFlags.add(Flags.Flag.FLAGGED);
   }
   if (isChanged(oldFlags, newFlags, Flags.Flag.RECENT)) {
     modifiedFlags.add(Flags.Flag.RECENT);
   }
   if (isChanged(oldFlags, newFlags, Flags.Flag.SEEN)) {
     modifiedFlags.add(Flags.Flag.SEEN);
   }
 }
예제 #14
0
 private static void addModifiedUserFlags(Flags oldFlags, Flags newFlags, Flags modifiedFlags) {
   addModifiedUserFlags(oldFlags, newFlags, oldFlags.getUserFlags(), modifiedFlags);
   addModifiedUserFlags(oldFlags, newFlags, newFlags.getUserFlags(), modifiedFlags);
 }
예제 #15
0
  public static void dumpPart(Part p) throws Exception {
    if (p instanceof Message) {
      Message m = (Message) p;
      Address[] a;
      // FROM
      if ((a = m.getFrom()) != null) {
        for (int j = 0; j < a.length; j++) System.out.println("FROM: " + a[j].toString());
      }

      // TO
      if ((a = m.getRecipients(Message.RecipientType.TO)) != null) {
        for (int j = 0; j < a.length; j++) System.out.println("TO: " + a[j].toString());
      }

      // SUBJECT
      System.out.println("SUBJECT: " + m.getSubject());

      // DATE
      Date d = m.getSentDate();
      System.out.println("SendDate: " + (d != null ? d.toLocaleString() : "UNKNOWN"));

      // FLAGS:
      Flags flags = m.getFlags();
      StringBuffer sb = new StringBuffer();
      Flags.Flag[] sf = flags.getSystemFlags(); // get the system flags

      boolean first = true;
      for (int i = 0; i < sf.length; i++) {
        String s;
        Flags.Flag f = sf[i];
        if (f == Flags.Flag.ANSWERED) s = "\\Answered";
        else if (f == Flags.Flag.DELETED) s = "\\Deleted";
        else if (f == Flags.Flag.DRAFT) s = "\\Draft";
        else if (f == Flags.Flag.FLAGGED) s = "\\Flagged";
        else if (f == Flags.Flag.RECENT) s = "\\Recent";
        else if (f == Flags.Flag.SEEN) s = "\\Seen";
        else continue; // skip it
        if (first) first = false;
        else sb.append(' ');
        sb.append(s);
      }

      String[] uf = flags.getUserFlags(); // get the user flag strings
      for (int i = 0; i < uf.length; i++) {
        if (first) first = false;
        else sb.append(' ');
        sb.append(uf[i]);
      }
      System.out.println("FLAGS = " + sb.toString());
    }

    System.out.println("CONTENT-TYPE: " + p.getContentType());

    /* Dump input stream
    InputStream is = ((MimeMessage)m).getInputStream();
    int c;
    while ((c = is.read()) != -1)
        System.out.write(c);
    */

    Object o = p.getContent();
    if (o instanceof String) {
      System.out.println("This is a String");
      System.out.println((String) o);
    } else if (o instanceof Multipart) {
      System.out.println("This is a Multipart");
      Multipart mp = (Multipart) o;
      int count = mp.getCount();
      for (int i = 0; i < count; i++) dumpPart(mp.getBodyPart(i));
    } else if (o instanceof InputStream) {
      System.out.println("This is just an input stream");
      InputStream is = (InputStream) o;
      int c;
      while ((c = is.read()) != -1) System.out.write(c);
    }
  }
예제 #16
0
 /**
  * Gets an iterator for the users flags changed.
  *
  * @return <code>String</code> <code>Iterator</code>, not null
  */
 public Iterator<String> userFlagIterator() {
   return Arrays.asList(modifiedFlags.getUserFlags()).iterator();
 }
  @Override
  public void setUp() throws Exception {
    ServiceRegistry serviceRegistry = (ServiceRegistry) ctx.getBean("ServiceRegistry");
    transactionService = serviceRegistry.getTransactionService();
    nodeService = serviceRegistry.getNodeService();
    importerService = serviceRegistry.getImporterService();
    personService = serviceRegistry.getPersonService();
    authenticationService = serviceRegistry.getAuthenticationService();
    permissionService = serviceRegistry.getPermissionService();
    imapService = serviceRegistry.getImapService();
    searchService = serviceRegistry.getSearchService();
    namespaceService = serviceRegistry.getNamespaceService();
    fileFolderService = serviceRegistry.getFileFolderService();

    flags = new Flags();
    flags.add(Flags.Flag.SEEN);
    flags.add(Flags.Flag.FLAGGED);
    flags.add(Flags.Flag.ANSWERED);
    flags.add(Flags.Flag.DELETED);

    // start the transaction
    txn = transactionService.getUserTransaction();
    txn.begin();
    authenticationService.authenticate(USER_NAME, USER_PASSWORD.toCharArray());

    // downgrade integrity
    IntegrityChecker.setWarnInTransaction();

    anotherUserName = "******" + System.currentTimeMillis();

    PropertyMap testUser = new PropertyMap();
    testUser.put(ContentModel.PROP_USERNAME, anotherUserName);
    testUser.put(ContentModel.PROP_FIRSTNAME, anotherUserName);
    testUser.put(ContentModel.PROP_LASTNAME, anotherUserName);
    testUser.put(ContentModel.PROP_EMAIL, anotherUserName + "@alfresco.com");
    testUser.put(ContentModel.PROP_JOBTITLE, "jobTitle");

    personService.createPerson(testUser);

    // create the ACEGI Authentication instance for the new user
    authenticationService.createAuthentication(anotherUserName, anotherUserName.toCharArray());

    user =
        new AlfrescoImapUser(anotherUserName + "@alfresco.com", anotherUserName, anotherUserName);

    String storePath = "workspace://SpacesStore";
    String companyHomePathInStore = "/app:company_home";

    StoreRef storeRef = new StoreRef(storePath);

    NodeRef storeRootNodeRef = nodeService.getRootNode(storeRef);

    List<NodeRef> nodeRefs =
        searchService.selectNodes(
            storeRootNodeRef, companyHomePathInStore, null, namespaceService, false);
    NodeRef companyHomeNodeRef = nodeRefs.get(0);

    ChildApplicationContextFactory imap = (ChildApplicationContextFactory) ctx.getBean("imap");
    ApplicationContext imapCtx = imap.getApplicationContext();
    ImapServiceImpl imapServiceImpl = (ImapServiceImpl) imapCtx.getBean("imapService");

    // Creating IMAP test folder for IMAP root
    LinkedList<String> folders = new LinkedList<String>();
    folders.add(TEST_IMAP_FOLDER_NAME);
    FileFolderServiceImpl.makeFolders(
        fileFolderService, companyHomeNodeRef, folders, ContentModel.TYPE_FOLDER);

    // Setting IMAP root
    RepositoryFolderConfigBean imapHome = new RepositoryFolderConfigBean();
    imapHome.setStore(storePath);
    imapHome.setRootPath(companyHomePathInStore);
    imapHome.setFolderPath(TEST_IMAP_FOLDER_NAME);
    imapServiceImpl.setImapHome(imapHome);

    // Starting IMAP
    imapServiceImpl.startup();

    nodeRefs =
        searchService.selectNodes(
            storeRootNodeRef,
            companyHomePathInStore
                + "/"
                + NamespaceService.CONTENT_MODEL_PREFIX
                + ":"
                + TEST_IMAP_FOLDER_NAME,
            null,
            namespaceService,
            false);
    testImapFolderNodeRef = nodeRefs.get(0);

    /*
     * Importing test folders:
     *
     * Test folder contains: "___-___folder_a"
     *
     * "___-___folder_a" contains: "___-___folder_a_a",
     *                             "___-___file_a",
     *                             "Message_485.eml" (this is IMAP Message)
     *
     * "___-___folder_a_a" contains: "____-____file_a_a"
     *
     */
    importInternal("imap/imapservice_test_folder_a.acp", testImapFolderNodeRef);

    reauthenticate(anotherUserName, anotherUserName);
  }
예제 #18
0
 private static boolean isChanged(Flags original, Flags updated, String userFlag) {
   return original != null
       && updated != null
       && (original.contains(userFlag) ^ updated.contains(userFlag));
 }
예제 #19
0
 /**
  * Gets an iterator for the system flags changed.
  *
  * @return <code>Flags.Flag</code> <code>Iterator</code>, not null
  */
 public Iterator<Flags.Flag> systemFlagIterator() {
   return Arrays.asList(modifiedFlags.getSystemFlags()).iterator();
 }