Open Bug 28769 Opened 25 years ago Updated 13 years ago

Auto-complete server names based on e-mail address

Categories

(SeaMonkey :: MailNews: Account Configuration, enhancement)

enhancement
Not set
normal

Tracking

(Not tracked)

ASSIGNED

People

(Reporter: mpt, Assigned: iannbugzilla)

Details

Attachments

(1 file, 7 obsolete files)

This broke out of bug 28589.

When a user is entering the incoming and outgoing server names in the account 
manager, the fields should auto-complete based on the domain part of their e-mail 
address (which they have just entered in the previous page of the wizard).

For example, if I have entered my e-mail address as xyz@foo.bar, and I then start 
typing `imaphost.f' in the incoming mail server field, Mozilla should
auto-complete with `oo.bar'.
[Changing helpwanted flag to keyword, as per bug 28345.]
Keywords: helpwanted
Summary: [helpwanted] Auto-complete server names based on e-mail address → Auto-complete server names based on e-mail address
Attached patch Implemented via onkeyup() (obsolete) — Splinter Review
Adds a function that is triggered by keyup and autocompletes if possible.
Attached patch Corrected patch (obsolete) — Splinter Review
Only autocompletes on first char or after a '.' (correctly now).

Please make old patch obsolete.
Attachment #61694 - Attachment is obsolete: true
Updated against current trunk but for some reason doesn't work from chrome but
does from file
Attachment #61767 - Attachment is obsolete: true
Current patch has some diagnostic dumps in but they don't seem to generate
anything :-(
Attached patch Patch v1.1 (obsolete) — Splinter Review
Patch against AccountWizard.xul rather than aw-server.xul
Attachment #121822 - Attachment is obsolete: true
Reassigning to me
Assignee: nobody → ian
Accepting
Status: NEW → ASSIGNED
Keywords: helpwanted
Attachment #121826 - Flags: review?(neil)
Comment on attachment 121826 [details] [diff] [review]
Patch v1.1

>+  // only autocomplete on characters
>+  if (keyCode < 48)
>+    return true;
Better to test for a nonzero charCode.

>+  // only autocomplete on first char or after a '.'
Actually this code doesn't (and perhaps should not) complete on the first char,
since it only autocompletes if a '.' is found. You could use a do loop to test
the whole servername first.
>+
>+  var shortname = servername;
>+  var j = shortname.indexOf('.') + 1;
>+  while (j > 0 && j < shortname.length)
Perhaps you are trying not to autocomplete after a '.' is typed... even if
that's the intent you should still check charCode above.

>+  {
>+    shortname = shortname.substring(j, shortname.length);
Don't need 2nd parameter to substring here or elsewhere when all you want is
the rest of the string

>+    if (emailArray[1].substring(0, shortname.length) == shortname) {
Should this be a case-insensitive match? (lowercase the email address and
shortname before the loop)

>+      servernameElement.select();
Don't need this, you're setting the selection again
Attachment #121826 - Flags: review?(neil) → review-
If I was to check for non zero charCode I couldn't use onkeyup as that only
seems to generate zero charCodes I'd have to use onkeypress instead. That would
introduce it's own problems in that at the time of that event the character will
not have been added to the textbox. Updated function, keeping with onkeyup,
would look something like this:

function serverKeyup(keyCode, name)
{
  // only autocomplete on characters
  if (keyCode < 33 || keyCode > 126 || keyCode == 46)
    return true;

  var servernameElement = document.getElementById(name);
  var servername = servernameElement.value.toLowerCase();

  var pageData = parent.GetPageData();
  var emailArray = pageData.identity.email.value.split('@');
  var email = emailArray[1].toLowerCase();

  // only autocomplete on first char after a '.'

  var shortname = servername;
  var j = shortname.indexOf('.') + 1;
  while (j > 0 && j < shortname.length)
  {
    shortname = shortname.substring(j);
    if (email.substring(0, shortname.length) == shortname) {
      servernameElement.value = servername + email.substring(shortname.length);
      servernameElement.selectionStart = servername.length;
      servernameElement.selectionEnd = servernameElement.value.length;
      return true;
    }
    j = shortname.indexOf('.') + 1;
  }

  return true;
}
Attachment #121826 - Attachment is obsolete: true
Attached patch Patch v1.3 (obsolete) — Splinter Review
Goes back to the do loop structure of James' original patch
Attachment #122512 - Attachment is obsolete: true
Attachment #122515 - Flags: review?(neil.parkwaycc.co.uk)
Comment on attachment 122515 [details] [diff] [review]
Patch v1.3

I'm not sure you don't want to autocomplete after a "." - say my email was
pov@bbc.co.uk then after I'd typed mail.bbc. I'd expect to see "co.uk"
autocompleted.

I've peeked into how "regular" autocomplete does it, it uses an onkeypress to
save the last key and an oninput to do the dirty work.

Also, I don't see the point of passing an id to serverKeyup when you can pass
the element itself (in the inline event handler the "this" keyword refers to
it).
Attachment #122515 - Flags: review?(neil.parkwaycc.co.uk)
this seems to be [object ChromeWindow] when called from onkeypress, is that right?
Autocomplete seems to work as you suggested already.
I was wondering why you tested for key == 46 (I haven't had time to try it).

The meaning of "this" depends on context - in <element
onkeyup="doSomething(this);"> it's the element, but in function doSomething(arg)
{ dump(arg); dump(this); } it's the window.
Comment on attachment 122515 [details] [diff] [review]
Patch v1.3

>+  // only autocomplete on characters
>+  if (keyCode < 33 || keyCode > 126 || keyCode == 46)
>+    return true;
>+
>+  var servernameElement = document.getElementById(name);
>+  var servername = servernameElement.value.toLowerCase();
>+
>+  var pageData = parent.GetPageData();
>+  var emailArray = pageData.identity.email.value.split('@');
>+  var email = emailArray[1].toLowerCase();
>+
>+  // only autocomplete on first char or after a '.'
Except you don't autocomplete after a '.' because you exclude it above :-(
Attachment #122515 - Flags: review-
+  // only autocomplete on characters
+  if (keyCode < 33 || keyCode > 126 || keyCode == 46)
+    return true;

these are just magic numbers to me. What do they refer to? Looks like non-ascii
characters, so what do you do for non-ASCII based languages? What happens in
japanese? 
(and yes, hostnames can be internationalized, a la iDNS and such, which we support)
Attached patch Patch 1.3a (obsolete) — Splinter Review
Element is now passed using 'this' and keycodes less than 33 are the only ones
ignored.
Attachment #122515 - Attachment is obsolete: true
what special signifigance does "33" hold? I'm not doubting the signifigance of
control characters, but your code ought to be self-documenting here - offhand I
know that "32" is a space character, but 33 is just a magic number to me. You
shoudl use some of the DOM constants if you're going to be checking this kind of
thing.
Looking at changing those lines to:

+  // don't autocomplete when non character keys (e.g. tab or delete) are pressed
+  if (keyCode <= KeyEvent.DOM_VK_DELETE || keyCode == KeyEvent.DOM_VK_META ||
+     (keyCode >= KeyEvent.DOM_VK_F1 && keyCode <= KeyEvent.DOM_VK_SCROLL_LOCK))
+    return true;

Less magic numbery?
yes, this is exactly what I was referring to! thanks.
Attached patch Patch v1.3bSplinter Review
Revised patch checking for DOM_VK rather than 'magic' numbers.
Attachment #122793 - Attachment is obsolete: true
Attachment #122957 - Flags: review?(neil.parkwaycc.co.uk)
Attachment #122957 - Flags: review?(neil.parkwaycc.co.uk) → review+
Attachment #122957 - Flags: superreview?(sspitzer)
Target Milestone: --- → mozilla1.4final
Attachment #122957 - Flags: superreview?(sspitzer) → superreview?(dmose)
Comment on attachment 122957 [details] [diff] [review]
Patch v1.3b

sr=dmose@mozilla.org
Attachment #122957 - Flags: superreview?(dmose) → superreview+
Attachment #122957 - Flags: approval1.4?
Comment on attachment 122957 [details] [diff] [review]
Patch v1.3b

since this is mail, I'd prefer to give the a (and test this.)

I want to test, because I'm a little nervous about doing home grown
autocomplete here.

for example, it isn't on a timer, which leads to a bad experience.

let me test and review before approval, ok?
Attachment #122957 - Flags: approval1.4?
Comment on attachment 122957 [details] [diff] [review]
Patch v1.3b

in addition to dmose's review, I'd like to review as well.

so making an official request.
Attachment #122957 - Flags: superreview+ → superreview?(sspitzer)
Product: Browser → Seamonkey
Ian, sspitzer,
Are you still working on this ?
Waiting for some sort of super-review, I suspect at some point I'll be asked to tweak the patch.
Priority: P3 → --
QA Contact: lchiang → nobody
Target Milestone: mozilla1.4final → ---
Iann comment #27
> Waiting for some sort of super-review, I suspect at some point I'll be asked to
> tweak the patch.

sr from spitzer?
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: