Switch to unified view

a/src/internfile/mh_mail.cpp b/src/internfile/mh_mail.cpp
1
#ifndef lint
1
#ifndef lint
2
static char rcsid[] = "@(#$Id: mh_mail.cpp,v 1.5 2005-04-06 10:20:11 dockes Exp $ (C) 2005 J.F.Dockes";
2
static char rcsid[] = "@(#$Id: mh_mail.cpp,v 1.6 2005-10-15 12:18:04 dockes Exp $ (C) 2005 J.F.Dockes";
3
#endif
3
#endif
4
4
5
#include <stdio.h>
5
#include <stdio.h>
6
#include <fcntl.h>
6
#include <fcntl.h>
7
#include <errno.h>
7
#include <errno.h>
...
...
170
    LOGERR(("MimeHandlerMail::processone: mime parse error for %s\n", 
170
    LOGERR(("MimeHandlerMail::processone: mime parse error for %s\n", 
171
        fn.c_str()));
171
        fn.c_str()));
172
    return MimeHandler::MHError;
172
    return MimeHandler::MHError;
173
    }
173
    }
174
174
175
    // Handle some headers. We should process rfc2047 encoding here
175
    // Handle some headers. 
176
    // Also there should be no 8bit chars, but there sometimes are. So
177
    // we transcode as if from iso-8859-1, which is better than
178
    // getting utf8 conversion errors later on
179
    Binc::HeaderItem hi;
176
    Binc::HeaderItem hi;
180
    string transcoded;
177
    string transcoded;
181
    if (doc.h.getFirstHeader("Subject", hi)) {
178
    if (doc.h.getFirstHeader("Subject", hi)) {
182
  transcode(hi.getValue(), transcoded, "iso-8859-1", "UTF-8");
179
  rfc2047_decode(hi.getValue(), transcoded);
183
    docout.title = transcoded;
180
    docout.title = transcoded;
184
    }
181
    }
185
    if (doc.h.getFirstHeader("From", hi)) {
182
    if (doc.h.getFirstHeader("From", hi)) {
186
  transcode(hi.getValue(), transcoded, "iso-8859-1", "UTF-8");
183
  rfc2047_decode(hi.getValue(), transcoded);
187
    docout.text += string("From: ") + transcoded + string("\n");
184
    docout.text += string("From: ") + transcoded + string("\n");
188
    }
185
    }
189
    if (doc.h.getFirstHeader("To", hi)) {
186
    if (doc.h.getFirstHeader("To", hi)) {
190
  transcode(hi.getValue(), transcoded, "iso-8859-1", "UTF-8");
187
  rfc2047_decode(hi.getValue(), transcoded);
191
    docout.text += string("To: ") + transcoded + string("\n");
188
    docout.text += string("To: ") + transcoded + string("\n");
192
    }
189
    }
193
    if (doc.h.getFirstHeader("Date", hi)) {
190
    if (doc.h.getFirstHeader("Date", hi)) {
194
  transcode(hi.getValue(), transcoded, "iso-8859-1", "UTF-8");
191
  rfc2047_decode(hi.getValue(), transcoded);
192
  // Try to set the mtime from the date field.
193
  string date = transcoded;
194
  string::size_type pos;
195
  // Possibly get rid of the day
196
  if ((pos = date.find(",")) != string::npos)
197
      date = date.substr(pos+1);
198
  struct tm tm;
199
  if (strptime(date.c_str(), " %d %b %Y %H:%M:%S %z ", &tm)) {
200
      char ascuxtime[100];
201
      sprintf(ascuxtime, "%ld", (long)mktime(&tm));
202
      docout.mtime = ascuxtime;
203
  } else {
204
      LOGDEB(("strptime failed for [%s]\n", date.c_str()));
205
  }
206
195
    docout.text += string("Date: ") + transcoded + string("\n");
207
    docout.text += string("Date: ") + transcoded + string("\n");
196
    }
208
    }
197
    if (doc.h.getFirstHeader("Subject", hi)) {
209
    if (doc.h.getFirstHeader("Subject", hi)) {
198
  transcode(hi.getValue(), transcoded, "iso-8859-1", "UTF-8");
210
  rfc2047_decode(hi.getValue(), transcoded);
199
    docout.text += string("Subject: ") + transcoded + string("\n");
211
    docout.text += string("Subject: ") + transcoded + string("\n");
200
    }
212
    }
201
213
202
    LOGDEB2(("MimeHandlerMail::processone: ismultipart %d mime subtype '%s'\n",
214
    LOGDEB2(("MimeHandlerMail::processone: ismultipart %d mime subtype '%s'\n",
203
        doc.isMultipart(), doc.getSubType().c_str()));
215
        doc.isMultipart(), doc.getSubType().c_str()));