emailer/src/main/scala/cz/xelfi/quoridor/emailer/Main.scala
changeset 240 29287b0a1a0b
parent 228 3ea04696a115
child 244 32dd025e4b76
     1.1 --- a/emailer/src/main/scala/cz/xelfi/quoridor/emailer/Main.scala	Tue Feb 16 01:22:36 2010 +0100
     1.2 +++ b/emailer/src/main/scala/cz/xelfi/quoridor/emailer/Main.scala	Sun Apr 25 22:46:08 2010 +0200
     1.3 @@ -50,15 +50,15 @@
     1.4      val props = java.lang.System.getProperties
     1.5      props.put("mail.smtp.host", args(3));
     1.6  
     1.7 -    val session = javax.mail.Session.getDefaultInstance(props, null)
     1.8 +    val session = if (args(3).equals("print")) null else javax.mail.Session.getDefaultInstance(props, null)
     1.9  
    1.10      val notify = new Notify() {
    1.11 -      protected def allPlayers(): Map[String,List[Node]] = {
    1.12 +      protected def allPlayers(): Map[String,List[Info]] = {
    1.13          val u = new URL(api, "games");
    1.14          val conn = u.openConnection
    1.15          conn.setRequestProperty("Accept", "text/xml")
    1.16  
    1.17 -        val ret = new HashMap[String,List[Node]]
    1.18 +        val ret = new HashMap[String,List[Info]]
    1.19  
    1.20          val before = System.currentTimeMillis - okDelay
    1.21          val games = XML.load(conn.getInputStream)
    1.22 @@ -76,7 +76,9 @@
    1.23                }
    1.24              if (name != null) {
    1.25                val prev = ret.getOrElse(name, Nil)
    1.26 -              val next = g :: prev
    1.27 +              val id = (g \\ "@id").text
    1.28 +              val info = new Info(modified, id)
    1.29 +              val next = info :: prev
    1.30                ret.put(name, next);
    1.31              }
    1.32            }
    1.33 @@ -84,8 +86,8 @@
    1.34          return ret;
    1.35        }
    1.36  
    1.37 -      protected def emails(ids : Collection[String]): List[String] = {
    1.38 -        var ret : List[String] = Nil;
    1.39 +      protected def emails(ids : Collection[String]): Map[String,String] = {
    1.40 +        var ret = new HashMap[String,String]
    1.41          for (val p <- ids) {
    1.42            val u = new URL(api, "users/" + p + "?loginID=" + loginID)
    1.43            val conn = u.openConnection
    1.44 @@ -98,13 +100,21 @@
    1.45                }
    1.46            })
    1.47            if (!res.isEmpty) {
    1.48 -            ret = res(0).text :: ret;
    1.49 +            ret.put(p, res(0).text)
    1.50            }
    1.51          }
    1.52          return ret
    1.53        }
    1.54  
    1.55        protected def sendEmail(address : String, subject : String, text : String) : Unit = {
    1.56 +        Console.println("Sending message to")
    1.57 +        Console.println("  email: " + address.split('@')(0) + "@... ")
    1.58 +        Console.println("  subject: " + subject)
    1.59 +        Console.println("  " + text)
    1.60 +        if (session == null) {
    1.61 +          return;
    1.62 +        }
    1.63 +
    1.64          val message = new MimeMessage(session)
    1.65          message.setFrom(new InternetAddress("quoridor@xelfi.cz"))
    1.66          message.addRecipient(Message.RecipientType.TO, new InternetAddress(address))