public ScrubResource() { DAOFactory dao = DAOFactory.getDAOFactory(); messageDAO = dao.getMessageDAO(); labelDAO = dao.getLabelDAO(); }
public DeliveryAgentFactory() { DAOFactory dao = DAOFactory.getDAOFactory(); messageDAO = dao.getMessageDAO(); }
public MessageModification build() { return new MessageModification(this); } }
if(ReservedLabels.contains(labelId)) { throw new IllegalLabelException("This is reserved label and can't be modified"); MessageDAO messageDAO = new CassandraMessageDAO(keyspace); messageIds = LabelIndexPersistence.get(mailbox.getId(), labelId, null, BatchConstants.BATCH_READS, false); messageDAO.modify(mailbox, messageIds, new MessageModification.Builder().removeLabels(labelIds).build()); LabelIndexPersistence.deleteIndex(m, mailbox.getId(), labelId); LabelCounterPersistence.delete(m, mailbox.getId(), labelId); AccountPersistence.deleteLabel(m, mailbox.getId(), labelId);
@QueryParam("removemarker") Set<Marker> removeMarkers) Mailbox mailbox = new Mailbox(user, domain); MessageModification modification = new MessageModification.Builder() .addLabels(addLabels).removeLabels(removeLabels) .addMarkers(addMarkers).removeMarkers(removeMarkers) .build(); messageDAO.modify(mailbox, messageId, modification); } catch (IllegalLabelException ile) { throw new BadRequestException(ile.getMessage()); } catch (Exception e) { logger.warn("Internal Server Error: ", e);
@Override public void remove(String... uids) throws IOException { logger.debug("POP3: Removing messages {} from {}", uids, mailbox); Set<Integer> labels = new HashSet<Integer>(1); labels.add(ReservedLabels.POP3.getId()); List<UUID> uuids = new ArrayList<UUID>(uids.length); for (String uid : uids) { uuids.add(Base64UUIDUtils.decode(uid)); } dao.modify(mailbox, uuids, new MessageModification.Builder().removeLabels(labels).build()); }
@Override public void update(Mailbox mailbox, Label label) throws IOException { // get all existing labels LabelMap existingLabels = AccountPersistence.getLabels(mailbox.getId()); // validate only if name is changed (skips letter case changes) if (label.getName() != null && !existingLabels.containsName(label.getName())) { LabelUtils.validateLabelName(label.getName(), existingLabels); } // check if label id reserved if (ReservedLabels.contains(label.getId())) { throw new ExistingLabelException("This is reserved label and can't be modified"); } // check if label id exists if (!existingLabels.containsId(label.getId())) { throw new IllegalLabelException("Label does not exist"); } // begin batch operation Mutator<String> mutator = createMutator(keyspace, strSe); // set new name AccountPersistence.putLabel(mutator, mailbox.getId(), label); // commit batch operation mutator.execute(); }
/** * Scrub mailbox and recalculate counters * * @param account * @return */ @POST @Path("counters") @Produces(MediaType.APPLICATION_JSON) public Response scrubCounters( @PathParam("user") final String user, @PathParam("domain") final String domain) { Mailbox mailbox = new Mailbox(user, domain); LabelMap calculatedCounters = messageDAO.scrub(mailbox, false); labelDAO.setCounters(mailbox, calculatedCounters); return Response.noContent().build(); }
throw new IllegalLabelException("Label name exceeds maximum allowed length"); if (existingLabels.containsName(labelName)) { throw new ExistingLabelException("Label with this name already exists"); for (Label l : ReservedLabels.getAll()) if (labelName.startsWith(l.getName() + LabelConstants.NESTED_LABEL_SEPARATOR.toString())) throw new IllegalLabelException("Netsted labels are not allowed under reserved labels"); throw new IllegalLabelException("Illegal use of nested label separator");
/** * Delete label * * @param account * @param labelId * @return */ @DELETE @Path("{id}") @Produces(MediaType.APPLICATION_JSON) public Response deleteLabel( @PathParam("user") String user, @PathParam("domain") String domain, @PathParam("id") Integer labelId) { Mailbox mailbox = new Mailbox(user, domain); try { labelDAO.delete(mailbox, labelId); } catch (IllegalLabelException ile) { throw new BadRequestException(ile.getMessage()); } catch (Exception e) { logger.error("Deleting label failed", e); throw new WebApplicationException(Response.Status.INTERNAL_SERVER_ERROR); } return Response.noContent().build(); }
@Override public InputStream getMessage(String uid) throws IOException { UUID uuid = Base64UUIDUtils.decode(uid); logger.debug("POP3: Get message {}/{} [{}]", mailbox, uuid, uid); try { InputStream is = dao.getRaw(mailbox, uuid).getUncompressedInputStream(); return new CRLFInputStream(is); } catch (Exception e) { logger.error("Error occured while retreiving POP3 message " + mailbox + "/" + uuid + " :", e); throw new IOException("Unable to read message"); } }
public AccountResource() { DAOFactory dao = DAOFactory.getDAOFactory(); accountDAO = dao.getAccountDAO(); }
/** * Generates new label ID which does not exist in the given list * * @param existingLabels * @return */ public static int getNewLabelId(Set<Integer> existingLabels) { // generate new unique label id int labelId = LabelUtils.getNewLabelId(); int attempts = 1; while (existingLabels.contains(labelId)) { if (attempts > MAX_NEW_LABEL_ID_ATTEMPTS) { // too many attempts to get new random id! too many labels? throw new IllegalLabelException("Too many labels"); } labelId = LabelUtils.getNewLabelId(); attempts++; } return labelId; }
@Override public void run() { try { accountDAO.delete(mailbox); } catch (IOException e) { logger.info("Account deletion failed: ", e); } } };
public LabelResource() { DAOFactory dao = DAOFactory.getDAOFactory(); messageDAO = dao.getMessageDAO(); labelDAO = dao.getLabelDAO(); }
public MailboxHandlerFactory() { DAOFactory dao = DAOFactory.getDAOFactory(); messageDAO = dao.getMessageDAO(); }
/** * Scrub mailbox, rebuild indexes and recalculate counters * * @param account * @return */ @POST @Path("indexes") @Produces(MediaType.APPLICATION_JSON) public Response scrubIndexes( @PathParam("user") final String user, @PathParam("domain") final String domain) { Mailbox mailbox = new Mailbox(user, domain); LabelMap calculatedCounters = messageDAO.scrub(mailbox, true); labelDAO.setCounters(mailbox, calculatedCounters); return Response.noContent().build(); }
public MailboxResource() { DAOFactory dao = DAOFactory.getDAOFactory(); labelDAO = dao.getLabelDAO(); messageDAO = dao.getMessageDAO(); }
public MessageResource() { DAOFactory dao = DAOFactory.getDAOFactory(); messageDAO = dao.getMessageDAO(); }
public SingleMessageResource() { DAOFactory dao = DAOFactory.getDAOFactory(); messageDAO = dao.getMessageDAO(); }