forked from I2P_Developers/i2p.i2p
Susimail: Show dropdown on login page for selection from multiple accounts
This commit is contained in:
@@ -318,6 +318,41 @@ class PersistentMailCache {
|
||||
return base;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return non-null, sorted, possibly empty
|
||||
* @since 0.9.62
|
||||
*/
|
||||
public static List<String> getAllUsers(String host, int port) {
|
||||
File f = new SecureDirectory(I2PAppContext.getGlobalContext().getConfigDir(), DIR_SUSI);
|
||||
if (!f.exists())
|
||||
return Collections.emptyList();
|
||||
f = new SecureDirectory(f, DIR_CACHE);
|
||||
if (!f.exists())
|
||||
return Collections.emptyList();
|
||||
File[] files = f.listFiles();
|
||||
if (files == null || files.length == 0)
|
||||
return Collections.emptyList();
|
||||
List<String> rv = new ArrayList<String>(files.length);
|
||||
String suff = host + port;
|
||||
for (File d : files) {
|
||||
if (!d.isDirectory())
|
||||
continue;
|
||||
String name = d.getName();
|
||||
if (!name.startsWith(CACHE_PREFIX))
|
||||
continue;
|
||||
name = name.substring(CACHE_PREFIX.length());
|
||||
String dec = Base64.decodeToString(name);
|
||||
if (dec == null)
|
||||
continue;
|
||||
if (dec.endsWith(suff))
|
||||
dec = dec.substring(0, dec.length() - suff.length());
|
||||
rv.add(dec);
|
||||
}
|
||||
if (rv.size() > 1)
|
||||
Collections.sort(rv);
|
||||
return rv;
|
||||
}
|
||||
|
||||
public File getHeaderFile(String uidl) {
|
||||
return getFile(uidl, HDR_SUFFIX);
|
||||
}
|
||||
|
||||
@@ -2450,7 +2450,7 @@ public class WebMail extends HttpServlet
|
||||
* now write body
|
||||
*/
|
||||
if( state == State.AUTH )
|
||||
showLogin( out );
|
||||
showLogin(out, _t("Add a new user").equals(request.getParameter(USER)));
|
||||
|
||||
else if (state == State.LOADING)
|
||||
showLoading(out, sessionObject, request);
|
||||
@@ -3112,7 +3112,7 @@ public class WebMail extends HttpServlet
|
||||
*
|
||||
* @param out
|
||||
*/
|
||||
private static void showLogin( PrintWriter out )
|
||||
private static void showLogin(PrintWriter out, boolean addNew)
|
||||
{
|
||||
//boolean fixed = Boolean.parseBoolean(Config.getProperty( CONFIG_PORTS_FIXED, "true" ));
|
||||
//String host = Config.getProperty(CONFIG_HOST, DEFAULT_HOST);
|
||||
@@ -3121,8 +3121,36 @@ public class WebMail extends HttpServlet
|
||||
|
||||
out.println( "<div id=\"dologin\"><h1>" + _t("Email Login") + "</h1><table cellspacing=\"3\" cellpadding=\"5\">\n" +
|
||||
// current postman hq length limits 16/12, new postman version 32/32
|
||||
"<tr><td align=\"right\" width=\"30%\">" + _t("User") + "</td><td width=\"40%\" align=\"left\"><input type=\"text\" size=\"32\" name=\"" + USER + "\" value=\"" + "\"> @mail.i2p</td></tr>\n" +
|
||||
"<tr><td align=\"right\" width=\"30%\">" + _t("Password") + "</td><td width=\"40%\" align=\"left\"><input type=\"password\" size=\"32\" name=\"pass\" value=\"" + "\"></td></tr>\n");
|
||||
"<tr><td align=\"right\" width=\"30%\">" + _t("User") + "</td><td width=\"40%\" align=\"left\">");
|
||||
boolean fixedPorts = Boolean.parseBoolean(Config.getProperty(CONFIG_PORTS_FIXED, "true"));
|
||||
if (fixedPorts && !addNew) {
|
||||
String host = Config.getProperty(CONFIG_HOST, DEFAULT_HOST);
|
||||
int port = DEFAULT_POP3PORT;
|
||||
String pop3Port = Config.getProperty(CONFIG_PORTS_POP3, Integer.toString(DEFAULT_POP3PORT));
|
||||
try { port = Integer.parseInt(pop3Port); } catch (NumberFormatException nfe) {}
|
||||
List<String> users = PersistentMailCache.getAllUsers(host, port);
|
||||
int sz = users.size();
|
||||
if (sz > 1) {
|
||||
out.println("<select name=\"" + USER + "\">");
|
||||
for (String user : users) {
|
||||
out.println("<option>" + DataHelper.escapeHTML(user) + "</option>");
|
||||
}
|
||||
out.println("<option>" + _t("Add a new user") + "</option>");
|
||||
out.println("</select>");
|
||||
} else if (sz == 1) {
|
||||
// For the common case, stuff the form so the browser will fill in the password.
|
||||
// User can change it to create a new one.
|
||||
out.println("<input type=\"text\" size=\"32\" name=\"" + USER + "\" value=\"" + DataHelper.escapeHTML(users.get(0)) + "\">");
|
||||
} else {
|
||||
out.println("<input type=\"text\" size=\"32\" name=\"" + USER + "\" value=\"\">");
|
||||
}
|
||||
} else {
|
||||
out.println("<input type=\"text\" size=\"32\" name=\"" + USER + "\" value=\"\">");
|
||||
}
|
||||
out.println(" @mail.i2p</td></tr>\n");
|
||||
|
||||
|
||||
out.println("<tr><td align=\"right\" width=\"30%\">" + _t("Password") + "</td><td width=\"40%\" align=\"left\"><input type=\"password\" size=\"32\" name=\"pass\" value=\"" + "\"></td></tr>\n");
|
||||
// which is better?
|
||||
out.println(
|
||||
"<tr><td colspan=\"2\"><hr></td></tr>\n" +
|
||||
|
||||
Reference in New Issue
Block a user