/** * Get quota (maximum) bytes for the given mailbox * * @param mailbox * @return */ public Long getQuotaBytes(final Mailbox mailbox) { // TODO: add account quota attribute check return Configurator.getDefaultQuotaBytes(); }
/** * Get quota (maximum) messages for the given mailbox * * @param mailbox * @return */ public Long getQuotaCount(final Mailbox mailbox) { // TODO: add account quota attribute check return Configurator.getDefaultQuotaCount(); }
/** * Inspect the classpath to find storage configuration file */ static URI getStorageConfigURL() throws ConfigurationException { URI uri; String configUrl = System.getProperty("elasticinbox.config"); if (configUrl == null) { configUrl = DEFAULT_CONFIGURATION; } try { File file = new File(configUrl); if(!file.canRead()) { throw new ConfigurationException("Cannot read config file: " + configUrl); } uri = file.toURI(); } catch (Exception e) { logger.error("Error opening logfile: ", e); throw new ConfigurationException("Cannot locate " + configUrl); } return uri; }
BlobStoreProfile profile = Configurator.getBlobStoreProfile(profileName); ContextBuilder contextBuilder = ContextBuilder.newBuilder(profile.getProvider()); if (profile.getProvider().equals(PROVIDER_FILESYSTEM)) { properties.setProperty(FilesystemConstants.PROPERTY_BASEDIR, profile.getEndpoint()); contextBuilder.endpoint(profile.getEndpoint()); } else if (BLOBSTORE_PROVIDERS.contains(profile.getProvider())) { if (profile.getEndpoint() != null) { contextBuilder.endpoint(profile.getEndpoint()); if (profile.getApiversion() != null) { contextBuilder.apiVersion(profile.getApiversion()); if (profile.getIdentity() != null && profile.getCredential() != null) { contextBuilder.credentials(profile.getIdentity(), profile.getCredential()); "Unsupported Blobstore provider: " + profile.getProvider()); if(profile.getProvider().equals(PROVIDER_TRANSIENT)) { context.getBlobStore().createContainerInLocation(null, profile.getContainer());
public void start(BundleContext context) throws Exception { plugin = this; bundleContext = context; // Setup performance logger for POP3 if(Configurator.isPerformanceCountersEnabled()) { PeriodicalLog pLog = new PeriodicalLog(); pLog.setName(SPEED4J_LOG_NAME); pLog.setMode(PeriodicalLog.Mode.JMX_ONLY); pLog.setMaxQueueSize(250000); pLog.setPeriod(Configurator.getPerformanceCountersInterval()); pLog.setJmx("AUTH.success,AUTH.fail"); pLog.setSlf4jLogname("com.elasticinbox.speed4j.pop3.PeriodicalLogger"); stopWatchFactory = StopWatchFactory.getInstance(pLog); } else { Slf4jLog pLog = new Slf4jLog(); pLog.setName(SPEED4J_LOG_NAME); pLog.setSlf4jLogname("com.elasticinbox.speed4j.pop3.PeriodicalLogger"); stopWatchFactory = StopWatchFactory.getInstance(pLog); } backend = new MailboxHandlerFactory(); logger.debug("Starting POP3 daemon..."); server = new POP3ProxyServer(backend); server.start(); logger.info("POP3 daemon started."); }
BlobStoreProfile profile = Configurator.getBlobStoreProfile(profileName); String path = BlobUtils.relativize(uri.getPath()); if (profile.getProvider().equals(PROVIDER_FILESYSTEM)) String fileName = new StringBuilder(profile.getEndpoint()) .append(File.separator).append(profile.getContainer()) .append(File.separator).append(path).toString(); String container = profile.getContainer(); BlobStoreContext context = getBlobStoreContext(profileName); context.getBlobStore().removeBlob(container, path);
public Speed4jOpTimer() { // Instantiate a new Periodical logger PeriodicalLog pLog = new PeriodicalLog(); pLog.setName("ElasticInbox-Hector"); pLog.setPeriod(Configurator.getPerformanceCountersInterval()); pLog.setMode(PeriodicalLog.Mode.JMX_ONLY); pLog.setMaxQueueSize(250000); pLog.setJmx("READ.success,WRITE.success,READ.fail,WRITE.fail,META_READ.success,META_READ.fail"); pLog.setSlf4jLogname("com.elasticinbox.speed4j.cassandra.HectorPeriodicalLogger"); stopWatchFactory = StopWatchFactory.getInstance(pLog); }
long requiredCount = mailboxCounters.getTotalMessages() + 1; if ((requiredBytes > Configurator.getDefaultQuotaBytes()) || (requiredCount > Configurator.getDefaultQuotaCount())) Configurator.getDefaultQuotaBytes(), requiredCount, Configurator.getDefaultQuotaCount() }); Configurator.getBlobStoreWriteProfileName(), in, message.getSize()) .buildURI();
/** * Read Blob contents * * @param uri * @return */ public static InputStream read(URI uri) { // check if blob was stored for the message Assert.notNull(uri, "URI cannot be null"); logger.debug("Reading blob {}", uri); String profileName = uri.getHost(); String container = Configurator.getBlobStoreProfile(profileName).getContainer(); BlobStoreContext context = getBlobStoreContext(profileName); String path = BlobUtils.relativize(uri.getPath()); InputStream in = context.getBlobStore() .getBlob(container, path) .getPayload().getInput(); return in; }
public CassandraMessageDAO(Keyspace keyspace) { this.keyspace = keyspace; // Create BlobStorage instance with AES encryption and Deflate compression CompressionHandler compressionHandler = Configurator.isBlobStoreCompressionEnabled() ? new DeflateCompressionHandler() : null; EncryptionHandler encryptionHandler = Configurator.isBlobStoreEncryptionEnabled() ? new AESEncryptionHandler() : null; this.blobStorage = new BlobStorageMediator(compressionHandler, encryptionHandler); }
if (updatedSize <= Configurator.getDatabaseBlobMaxSize()) updatedSize, Configurator.getDatabaseBlobMaxSize()); blobUri = dbBlobStorage.write(messageId, mailbox, null, in1, updatedSize); } else { logger.debug( "Storing Blob in the cloud because size ({}KB) was greater than database threshold {}KB", updatedSize, Configurator.getDatabaseBlobMaxSize()); blobUri = cloudBlobStorage.write(messageId, mailbox, Configurator.getBlobStoreWriteProfileName(), in1, updatedSize);
public void start() throws Exception { Logger logger = new POP3ProtocolLogger(); POP3ProtocolHandlerChain chain = new POP3ProtocolHandlerChain(new AuthHandler(backend)); server = new NettyServer(new POP3Protocol(chain, new POP3ServerConfig(), logger)); server.setListenAddresses(new InetSocketAddress(Configurator.getPop3Port())); server.setMaxConcurrentConnections(Configurator.getPop3MaxConnections()); server.setTimeout(POP3ServerConfig.CONNECTION_TIMEOUT); server.setUseExecutionHandler(true, 16); server.bind(); }
public void start() throws Exception { Logger logger = new LMTPProtocolLogger(); LMTPProtocolHandlerChain chain = new LMTPProtocolHandlerChain(); chain.add(0, new ElasticInboxDeliveryHandler(backend)); chain.add(0, new ValidRcptHandler()); chain.wireExtensibleHandlers(); server = new NettyServer(new SMTPProtocol(chain, new LMTPServerConfig(), logger)); server.setListenAddresses(new InetSocketAddress(Configurator.getLmtpPort())); server.setMaxConcurrentConnections(Configurator.getLmtpMaxConnections()); server.setTimeout(LMTPServerConfig.CONNECTION_TIMEOUT); server.setUseExecutionHandler(true, 16); server.bind(); }
@Override public BlobURI write(final UUID messageId, final Mailbox mailbox, final String profileName, final InputStream in, final Long size) throws IOException, GeneralSecurityException { // get blob name String blobName = new BlobNameBuilder().setMailbox(mailbox) .setMessageId(messageId).setMessageSize(size).build(); InputStream in1; Long updatedSize = size; // prepare URI BlobURI blobUri = new BlobURI() .setProfile(profileName) .setName(blobName); // encrypt stream if (encryptionHandler != null) { byte[] iv = getCipherIVFromBlobName(blobName); InputStream encryptedInputStream = this.encryptionHandler.encrypt(in, Configurator.getBlobStoreDefaultEncryptionKey(), iv); FileBackedOutputStream fbout = new FileBackedOutputStream(MAX_MEMORY_FILE_SIZE, true); updatedSize = ByteStreams.copy(encryptedInputStream, fbout); in1 = fbout.getSupplier().getInput(); blobUri.setEncryptionKey(Configurator.getBlobStoreDefaultEncryptionKeyAlias()); } else { in1 = in; } CloudStoreProxy.write(blobName, profileName, in1, updatedSize); return blobUri; }
if (Configurator.isStoreHtmlWithMetadata()) } else if (!Configurator.isStorePlainWithMetadata() && (m.getPlainBody() != null)) { columns.put(CN_PLAIN_BODY, IOUtils.compress(m.getPlainBody())); if (Configurator.isStorePlainWithMetadata() && (m.getPlainBody() != null)) { columns.put(CN_PLAIN_BODY, IOUtils.compress(m.getPlainBody()));
@Override public Message filter(Message message) { // by default store in Inbox if(message.getLabels().isEmpty()) { message.addLabel(ReservedLabels.INBOX.getId()); // add to POP3 if enabled if (Configurator.isLmtpPop3Enabled()) { logger.debug("Adding message received via LMTP to POP3"); message.addLabel(ReservedLabels.POP3.getId()); } } return message; } }
@Override public BlobDataSource read(final URI uri) throws IOException { InputStream in; BlobURI blobUri = new BlobURI().fromURI(uri); String keyAlias = blobUri.getEncryptionKey(); if (keyAlias != null) { // currently we only support AES encryption, use by default EncryptionHandler eh = new AESEncryptionHandler(); try { logger.debug("Decrypting object {} with key {}", uri, keyAlias); byte[] iv = getCipherIVFromBlobName(BlobUtils.relativize(uri.getPath())); in = eh.decrypt(CloudStoreProxy.read(uri), Configurator.getEncryptionKey(keyAlias), iv); } catch (GeneralSecurityException gse) { throw new IOException("Unable to decrypt message blob: ", gse); } } else { in = CloudStoreProxy.read(uri); } return new BlobDataSource(uri, in); }
public void start(BundleContext context) throws Exception { plugin = this; bundleContext = context; // Setup performance logger for LMTP if(Configurator.isPerformanceCountersEnabled()) { LoggingPeriodicalLog pLog = new LoggingPeriodicalLog(); pLog.setName(SPEED4J_LOG_NAME); pLog.setMode(PeriodicalLog.Mode.JMX_ONLY); pLog.setMaxQueueSize(250000); pLog.setPeriod(Configurator.getPerformanceCountersInterval()); pLog.setJmx("DELIVERY.success,DELIVERY.discard,DELIVERY.defer,DELIVERY.defer_failure,DELIVERY.reject_overQuota,DELIVERY.reject_nonExistent"); pLog.setSlf4jLogname("com.elasticinbox.speed4j.lmtp.PeriodicalLogger"); stopWatchFactory = StopWatchFactory.getInstance(pLog); } else { Slf4jLog pLog = new Slf4jLog(); pLog.setName(SPEED4J_LOG_NAME); pLog.setSlf4jLogname("com.elasticinbox.speed4j.lmtp.PeriodicalLogger"); stopWatchFactory = StopWatchFactory.getInstance(pLog); } DeliveryAgentFactory mdf = new DeliveryAgentFactory(); backend = new MulticastDeliveryAgent(mdf.getDeliveryAgent()); logger.debug("Starting LMTP daemon..."); server = new LMTPProxyServer(backend); server.start(); logger.info("LMTP daemon started."); }
/** * Store Blob * * @param blobName * Blob filename including relative path * @param profileName * Blob store profile name * @param in * Payload * @param size * Payload size in bytes * @return * @throws IOException */ public static void write(final String blobName, final String profileName, InputStream in, final Long size) throws IOException, GeneralSecurityException { Assert.notNull(in, "No data to store"); Assert.notNull(size, "Blob size must be specified"); final String container = Configurator.getBlobStoreProfile(profileName).getContainer(); BlobStoreContext context = getBlobStoreContext(profileName); logger.debug("Storing blob {} on {}", blobName, profileName); BlobStore blobStore = context.getBlobStore(); BlobBuilder blobBuilder = blobStore.blobBuilder(blobName).payload(in).contentLength(size); // store blob blobStore.putBlob(container, blobBuilder.build()); }
throw new ConfigurationException("Unable to access key store: " + ioe.getMessage(), ioe); } catch (GeneralSecurityException gse) { throw new ConfigurationException("Unable to load encryption keys: " + gse.getMessage(), gse);