Changeset 1790 for trunk/dll/newview.c


Ignore:
Timestamp:
Aug 31, 2014, 8:11:13 PM (11 years ago)
Author:
Gregg Young
Message:

Added isemailaddress to try to eliminate lines being falsely identified as containing an email. Fixed the mailto code to avoid a buffer over run (trap) and to cut trailing punctuation marks from the address. Tickets [543] & [544]

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/dll/newview.c

    r1781 r1790  
    4141  17 JAN 10 GKY Changes to get working with Watcom 1.9 Beta (1/16/10). Mostly cast CHAR CONSTANT * as CHAR *.
    4242  28 Jun 14 GKY Fix errors identified with CPPCheck Fix "mailto" failure to drop trailing >
     43  30 Aug 14 GKY Added isemailaddress to try to eliminate lines being falsely identified as
     44                containing an email. Fixed the mailto code to avoid a buffer over run (trap)
     45                and to cut trailing punctuation marks from the address
    4346
    4447***********************************************************************/
     
    4952#include <limits.h>
    5053#include <share.h>
     54#include <ctype.h>
    5155
    5256#define INCL_DOS
     
    199203//to the first word that contains the character then prepends <mailto: and appends >
    200204
     205BOOL isemailaddress(PSZ pszLine)
     206{
     207  CHAR *tmp;
     208  CHAR *p, *pp;
     209
     210  tmp = xmallocz(strlen(pszLine) + 1, pszSrcFile, __LINE__);
     211  if (!tmp)
     212    return FALSE;
     213  memcpy(tmp, pszLine, strlen(pszLine));
     214  tmp[strlen(pszLine) + 1] = 0;
     215  bstripcr(tmp);
     216  p = tmp;
     217  p++;
     218  p = strchr(p, '@');
     219  if (!p) {
     220    free(tmp);
     221    return FALSE;
     222  }
     223  pp = strchr(p, '.');
     224  if (!pp || pp - p < 2) {
     225    free(tmp);
     226    return FALSE;
     227  }
     228  p++;
     229  for (p ; p < pp; p++) {
     230    if (isalnum(*p) || *p == '-')
     231      continue;
     232    else if (*p == '{') {
     233      if (!strchr(p ,'}') || pp - p > 4) {
     234        free(tmp);
     235        return FALSE;
     236      }
     237    }
     238    else  {
     239      free(tmp);
     240      return FALSE;
     241    }
     242
     243  }
     244  free(tmp);
     245  return TRUE;
     246}
     247
    201248PSZ mailstr(CHAR *pszSrc, CHAR *pszFindChar, LONG StrLens)
    202249{
     
    240287  *pszCharCounter = 0;
    241288  if (!stristr(pszSrc, "<mailto:") && !fNoMailtoMailRun) {
    242     strip_lead_char("<", pszSrc);
    243     strip_trail_char(">", pszSrc);
     289    strip_lead_char("'<", pszSrc);
     290    strip_trail_char(",.;:'>", pszSrc);
    244291    strcat(szMailTo, pszSrc);
    245292    //strcat(szMailTo, szMailEnd);
     
    248295    }
    249296  else {
    250     strip_lead_char("<", pszSrc);
    251     strip_trail_char(">", pszSrc);
     297    strip_lead_char("'<", pszSrc);
     298    strip_trail_char(",.;':>", pszSrc);
    252299    return pszSrc;
    253300  }
     
    263310      CHAR *p, *e, *pp;
    264311      SHORT count;
    265       CHAR szUrlString[SEARCHSTRINGLEN];
     312      CHAR szUrlString[SEARCHSTRINGLEN] = {0};
    266313
    267314      WinSetWindowPtr(hwnd, QWL_USER, mp2);
     
    303350      while (p && *p && p < e);
    304351      p = urld->line;
    305       if (strchr(p, '@')) {
    306         strcpy(szUrlString, urld->line);
     352      if (isemailaddress(p)) {
     353        memcpy(szUrlString, urld->line, SEARCHSTRINGLEN - 1);
    307354        mailstr(szUrlString, "@", e - p);
    308         strcpy(urld->url, szUrlString);
     355        memcpy(urld->url, szUrlString, strlen( szUrlString) + 1);
     356        urld->url[strlen(szUrlString) + 1] = 0;
    309357        if (pp = strchr(urld->url, '>'))
    310358          *pp = 0;
     
    376424                }
    377425              }
    378               else if (strchr(urld->url, '@')) {
     426              else if (isemailaddress(urld->url)) {
    379427                  WinDismissDlg(hwnd, 3);
    380428                  break;
     
    13951443                  strstr(ad->text, "http://"))
    13961444                ad->httpin = TRUE;
    1397               if (*mailrun && !ad->ignoremail && strstr(ad->text, "@"))
     1445              if (*mailrun && !ad->ignoremail && isemailaddress(ad->text))
    13981446                ad->mailin = TRUE;
    13991447            }
     
    24542502              (ad->ftpin && (*ftprun || fFtpRunWPSDefault) &&
    24552503               strnstr(ad->lines[whichline], "ftp://", width)) ||
    2456               (ad->mailin && *mailrun && strchr(ad->lines[whichline], '@'))) {
     2504              (ad->mailin && *mailrun && isemailaddress(ad->lines[whichline]))) {
    24572505
    24582506            USHORT ret;
     
    33843432      ad->mailin = FALSE;
    33853433      if (ad->text && *mailrun && !ad->ignoremail &&
    3386           strstr(ad->text, "@"))
     3434          isemailaddress(ad->text))
    33873435        ad->mailin = TRUE;
    33883436      IgnoreMail = ad->ignoremail;
Note: See TracChangeset for help on using the changeset viewer.