forked from m242/maildrop
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
83 changed files
with
2,654 additions
and
2,574 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
logs | ||
project/project | ||
project/target | ||
target | ||
tmp | ||
.history | ||
dist | ||
/.idea | ||
/*.iml | ||
/out | ||
/.idea_modules | ||
/.classpath | ||
/.project | ||
/RUNNING_PID | ||
/.settings |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
name := "common" | ||
|
||
version := "2.0" | ||
|
||
scalaVersion := "2.11.2" | ||
|
||
resolvers ++= Seq( | ||
"rediscala" at "http://dl.bintray.com/etaty/maven", | ||
"Typesafe repository" at "http://repo.typesafe.com/typesafe/releases/" | ||
) | ||
|
||
libraryDependencies ++= Seq( | ||
"com.typesafe" % "config" % "1.2.1", | ||
"com.typesafe.akka" % "akka-actor_2.11" % "2.3.6", | ||
"com.etaty.rediscala" %% "rediscala" % "1.3.1", | ||
"com.typesafe.play" %% "play-json" % "2.3.4" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
logLevel := Level.Warn |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
maildrop { | ||
|
||
server { | ||
bind-address = "0.0.0.0" | ||
bind-port = 25000 | ||
command-delay = 2s | ||
connection-timeout = 60s | ||
max-connections = 200 | ||
} | ||
|
||
sender { | ||
greylist { | ||
response = "You have been temporarily greylisted. Please try back later." | ||
time = 5m | ||
} | ||
dnsbl = [ "zen.spamhaus.org.", "bl.mailspike.net.", "bb.barracudacentral.org.", "psbl.surriel.com.", "dnsbl.sorbs.net.", "bl.score.senderscore.com" ] | ||
spf { | ||
response = "Invalid sender - see http://www.openspf.org/Introduction" | ||
} | ||
cache-time = 24h | ||
} | ||
|
||
recipient { | ||
max-addr-length = 50 | ||
response = "That is an invalid recipient." | ||
} | ||
|
||
data { | ||
alt-inbox-modifier = 1234567890 | ||
alt-inbox-prefix = "D-" | ||
max-message-size = 100k | ||
max-message-reason = "The message is too large (more than 100k)." | ||
} | ||
|
||
mailbox { | ||
max-length = 10 | ||
expires = 24h | ||
} | ||
|
||
redis { | ||
host = "localhost" | ||
port = 6379 | ||
// password = "foo" | ||
// db = 2 | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<configuration> | ||
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> | ||
<!-- encoders are assigned the type | ||
ch.qos.logback.classic.encoder.PatternLayoutEncoder by default --> | ||
<encoder> | ||
<pattern>%d{HH:mm:ss.SSS} [%level] %logger{36} - %msg%n</pattern> | ||
</encoder> | ||
</appender> | ||
<root level="info"> | ||
<appender-ref ref="STDOUT"/> | ||
</root> | ||
</configuration> |
This file was deleted.
Oops, something went wrong.
12 changes: 6 additions & 6 deletions
12
.../scala/com/heluna/util/AltInboxUtil.scala → ...a/com/heluna/maildrop/util/AltInbox.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
common/src/main/scala/com/heluna/maildrop/util/MailDropConfig.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package com.heluna.maildrop.util | ||
|
||
import java.io.File | ||
import java.util.concurrent.TimeUnit | ||
import com.typesafe.config.{Config, ConfigFactory} | ||
import scala.util.Try | ||
|
||
/** | ||
* common com.heluna.maildrop | ||
* User: markbe | ||
* Date: 9/10/14 | ||
* Time: 9:39 AM | ||
*/ | ||
|
||
object MailDropConfig { | ||
|
||
val config = Option(System.getProperty("config.file")).fold[Config](ConfigFactory.load())(f => ConfigFactory.parseFile(new File(f)).withFallback(ConfigFactory.load())) | ||
|
||
def getBytes(key: String): Option[Long] = Try(Option(config.getBytes(key).toLong)).toOption.flatten | ||
|
||
def getInt(key: String): Option[Int] = Try(Option(config.getInt(key))).toOption.flatten | ||
|
||
def getLong(key: String): Option[Long] = Try(Option(config.getLong(key))).toOption.flatten | ||
|
||
def getMilliseconds(key: String): Option[Long] = Try(Option(config.getDuration(key, TimeUnit.MILLISECONDS))).toOption.flatten | ||
|
||
def getSeconds(key: String): Option[Long] = Try(Option(config.getDuration(key, TimeUnit.SECONDS))).toOption.flatten | ||
|
||
def getString(key: String): Option[String] = Try(Option(config.getString(key))).toOption.flatten | ||
|
||
def getStringList(key: String): List[String] = Try(getStringList(key)).toOption.getOrElse(List[String]()) | ||
|
||
def apply(key: String) = getString(key) | ||
|
||
} |
56 changes: 56 additions & 0 deletions
56
common/src/main/scala/com/heluna/maildrop/util/Mailbox.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package com.heluna.maildrop.util | ||
|
||
import java.util.Date | ||
import play.api.libs.json.{JsValue, Json} | ||
import scala.concurrent.ExecutionContext.Implicits.global | ||
import scala.concurrent.Future | ||
import scala.util.Random | ||
|
||
/** | ||
* smtp com.heluna.maildrop.util | ||
* User: markbe | ||
* Date: 9/10/14 | ||
* Time: 11:53 AM | ||
*/ | ||
|
||
object Mailbox { | ||
|
||
val maxLength = MailDropConfig.getInt("maildrop.mailbox.max-length").getOrElse(10) | ||
val expiry = MailDropConfig.getSeconds("maildrop.mailbox.expires").getOrElse(86400L) | ||
|
||
def key(recipient: String) = "mailbox:" + recipient.toLowerCase | ||
|
||
def add(sender: String, recipient: String, subject: String, date: Date = new Date(), body: String): Unit = { | ||
val id = shortId | ||
val rkey = key(recipient) | ||
val json = Json.obj( | ||
"id" -> id, | ||
"sender" -> sender, | ||
"recipient" -> recipient, | ||
"subject" -> subject, | ||
"date" -> date.getTime, | ||
"body" -> body | ||
) | ||
Redis.client.lpush(rkey, Json.stringify(json)) | ||
Redis.client.ltrim(rkey, 0, maxLength - 1) | ||
Redis.client.expire(rkey, expiry) | ||
} | ||
|
||
def list(recipient: String): Future[List[JsValue]] = | ||
Redis.client.lrange[String](key(recipient), 0, maxLength).map(seq => seq.map(json => Json.parse(json)).toList) | ||
|
||
def get(recipient: String, id: String): Future[Option[JsValue]] = | ||
list(recipient).map(messages => messages.find(json => (json \ "id").as[String] == id)) | ||
|
||
def delete(recipient: String, id: String): Unit = { | ||
val rkey = key(recipient) | ||
list(recipient).foreach(messages => { | ||
val idx = messages.indexWhere(json => (json \ "id").as[String] == id) | ||
Redis.client.lset(rkey, idx, "__deleted__") | ||
Redis.client.lrem(rkey, 0, "__deleted__") | ||
}) | ||
} | ||
|
||
def shortId = Random.alphanumeric.take(6).mkString | ||
|
||
} |
38 changes: 38 additions & 0 deletions
38
common/src/main/scala/com/heluna/maildrop/util/Metrics.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package com.heluna.maildrop.util | ||
|
||
import java.text.SimpleDateFormat | ||
import java.util.Date | ||
import scala.concurrent.ExecutionContext.Implicits.global | ||
import scala.concurrent.Future | ||
|
||
/** | ||
* smtp com.heluna.maildrop.util | ||
* User: markbe | ||
* Date: 9/10/14 | ||
* Time: 11:26 AM | ||
*/ | ||
|
||
object Metrics { | ||
|
||
val BLOCKEDCHANNEL = "blocked-channel" | ||
val sdf = new SimpleDateFormat("yyyy/MM/dd") | ||
def key = sdf.format(new Date()) | ||
|
||
def connection(): Unit = { | ||
Redis.client.incr(key + "/connection") | ||
} | ||
|
||
def message(): Unit = { | ||
Redis.client.incr(key + "/message") | ||
} | ||
|
||
def blocked(): Unit = { | ||
Redis.client.incr(key + "/blocked") | ||
Redis.client.incr("blocked") onSuccess { | ||
case blocked => Redis.client.publish(BLOCKEDCHANNEL, blocked.toString) | ||
} | ||
} | ||
|
||
def getBlocked = Redis.client.get("blocked").map(_.map(_.utf8String.toLong).getOrElse(0L)) | ||
|
||
} |
28 changes: 28 additions & 0 deletions
28
common/src/main/scala/com/heluna/maildrop/util/Redis.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package com.heluna.maildrop.util | ||
|
||
import java.net.InetSocketAddress | ||
|
||
import akka.actor.ActorSystem | ||
import redis.RedisClient | ||
import redis.actors.RedisSubscriberActor | ||
import redis.api.pubsub.{Message, PMessage} | ||
|
||
/** | ||
* smtp com.heluna.maildrop.util | ||
* User: markbe | ||
* Date: 9/10/14 | ||
* Time: 11:09 AM | ||
*/ | ||
|
||
object Redis { | ||
|
||
implicit val redisSystem = ActorSystem() | ||
|
||
val hostname = MailDropConfig("maildrop.redis.host").getOrElse("localhost") | ||
val port = MailDropConfig.getInt("maildrop.redis.port").getOrElse(6379) | ||
val password = MailDropConfig("maildrop.redis.password") | ||
val db = MailDropConfig.getInt("maildrop.redis.db") | ||
|
||
val client = RedisClient(hostname, port, password, db) | ||
|
||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.