Skip to content

Commit

Permalink
Merge branch 'susimail-html' into 'master'
Browse files Browse the repository at this point in the history
Susimail: Add support for HTML email

See merge request i2p-hackers/i2p.i2p!177
  • Loading branch information
zzz committed Feb 2, 2024
2 parents 7040d32 + 8aca5d0 commit f2dc8ec
Show file tree
Hide file tree
Showing 7 changed files with 328 additions and 37 deletions.
29 changes: 29 additions & 0 deletions apps/susimail/src/js/iframer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/* @license http://www.gnu.org/licenses/gpl-2.0.html GPL-2.0 */
/* see also licenses/LICENSE-GPLv2.txt */

// called from iframed.js

function setupFrame() {
var frames = document.getElementsByClassName("iframedsusi");
for(index = 0; index < frames.length; index++)
{
var frame = frames[index];
frame.addEventListener("load", function() {
// old way, iframed.js. we use this as a backup in case
// the js injection didn't work

resizeFrame(frame);

// new way, iframe-resizer

// By default the height of the iFrame is calculated by converting the margin of the body to px and then adding the top and bottom figures to the offsetHeight of the body tag.
// In cases where CSS styles causes the content to flow outside the body you may need to change this setting to one of the following options.
// If the default option doesn't work then the best solutions is to use either taggedElement, or lowestElement.
// The **lowestElement** option is the most reliable way of determining the page height.
// However, it does have a performance impact, as it requires checking the position of every element on the page.
iFrameResize({ log: false, heightCalculationMethod: 'lowestElement' }, frame)
}, true);
}
}

/* @license-end */
6 changes: 4 additions & 2 deletions apps/susimail/src/src/i2p/susi/util/RegexOutputStream.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
import java.io.FilterOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Locale;

import net.i2p.I2PAppContext;
import net.i2p.data.DataHelper;
import net.i2p.util.Log;

/**
* Replace patterns with a simple regex on the fly.
* Case insensitive.
*
* @since 0.9.62
*/
Expand All @@ -34,7 +36,7 @@ public RegexOutputStream(OutputStream out, String pattern, String replace, Strin
super(out);
if (pattern.length() == 0 || pattern.startsWith("*") || pattern.endsWith("*") || pattern.contains("**"))
throw new IllegalArgumentException();
match = pattern;
match = pattern.toLowerCase(Locale.US);
repl = replace;
noMatch = onNoMatch;
buf = new StringBuilder(64);
Expand All @@ -60,7 +62,7 @@ public void write(int val) throws IOException {
found = true;
}
}
} else if (m == c) {
} else if (m == Character.toLowerCase(c)) {
pushit(c);
idx++;
if (idx == match.length()) {
Expand Down
78 changes: 78 additions & 0 deletions apps/susimail/src/src/i2p/susi/webmail/CSPDetector.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package i2p.susi.webmail;

import java.util.Locale;

/**
* Check user-agent for support of CSP
* @since 0.9.62
*/
class CSPDetector {
/**
* ref: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy
*/
public static boolean supportsCSP(String ua) {
if (ua == null)
return false;
ua = ua.toLowerCase(Locale.US);
// mobile anything: assume no
if (ua.contains("mobile"))
return false;

// ref: https://www.useragents.me/
// min versions
// chrome: 25
// covers edge, opera
int idx = ua.indexOf("chrome/");
if (idx >= 0) {
idx += 7;
return getVersion(ua, idx) >= 25;
}
// safari: 7
idx = ua.indexOf("safari/");
if (idx >= 0) {
idx = ua.indexOf("version/");
if (idx >= 0) {
idx += 8;
return getVersion(ua, idx) >= 7;
}
}
// firefox: 23
idx = ua.indexOf("firefox/");
if (idx >= 0) {
idx += 8;
return getVersion(ua, idx) >= 23;
}
return false;
}

private static int getVersion(String ua, int idx) {
int rv = 0;
for (int i = idx; i < ua.length(); i++) {
char c = ua.charAt(i);
if (c < '0' || c > '9')
break;
if (i > idx)
rv *= 10;
rv += c - '0';
}
//System.out.println("Found version " + rv + " in " + ua);
return rv;
}

/****
public static void main(String[] args) {
String s = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36 Edg/119.0.0.0";
System.out.println(supportsCSP(s) + " " + s);
s = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36";
System.out.println(supportsCSP(s) + " " + s);
s = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.1 Safari/605.1.1";
System.out.println(supportsCSP(s) + " " + s);
s = "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/119.0";
System.out.println(supportsCSP(s) + " " + s);
s = "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/11.0";
System.out.println(supportsCSP(s) + " " + s);
s = "xxx";
System.out.println(supportsCSP(s) + " " + s);
}
****/
}
Loading

0 comments on commit f2dc8ec

Please sign in to comment.