Bug 117882 - Cannot send to addresses containing an ampersand (&)
Summary: Cannot send to addresses containing an ampersand (&)
Status: RESOLVED FIXED
Alias: None
Product: kmail
Classification: Unmaintained
Component: general (show other bugs)
Version: 1.9
Platform: Gentoo Packages Linux
: NOR normal
Target Milestone: ---
Assignee: kdepim bugs
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-12-07 19:00 UTC by Robert Clark
Modified: 2007-09-14 12:17 UTC (History)
0 users

See Also:
Latest Commit:
Version Fixed In:
Sentry Crash Report:


Attachments
Suggested fix from Magnus as applied to kmail/kmsender.cpp on the HEAD branch (806 bytes, patch)
2006-08-05 02:15 UTC, Robert Clark
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Robert Clark 2005-12-07 19:00:30 UTC
Version:           1.9 (using KDE KDE 3.5.0)
Installed from:    Gentoo Packages
Compiler:          gcc version 3.4.4 (Gentoo 3.4.4-r1, ssp-3.4.4-1.0, pie-8.7.8) 
OS:                Linux

Starting with KMail 1.9 (KDE 3.5.0) I can no longer send email to addresses containing an ampersand (&).

The geniuses that set up the email system here decided that addresses like:

   TheName&TheValue@example.com

were a good idea. Previously, KMail 1.8.x (KDE 3.4.x) was able to send to these addresses. Now I get a 
bounce from the email server:

   This is an automatically generated Delivery Status Notification.

   Delivery to the following recipients failed.

       TheName@example.com

where "&TheValue" has been dropped from the email address. Since the mail server is MS Exchange, I can't
get a more detailed error message.

I am able to send email to the address when I telnet into the mail server and execute the MAIL FROM/RCPT TO 
commands manually.

I don't know enough about KMail to get it to print out debugging traces, but am more than willing to do
so if someone can point me at the instructions.
Comment 1 Frans Flippo 2006-03-30 08:21:06 UTC
I get the same thing with an address K&H&L@somedomain.nl. According to RFC822, & is not a special character and should be treated exactly as any other alphanumeric character. It looks like kmail treats it specially.
Bug still exists in kmail 1.9.1.
Comment 2 benjamin fry 2006-04-07 19:41:04 UTC
I was able to confirm that this happens with other smtp servers, not just exchange (tested against mac.com and postfix in my own domain).
Comment 3 Lloyd Osten 2006-06-01 04:38:36 UTC
this bug is still in Kmail 1.9.1 on KDE 3.5.2 (linux)

I got the following info from my ISP...

