[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kmail-devel
Subject:    Re: new "kmail with PGP" error
From:       Andreas Gungl <a.gungl () gmx ! de>
Date:       2000-03-06 20:29:26
[Download RAW message or body]

Am Mon, 06 Mär 2000 schrieb Don Sanders:
>On Fri, 03 Mar 2000, Andreas Gungl wrote:
>> [...]
>> >just I got a message, which was encrypted by pgp. It was a multipart
>> >message, containing the info as plain text and html formatted.
>> >
>> >I guess, the default to display the message in kmail is to use the
>> >html formatted part. So kmail doesnīt realize, that the message is
>> >encrypted, since the "--- BEGIN PGP MESSAGE ---" is between html
>> >tags.
>> >
>> >I donīt know, at the moment, if pgp would handle the decryption of
>> >the html formatted message. And I donīt want to discuss about the
>> >sence of encrypted mails in multipart format.
>> >
>> >But I think, the parsing should become improved in kmail, so that the
>> >plain text part is determined as an encrypted messsage and is passed
>> >to kmail (and its result displayed in kmail).
>> >
>> >Any comments to this?
>
>kmreaderwin.cpp ...
>void KMReaderWin::parseMsg(KMMessage* aMsg) ...
>    for (i=0; i<numParts; i++) ...
>          if (stricmp(subtype, "html")==0)
>          { 
>            //DECODING NEEDED HERE
>	...
>            mViewer->write(str); //writes raw html
>          }
>          else writeBodyStr(str); 
>
>void KMReaderWin::writeBodyStr(const QString aStr)
>{
>  QString line, sig, htmlStr = "";
>  Kpgp* pgp = Kpgp::getKpgp();
>  assert(pgp != NULL);
>  //  assert(!aStr.isNull());
>  bool pgpMessage = false;
>
>  if (pgp->setMessage(aStr)) // message is pgp encrypted of signed
>  {
>   ...
>
>To fix this it would be necessary to handling decoding (like it is done in 
>writeBodyStr) at the place marked //DECODING NEEDED HERE. Or at least I think 
>that's the case.
>
>BFN,
>Don.

Hi,

Thank you for the hint about where to look for a solution. I donīt
understand the code completely. Doesnīt seem to be easy with handling
the parts. So I think, Sven is the one who should know this code best.

Here is just a hack which worked for me. (No complete and perfect
yet, but a first proposal.) The idea is, to look through all parts,
if there is a plain text part with a pgp encrypted message. If so,
this is the prefered part for displaying. Otherwise the prefered part
is the html one. (I personally would like a settings option about
which type of part to prefer.)

    // ---sven: handle multipart/alternative start ---
    // This is for multipart/alternative messages WITHOUT attachments
    // main header has type=multipart/alternative and one attachment is
    // text/html
    if (type.find("multipart/alternative") != -1 && numParts == 2)
    {
      debug("Alternative message, type: %s",type.data());
      //Now: Only two attachments one of them is html
      int part_to_use = 0;
      for (i=0; i<2; i++)                   // count parts...
      {
        aMsg->bodyPart(i, &msgPart);        // set part...
        subtype = msgPart.subtypeStr();     // get subtype...
        if (stricmp(subtype, "html")==0)    // is it html?
        {                                   // yes...
	  if (part_to_use)		    // use html, if no ppg
	   part_to_use = i;		    // part found before
        }
        else				    // no html part...
        {
          str = QCString(msgPart.bodyDecoded());	// decode it...
          if (str.find("BEGIN PGP MESSAGE") != -1)	// is pgp message?
            part_to_use = i;				// use this part
        }
      }                                     // end for.
      if (part_to_use)
      {
        aMsg->bodyPart(part_to_use, &msgPart);
        subtype = msgPart.subtypeStr();
        if (stricmp(subtype, "html")==0)    // is it html?
          mViewer->write(str);              // write it...
        else
          writeBodyStr(QCString(msgPart.bodyDecoded()));
        return;
      }
      // if we are here we didnt find any html part. Handle it normaly then
    }
    // This works only for alternative msgs without attachments. Alternative
    // messages with attachments are broken with or without this. No need
    // to bother with strib </body> or </html> here, because if any part
    // follows this will not be shown correctly. You'll still be able to read the
    // main message and deal with attachments. Nothing I can do now :-(
    // ---sven: handle multipart/alternative end ---

Please feel free to comment this idea. Sven, perhaps you could
continue this, if it isnīt complete nonsense. I think, you still have
some more ideas on how to improve the handling of the parts. As I
said, itīs my first look at this code and you are the more
experienced one.

BTW, itīs possible to send the whole contents of an encrypted
multipart mail to pgp 6.x because this version can handle mime
parts. It will decypt the plain text part and return that contents.
But I doubt, if the elder versions are able to handle this. (Canīt
test at the moment.) So I think, the way mentioned above is better.

Andreas

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic