def cleanUri()

in backend/app/model/Email.scala [118:179]


  def cleanUri(original: String): String = UriCleaner.clean(original.removeChevrons())

  def cleanInReplyTo(original: String): List[String] = original.splitListClean(' ').map(_.removeChevrons())

  /**
    * An alternative endpoint that can be used if we are not certain we'll have a useful message ID.
    *
    * In this case if we don't have an explicit message ID we make a best effort to create one that is unique from the
    * information that we do have.
    *
    * We include the main components but have deliberately omitted some of the metadata flags. The aim is a good
    * balance between having enough entropy without causing problems if we change the way that some of the more
    * esoteric features are represented.
    */
  def createFrom(maybeUri: Option[Uri],
            from: Option[Recipient],
            recipients: List[Recipient],
            sentAt: Option[String],
            sensitivity: Option[Sensitivity],
            priority: Option[String],
            subject: String,
            body: String,
            inReplyTo: List[String],
            references: List[String],
            html: Option[String],
            attachmentCount: Int,
            metadata: Map[String, Seq[String]] = Map.empty,
            flag: Option[String] = None): Email = {
    val uri = maybeUri.getOrElse {
      val toBeHashed = s"$from/$recipients/$sentAt/$subject/$body/$inReplyTo/$references/$html"
      val uri = {
        val digest = MessageDigest.getInstance("SHA-512")
        digest.update(toBeHashed.getBytes("UTF-8"))
        Uri(s"no_id:${Base64.getUrlEncoder.withoutPadding.encodeToString(digest.digest())}")
      }
      logger.warn(s"Synthesised message ID $uri")
      uri
    }

    // ensure that the IDs for reply-to and references are clean and valid
    val cleanReplyTo = inReplyTo.map(_.trim).filter(_.nonEmpty)
    if (cleanReplyTo != inReplyTo) logger.warn(s"In-Reply-To list was cleaned up for $uri. Was: $inReplyTo Now: $cleanReplyTo")
    val cleanReferenced = references.map(_.trim).filter(_.nonEmpty)
    if (cleanReferenced != references) logger.warn(s"Referenced list was cleaned up for $uri. Was: $references Now: $cleanReferenced")

    Email(
      uri = uri,
      from = from,
      recipients = recipients,
      sentAt = sentAt,
      sensitivity = sensitivity,
      priority = priority,
      subject = subject,
      body = body,
      inReplyTo = cleanReplyTo,
      references = cleanReferenced,
      html = html,
      attachmentCount = attachmentCount,
      metadata = metadata,
      flag = flag
    )
  }