lloyd osten wrote:
> On Monday 29 May 2006 13:30, you wrote:
> 
>>Hi Lloyd,
>>
>>Can you forward me the bounce message you are getting when trying
>>to send to Losurs.  I'll have a look at it, and get back to you
>>with what's up.
> 
> 
> Just as I clicked send on this new message, the following error 
> appeared:
> 
> Message sending failed since the following recipients were rejected by 
> the server q (The server responded "5.1.1 <q>...user unknown"
> 

Hi Lloyd,

We found this in the logs of our mail server:

May 30 06:34:27 mailout1 sendmail[20825]: k4UCYMqf020825: 
from=<lloyd.osten@accesscomm.ca>, size=348, class=0, nrcpts=0, 
proto=ESMTP, daemon=MTA, relay=static24-72-63-103.regina.accesscomm.ca 
[24.72.63.103]
May 30 06:34:27 mailout1 sendmail[20825]: k4UCYMqf020825: <q>... User 
unknown

 From what we can guess, it would appear that your kmail is doing 
something weird with the & symbol in q&a@losurs.org.  It seems to be 
stripping everything after the q, so you are left with the above error 
message.  Here's a post that seem to refer to the same problem:

http://linux.derkeiler.com/Mailing-Lists/KDE/2006-01/msg00301.html

Ultimately, I'd say you file a bug report, or check out another client.
Comment 4 Magnus Holmgren 2006-06-02 23:21:07 UTC
The problem is here, in kmsender.cpp:

bool KMSendSMTP::doSend( const QString & sender, const QStringList & to, const QStringList & cc, const QStringList & bcc, const QCString & message ) {
  QString query = "headers=0&from=";
  query += KURL::encode_string( sender );

  if ( !to.empty() )
    query += "&to=" + to.join( "&to=" );
  if ( !cc.empty() )
    query += "&cc=" + cc.join( "&cc=" );
  if ( !bcc.empty() )
    query += "&bcc=" + bcc.join( "&bcc=" );

The recipients need some KURL::encode_string()-ing too, not just the sender!
Comment 5 Magnus Holmgren 2006-06-02 23:58:38 UTC
Is this the shortest replacement?

  QString query = "headers=0&from=";
  QStringList::Iterator it;
  query += KURL::encode_string( sender );

  for ( it = to.begin(); it != to.end(); ++it )
    query += "&to=" + KURL::encode_string(*it);
  for ( it = cc.begin(); it != cc.end(); ++it )
    query += "&cc=" + KURL::encode_string(*it);
  for ( it = bcc.begin(); it != bcc.end(); ++it )
    query += "&bcc=" + KURL::encode_string(*it);
Comment 6 benjamin fry 2006-06-03 00:11:32 UTC
that looks good to me, but this is only based on the code you have put up here.

I think I'm going to patch my local version.
Comment 7 Robert Clark 2006-08-05 02:15:15 UTC
Created attachment 17234 [details]
Suggested fix from Magnus as applied to kmail/kmsender.cpp on the HEAD branch
Comment 8 Allen Winter 2006-08-09 15:36:51 UTC
SVN commit 571372 by winterz:

Fix for the bug "Cannot send to addresses containing an ampersand".
Thanks for the patch Magnus and Robert.
Approved by Ingo.

BUG: 117882


 M  +12 -10    kmsender.cpp  


--- branches/KDE/3.5/kdepim/kmail/kmsender.cpp #571371:571372
@@ -173,7 +173,7 @@
   }
 
   //Ensure the message is correctly and fully parsed
-  
+
   /* The above was added by Marc and seems to be necessary to ensure
    * the mail is in a sane state before sending. The unGet makes the
    * attached unencrypted version of the mail (if there is one ) disappear.
@@ -331,10 +331,10 @@
         imapSentFolder =
           kmkernel->imapFolderMgr()->findIdString( mCurrentMsg->fcc() );
     }
-    // No, or no usable sentFolder, and no, or no usable imapSentFolder, 
+    // No, or no usable sentFolder, and no, or no usable imapSentFolder,
     // let's try the on in the identity
     if ( ( sentFolder == 0 || sentFolder->isReadOnly() )
-      && ( imapSentFolder == 0 || imapSentFolder->isReadOnly() ) 
+      && ( imapSentFolder == 0 || imapSentFolder->isReadOnly() )
       && !id.fcc().isEmpty() )
     {
       sentFolder = kmkernel->folderMgr()->findIdString( id.fcc() );
@@ -600,7 +600,7 @@
   QStringList to, cc, bcc;
   QString sender;
   extractSenderToCCAndBcc( mCurrentMsg, &sender, &to, &cc, &bcc );
-  
+
   // MDNs are required to have an empty envelope from as per RFC2298.
   if ( messageIsDispositionNotificationReport( mCurrentMsg ) && GlobalSettings::self()->sendMDNsWithEmptySender() )
     sender = "<>";
@@ -1052,13 +1052,15 @@
   QString query = "headers=0&from=";
   query += KURL::encode_string( sender );
 
-  if ( !to.empty() )
-    query += "&to=" + to.join( "&to=" );
-  if ( !cc.empty() )
-    query += "&cc=" + cc.join( "&cc=" );
-  if ( !bcc.empty() )
-    query += "&bcc=" + bcc.join( "&bcc=" );
+  QStringList::ConstIterator it;
 
+  for ( it = to.begin(); it != to.end(); ++it )
+    query += "&to=" + KURL::encode_string(*it);
+  for ( it = cc.begin(); it != cc.end(); ++it )
+    query += "&cc=" + KURL::encode_string(*it);
+  for ( it = bcc.begin(); it != bcc.end(); ++it )
+    query += "&bcc=" + KURL::encode_string(*it);
+
   KMTransportInfo * ti = mSender->transportInfo();
 
   if ( ti->specifyHostname )