3.13. How do I remove a user name or email address with an illegal character in it (or Mixed or Upper case domain)?

This sort of thing might result in a subscriber address being corrupted, and errors like this:

Traceback (most recent call last):

  File "/usr/local/mailman/scripts/driver", line 87, in run_main
    main()
  File "/usr/local/mailman/Mailman/Cgi/admin.py", line 198, in main
    show_results(mlist, doc, category, subcat, cgidata)
  File "/usr/local/mailman/Mailman/Cgi/admin.py", line 501, in show_results
    form.AddItem(membership_options(mlist, subcat, cgidata, doc, form))
  File "/usr/local/mailman/Mailman/Cgi/admin.py", line 873, in membership_options
    all = [_m.encode() for _m in mlist.getMembers()]
  UnicodeDecodeError: 'ascii' codec can't decode byte 0xa0 in position 22: ordinal not in range(128)

Before trying the method(s) below, first try

 % bin/list_members -i listname

If that lists the addresses you want removed, try

 % bin/list_members -i listname | bin/remove_members -f - listname

Note that this won't work if the invalid address contains leading or trailing whitespace. In that case, use the withlist removeMember() method described below or use the withlist script at http://www.msapiro.net/scripts/remove_bad_address.py (mirrored at http://fog.ccsf.cc.ca.us/~msapiro/scripts/remove_bad_address.py).

To fix this, try using bin/withlist.

If you have a bad address such as "na,me@example.com" that should be corrected to "name@example.com" you would do the following:

 % bin/withlist -l mylist
 >>> m.removeMember('na,me@example.com')
 >>> m.Save()
 >>> ^D

You may use C-style escapes, as well: m.removeMember("\r\nname@example.com")

This is the preferred method since it cleans out any other information in the database associated with the bogus address, but if it raises exceptions and doesn't remove the member you should do one of the following (and submit a bug report!)

If the member is a regular member

 % bin/withlist -l mylist
 >>> del m.members['na,me@example.com']
 >>> m.Save()
 >>> ^D

If the member is a digest member

 % bin/withlist -l mylist
 >>> del m.digest_members['na,me@example.com']
 >>> m.Save()
 >>> ^D

Email addresses may only contain ASCII characters. Older versions of Mailman allowed non-ASCII characters as email addresses sometimes. This has since been fixed, but some older lists may have bogus addresses in them. Here's a command line recipe that might help clear all of these out:

 % bin/find_member -l listname "[^\w\-+@.%]" > file

This will give you an list of bad addresses, but you will need to edit the list to remove language such as 'found in', etc to make it only a list of email addresses that can be used by the following command:

 % bin/remove_members -f file listname

Also, you may need to adjust the regular expression used by find_member.

If you are told when trying to remove the invalid members that the invalid members do not exist, instead of saving the invalid members to a file first which can cause problems with some invalid characters, you can use a pipe to do this in one step:

 % bin/list_members -i listname | bin/remove_members -f - listname

If the above methods don't work, you can try

 % bin/list_members -f listname | grep -v -e 'pattern' | bin/sync_members -f - listname

where listname is the name of the list and pattern is a pattern that will match the bad address. Alternatively, you can direct the output of bin/list_members to a file, edit the file to remove the unwanted address(es) and than use it as input to bin/sync_members.


Prior to Mailman 2.1.10, there was a bug that affected addresses of the form lower_case_user@Mixed_or_UPPER_case_domain. If you have such addresses on a list and they can't be removed, there is a withlist script to fix the problem at http://www.msapiro.net/scripts/fix_uc_address.py (mirrored at http://fog.ccsf.cc.ca.us/~msapiro/scripts/fix_uc_address.py).

Converted from the Mailman FAQ Wizard

This is one of many Frequently Asked Questions.

MailmanWiki: DOC/How do I remove a user name or email address with an illegal character in it (or Mixed or Upper case domain)? (last edited 2011-05-14 15:49:25 by msapiro)