diff options
| author | Vosjedev <vosje@vosjedev.net> | 2025-10-28 16:57:08 +0100 |
|---|---|---|
| committer | Vosjedev <vosje@vosjedev.net> | 2025-10-28 16:57:08 +0100 |
| commit | 13b268348f73ceddaacf1284844ba50cdd0632da (patch) | |
| tree | aa4987c7ecf5ff4616ad468e1874cd796d40c179 | |
| parent | 357abea4e89204ed0df7dd4e8f9722529f4a7363 (diff) | |
| download | acit-13b268348f73ceddaacf1284844ba50cdd0632da.tar.gz acit-13b268348f73ceddaacf1284844ba50cdd0632da.tar.bz2 acit-13b268348f73ceddaacf1284844ba50cdd0632da.tar.xz | |
Add small util functions used by imapplugin
| -rw-r--r-- | src/acit/util.py | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/src/acit/util.py b/src/acit/util.py new file mode 100644 index 0000000..e4e346c --- /dev/null +++ b/src/acit/util.py @@ -0,0 +1,28 @@ +def lookahead(iterable): # https://stackoverflow.com/a/1630350 + """Pass through all values from the given iterable, augmented by the + information if there are more values to come after the current one + (True), or if it is the last value (False). + """ + # Get an iterator and pull the first value. + it = iter(iterable) + try: + last = next(it) + except StopIteration: + return + # Run the iterator to exhaustion (starting from the second value). + for val in it: + # Report the *previous* value (more to come). + yield last, False + last = val + # Report the last value. + yield last, True + +def email2html(mailtext:str,extraclasses=""): + print(mailtext) + from html import escape + res='<section class="email %s"><p>'%extraclasses + mail=escape(mailtext).replace("\n\n","</p><p>").replace("\n","<br>") + res+=mail + res+="</p></section>" + return res + |
