Skip to content

Commit

Permalink
treat mailto: URI parameters case-insensitive
Browse files Browse the repository at this point in the history
Although RFC defines such parameters case-sensitive, some applications
still use capitalized versions like "Subject" and "Body". Since the Java
Uri parser is case-sensitive, this patch replaces all URI parameter
names with a lower-case version, and since all parameter name requests
are also done in lower-case, this effectively makes the mailto: handler
logic case-insensitive.
  • Loading branch information
dnet committed Nov 12, 2012
1 parent 900959c commit fb63515
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion src/com/fsck/k9/activity/MessageCompose.java
Original file line number Diff line number Diff line change
Expand Up @@ -3257,7 +3257,7 @@ private void initializeFromMailto(Uri mailtoUri) {
* creating a new hierarchical dummy Uri object with the query
* parameters of the original URI.
*/
Uri uri = Uri.parse("foo://bar?" + mailtoUri.getEncodedQuery());
Uri uri = Uri.parse("foo://bar?" + lowerCaseHfNames(mailtoUri.getEncodedQuery()));

// Read additional recipients from the "to" parameter.
List<String> to = uri.getQueryParameters("to");
Expand Down Expand Up @@ -3291,6 +3291,25 @@ private void initializeFromMailto(Uri mailtoUri) {
}
}

// Regex for URI parameter names
private static final Pattern QUERY_HFNAME = Pattern.compile("(?:^|&)([a-zA-Z]+)=");

/**
* Convert URI parameter names to lower case
* "foo=BaR&amp;Qux=BAZ&amp;ALLCAPS=lowcase" becomes "foo=BaR&amp;qux=BAZ&amp;allcaps=lowcase"
*
* @param encodedQuery
* URI-encoded parameter list string
*/
private String lowerCaseHfNames(String encodedQuery) {
final StringBuilder sb = new StringBuilder(encodedQuery);
final Matcher m = QUERY_HFNAME.matcher(sb);
while (m.find()) {
sb.replace(m.start(1), m.end(1), m.group(1).toLowerCase());
}
return sb.toString();
}

private class SendMessageTask extends AsyncTask<Void, Void, Void> {
@Override
protected Void doInBackground(Void... params) {
Expand Down

0 comments on commit fb63515

Please sign in to comment.