Skip to content

Commit

Permalink
Merge pull request #346 from eikek/merge-0.9
Browse files Browse the repository at this point in the history
Merge 0.9
  • Loading branch information
eikek authored Mar 21, 2022
2 parents 420ef7d + a37374c commit 09e7de9
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 18 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package emil.javamail.internal.ops

import cats.effect.Sync
import cats.syntax.all._
import emil._
import emil.javamail.conv.Conv
import emil.javamail.internal.{JavaMailConnection, JavaMailImapConnection, Logger}
Expand All @@ -14,39 +15,39 @@ object LoadMail {
)(implicit
cm: Conv[MimeMessage, Mail[F]]
): MailOp[F, JavaMailConnection, Option[Mail[F]]] =
FindMail[F](mh).map { optMime =>
FindMail[F](mh).andThen { optMime =>
logger.debug(s"Loading complete mail for '$mh' from mime message '$optMime'")
optMime.map(cm.convert)
optMime.traverse(mime => Sync[F].delay(cm.convert(mime)))
}

def byUid[F[_]: Sync](folder: MailFolder, uid: MailUid)(implicit
cm: Conv[MimeMessage, Mail[F]]
): MailOp[F, JavaMailImapConnection, Option[Mail[F]]] =
FindMail.byUid[F](folder, uid).map { optMime =>
FindMail.byUid[F](folder, uid).andThen { optMime =>
logger
.debug(s"Loaded complete raw mail for '$uid' from mime message '$optMime'")
optMime.map(cm.convert)
optMime.traverse(mime => Sync[F].delay(cm.convert(mime)))
}

def byUid[F[_]: Sync](folder: MailFolder, start: MailUid, end: MailUid)(implicit
cm: Conv[MimeMessage, Mail[F]]
): MailOp[F, JavaMailImapConnection, List[Mail[F]]] =
FindMail.byUid[F](folder, start, end).map { mimes =>
FindMail.byUid[F](folder, start, end).andThen { mimes =>
logger
.debug(
s"Loaded complete raw mail from '$start' to '$end' from mime messages: ${mimes.size}"
)
mimes.map(cm.convert)
mimes.traverse(mime => Sync[F].delay(cm.convert(mime)))
}

def byUid[F[_]: Sync](folder: MailFolder, uids: Set[MailUid])(implicit
cm: Conv[MimeMessage, Mail[F]]
): MailOp[F, JavaMailImapConnection, List[Mail[F]]] =
FindMail.byUid[F](folder, uids).map { mimes =>
FindMail.byUid[F](folder, uids).andThen { mimes =>
logger
.debug(
s"Loaded complete raw mail for '$uids' from mime messages: ${mimes.size}"
)
mimes.map(cm.convert)
mimes.traverse(mime => Sync[F].delay(cm.convert(mime)))
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package emil.javamail.internal.ops

import cats.effect.Sync
import cats.syntax.all._
import emil._
import emil.javamail.conv.Conv
import emil.javamail.internal.{JavaMailConnection, JavaMailImapConnection, Logger}
Expand All @@ -15,43 +16,54 @@ object LoadMailRaw {
)(implicit
cm: Conv[MimeMessage, ByteVector]
): MailOp[F, JavaMailConnection, Option[ByteVector]] =
FindMail[F](mh).map { optMime =>
FindMail[F](mh).andThen { optMime =>
logger.debug(s"Loading complete raw mail for '$mh' from mime message '$optMime'")
optMime.map(cm.convert)
optMime.traverse(mime => Sync[F].delay(cm.convert(mime)))
}

def byUid[F[_]: Sync](folder: MailFolder, uid: MailUid)(implicit
cm: Conv[MimeMessage, MailHeader],
cb: Conv[MimeMessage, ByteVector]
): MailOp[F, JavaMailImapConnection, Map[MailHeader, ByteVector]] =
FindMail.byUid[F](folder, uid).map { optMime =>
logger
.debug(s"Loaded complete raw mail for '$uid' from mime message '$optMime'")
optMime.map(mime => cm.convert(mime) -> cb.convert(mime)).toList.toMap
FindMail.byUid[F](folder, uid).andThen { optMime =>
logger.debug(s"Loaded complete raw mail for '$uid' from mime message '$optMime'")
optMime
.traverse { mime =>
(Sync[F].delay(cm.convert(mime)), Sync[F].delay(cb.convert(mime))).tupled
}
.map(_.toList.toMap)
}

def byUid[F[_]: Sync](folder: MailFolder, start: MailUid, end: MailUid)(implicit
cm: Conv[MimeMessage, MailHeader],
cb: Conv[MimeMessage, ByteVector]
): MailOp[F, JavaMailImapConnection, Map[MailHeader, ByteVector]] =
FindMail.byUid[F](folder, start, end).map { mimes =>
FindMail.byUid[F](folder, start, end).andThen { mimes =>
logger
.debug(
s"Loaded complete raw mail from '$start' to '$end' from mime messages: ${mimes.size}"
)
mimes.map(mime => cm.convert(mime) -> cb.convert(mime)).toMap
mimes
.traverse { mime =>
(Sync[F].delay(cm.convert(mime)), Sync[F].delay(cb.convert(mime))).tupled
}
.map(_.toMap)
}

def byUid[F[_]: Sync](folder: MailFolder, uids: Set[MailUid])(implicit
cm: Conv[MimeMessage, MailHeader],
cb: Conv[MimeMessage, ByteVector]
): MailOp[F, JavaMailImapConnection, Map[MailHeader, ByteVector]] =
FindMail.byUid[F](folder, uids).map { mimes =>
FindMail.byUid[F](folder, uids).andThen { mimes =>
logger
.debug(
s"Loaded complete raw mail for '$uids' from mime messages: ${mimes.size}"
)
mimes.map(mime => cm.convert(mime) -> cb.convert(mime)).toMap
mimes
.traverse { mime =>
(Sync[F].delay(cm.convert(mime)), Sync[F].delay(cb.convert(mime))).tupled
}
.map(_.toMap)
}

}

0 comments on commit 09e7de9

Please sign in to comment.