Print this page
    
8485 Remove set but unused variables in usr/src/cmd
    
      
        | Split | Close | 
      | Expand all | 
      | Collapse all | 
    
    
          --- old/usr/src/cmd/mail/copylet.c
          +++ new/usr/src/cmd/mail/copylet.c
   1    1  /*
   2    2   * CDDL HEADER START
   3    3   *
   4    4   * The contents of this file are subject to the terms of the
   5    5   * Common Development and Distribution License, Version 1.0 only
   6    6   * (the "License").  You may not use this file except in compliance
   7    7   * with the License.
   8    8   *
   9    9   * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
  10   10   * or http://www.opensolaris.org/os/licensing.
  11   11   * See the License for the specific language governing permissions
  12   12   * and limitations under the License.
  
    | ↓ open down ↓ | 12 lines elided | ↑ open up ↑ | 
  13   13   *
  14   14   * When distributing Covered Code, include this CDDL HEADER in each
  15   15   * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  16   16   * If applicable, add the following below this CDDL HEADER, with the
  17   17   * fields enclosed by brackets "[]" replaced with your own identifying
  18   18   * information: Portions Copyright [yyyy] [name of copyright owner]
  19   19   *
  20   20   * CDDL HEADER END
  21   21   */
  22   22  /*
       23 + * Copyright 2017 Gary Mills
  23   24   * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
  24   25   * Use is subject to license terms.
  25   26   */
  26   27  
  27   28  /*      Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
  28   29  /*        All Rights Reserved   */
  29   30  
  30      -#pragma ident   "%Z%%M% %I%     %E% SMI"
  31      -
  32   31  #include "mail.h"
  33   32  
  34   33  /*
  35   34      NAME
  36   35          copylet - copy a given letter to a file pointer
  37   36  
  38   37      SYNOPSIS
  39   38          int copylet(int letnum, FILE *f, int type)
  40   39  
  41   40      DESCRIPTION
  42   41          Copylet() will copy the letter "letnum" to the
  43   42          given file pointer.
  44   43  
  45   44                  letnum  -> index into: letter table
  46   45                  f       -> file pointer to copy file to
  47   46                  type    -> copy type
  48   47  
  49   48          Returns TRUE on a completely successful copy.
  50   49  */
  51   50  
  52   51  int
  53   52  copylet(int letnum, FILE *f, int type) 
  54   53  {
  55   54          int             pos = ftell(f);
  56   55          int             rc  = xxxcopylet(letnum, f, type);
  57   56  
  58   57          if (fflush(f) != 0)
  59   58                  rc = FALSE;
  60   59          
  61   60          /*
  62   61           * On error, truncate the file to its original position so that a
  63   62           * partial message is not left in the mailbox.
  64   63           */
  65   64          if (rc == FALSE)
  66   65                  ftruncate(fileno(f), pos);
  67   66  
  68   67          return(rc);
  69   68  }
  70   69  
  71   70  int
  72   71  xxxcopylet(int letnum, FILE *f, int type) 
  73   72  {
  74   73          static char     pn[] = "copylet";
  75   74          char    buf[LSIZE], lastc;
  76   75          char    wbuf[LSIZE];
  77   76          int     n;
  78   77          long    i, k;
  79   78          int     num;
  80   79          int     rtrncont = 1;   /* True: nondelivery&content included, or regular mail */
  81   80          int     suppress = FALSE;
  82   81          int     sav_suppress = FALSE; /* Did we suppress previous hdr line? */
  
    | ↓ open down ↓ | 41 lines elided | ↑ open up ↑ | 
  83   82          int     print_from_struct = FALSE; /* print from hdrlines struct */
  84   83                                             /* rather than fgets() buffer */
  85   84          int     pushrest = FALSE;
  86   85          int     ctf = FALSE;
  87   86          int     didafflines = FALSE;    /* Did we already put out any */
  88   87                                          /* H_AFWDFROM lines? */
  89   88          int     didrcvlines = FALSE;    /* Did we already put out any */
  90   89                                          /* H_RECEIVED lines? */
  91   90          long    clen = -1L;
  92   91          int     htype;                  /* header type */
  93      -        int     sav_htype;      /* Header type of last non-H_CONT header line */
  94   92          struct hdrs *hptr;
  95   93  
  96   94          if (!sending) {
  97   95                  /* Clear out any saved header info from previous message */
  98   96                  clr_hinfo();
  99   97          }
 100   98  
 101   99          fseek(tmpf, let[letnum].adr, 0);
 102  100          /* Get size of message as stored into tempfile by copymt() */
 103  101          k = let[letnum+1].adr - let[letnum].adr;
 104  102          Dout(pn, 1, "(letnum = %d, type = %d), k = %ld\n", letnum, type, k);
 105  103          while (k>0) {   /* process header */
 106  104                  num = ((k < sizeof(buf)) ? k+1 : sizeof(buf));
 107  105                  if (fgets (buf, num, tmpf) == NULL) {
 108  106                          return (FALSE);
 109  107                  }
 110  108                  if ((n = strlen (buf)) == 0) {
 111  109                          k = 0;
 112  110                          break;
 113  111                  }
 114  112                  k -= n;
 115  113                  lastc = buf[n-1];
 116  114                  if (pushrest) {
 117  115                          pushrest = (lastc != '\n');
 118  116                          continue;
 119  117                  }
 120  118                  htype = isheader (buf, &ctf);
 121  119                  Dout(pn, 5, "loop 1: buf = %s, htype= %d/%s\n", buf, htype, header[htype].tag);
 122  120                  if (htype == H_CLEN) {
 123  121                          if (!sending) {
 124  122                                  savehdrs(buf,htype);
 125  123                          }
 126  124                          if ((hptr = hdrlines[H_CLEN].head) !=
 127  125                              (struct hdrs *)NULL) {
 128  126                                  clen = atol (hptr->value);
 129  127                          }
 130  128                  }
 131  129                  if (type == ZAP) {
 132  130                          if (htype != FALSE) {
 133  131                                  pushrest = (lastc != '\n');
 134  132                                  continue;
 135  133                          }
 136  134                          /* end of header.  Print non-blank line and bail. */
 137  135                          Dout(pn, 5, "ZAP end header; n=%d, buf[0] = %d\n", n, buf[0]);
 138  136                          if (buf[0] != '\n') {
 139  137                                  if (fwrite(buf,1,n,f) != n) {
 140  138                                          sav_errno = errno;
 141  139                                          return(FALSE);
 142  140                                  }
 143  141                          } else {
 144  142                                  n = 0;
 145  143                          }
 146  144                          break;
 147  145                  }
 148  146                  /* Copy From line appropriately */
 149  147                  if (fwrite(buf,1,n-1,f) != n-1)  {
 150  148                          sav_errno = errno;
 151  149                          return(FALSE);
 152  150                  }
 153  151                  if (lastc != '\n') {
 154  152                          if (fwrite(&lastc,1,1,f) != 1) {
 155  153                                  sav_errno = errno;
 156  154                                  return(FALSE);
 157  155                          }
 158  156                          continue;
 159  157                  }
 160  158                  switch(type) {
 161  159                          case REMOTE:
 162  160                                  if (fprintf(f, rmtmsg, thissys) < 0)
 163  161                                  {
 164  162                                          sav_errno = errno;
 165  163                                          return(FALSE);
 166  164                                  }
 167  165                                  
 168  166                                  break;
 169  167  
 170  168                          case TTY:
 171  169                          case ORDINARY:
 172  170                          default:
 173  171                                  if (fprintf(f, "\n") < 0)
 174  172                                  {
 175  173                                          sav_errno = errno;
 176  174                                          return(FALSE);
 177  175                                  }
 178  176                                  break;
 179  177                  }
 180  178                  if ((error > 0) && (dflag == 1)) {
 181  179                          Dout(pn, 3, "before gendeliv(), uval = '%s'\n", uval);
 182  180                          gendeliv(f, dflag, uval);
 183  181                          if (!(ckdlivopts(H_TCOPY, (int*)0) & RETURN)) {
 184  182                                  rtrncont = 0;
 185  183                          } else {
 186  184                                  /* Account for content-type info */
 187  185                                  /* of returned msg */
 188  186                                  if (fprintf(f, "%s %s\n", header[H_CTYPE].tag,
 189  187                                      (let[letnum].text == TRUE ? "text/plain" : "application/octet-stream")) < 0)
 190  188                                  {
 191  189                                          sav_errno = errno;
 192  190                                          return(FALSE);
 193  191                                  }
 194  192  
 195  193                                  /* Compute Content-Length of what's being */
 196  194                                  /* returned... */
 197  195                                  i = k;
 198  196                                  /* Account for H_AFWDFROM, H_AFWDCNT, */
 199  197                                  /* H_TCOPY, or H_RECEIVED lines which may */
 200  198                                  /* be added later */
 201  199                                  if (affcnt > 0) {
 202  200                                          sprintf(wbuf, "%d", affcnt);
 203  201                                          i += (affbytecnt
 204  202                                                  + strlen(header[H_AFWDCNT].tag)
 205  203                                                  + strlen(wbuf) + 2);
 206  204                                  }
 207  205                                  if (orig_tcopy) {
 208  206                                      if ((hptr = hdrlines[H_TCOPY].head) !=
 209  207                                                          (struct hdrs *)NULL) {
 210  208                                          i +=
 211  209                                            strlen(hdrlines[H_TCOPY].head->value);
 212  210                                      }
 213  211                                  }
 214  212                                  if ((hptr = hdrlines[H_RECEIVED].head) !=
 215  213                                                          (struct hdrs *)NULL) {
 216  214                                      i += rcvbytecnt;
 217  215                                  }
 218  216                                  /* Add in strlen of MIME-Version:, */
 219  217                                  /* Content-Length: and Content-Type: */
 220  218                                  /* values for msg being returned... */
 221  219                                  if ((hptr = hdrlines[H_MIMEVERS].head) !=
 222  220                                                          (struct hdrs *)NULL) {
 223  221                                      i += strlen(hdrlines[H_MIMEVERS].head->value);
 224  222                                  }
 225  223                                  if ((hptr = hdrlines[H_CTYPE].head) !=
 226  224                                                          (struct hdrs *)NULL) {
 227  225                                      i += strlen(hdrlines[H_CTYPE].head->value);
 228  226                                  }
 229  227                                  if ((hptr = hdrlines[H_CLEN].head) !=
 230  228                                                          (struct hdrs *)NULL) {
 231  229                                      i += strlen(hdrlines[H_CLEN].head->value);
 232  230                                  }
 233  231                                  if (fprintf(f, "%s %ld\n", header[H_CLEN].tag, i) < 0)
 234  232                                  {
 235  233                                          sav_errno = errno;
 236  234                                          return(FALSE);
 237  235                                  }
 238  236                          }
 239  237                          if (fprintf(f, "\n") < 0)
 240  238                          {
 241  239                                  sav_errno = errno;
 242  240                                  return(FALSE);
 243  241                          }
 244  242                  }
 245  243                  if (fflush(f))
 246  244                  {
 247  245                          sav_errno = errno;
 248  246                          return(FALSE);
 249  247                  }
 250  248                  
 251  249                  break;
 252  250          }
 253  251          /* if not ZAP, copy balance of header */
 254  252          n = 0;
 255  253          if ((type != ZAP) && rtrncont)
 256  254                  while (k>0 || n>0) {
 257  255                          if ((n > 0) && !suppress) {
 258  256                                  if (print_from_struct == TRUE) {
 259  257                                          if (printhdr (type, htype, hptr, f) < 0) {
 260  258                                                  return (FALSE);
 261  259                                          }
 262  260                                  } else {
 263  261                                      if (sel_disp(type, htype, buf) >= 0) {
 264  262                                          if (fwrite(buf,1,n,f) != n)  {
 265  263                                                  sav_errno = errno;
 266  264                                                  return(FALSE);
 267  265                                          }
 268  266                                      }
 269  267                                  }
 270  268                                  if (htype == H_DATE) {
 271  269                                          dumprcv(type, htype,&didrcvlines,&suppress,f);
 272  270                                          dumpaff(type, htype,&didafflines,&suppress,f);
 273  271                                  }
 274  272                          }
 275  273                          if (k <= 0) {
 276  274                                  /* Can only get here if k=0 && n>0, which occurs */
 277  275                                  /* in a message with header lines but no content. */
 278  276                                  /* If we haven't already done it, force out any */
 279  277                                  /* H_AFWDFROM or H_RECEIVED lines */
 280  278                                  dumprcv(type, -1,&didrcvlines,&suppress,f);
 281  279                                  dumpaff(type, -1,&didafflines,&suppress,f);
 282  280                                  break;
 283  281                          }
 284  282                          num = ((k < sizeof(buf)) ? k+1 : sizeof(buf));
 285  283                          if (fgets (buf, num, tmpf) == NULL) {
 286  284                                  return (FALSE);
 287  285                          }
 288  286                          n = strlen (buf);
  
    | ↓ open down ↓ | 185 lines elided | ↑ open up ↑ | 
 289  287                          k -= n;
 290  288                          lastc = buf[n-1];
 291  289  
 292  290                          if (pushrest) {
 293  291                                  pushrest = (lastc != '\n');
 294  292                                  continue;
 295  293                          }
 296  294                          sav_suppress = suppress;
 297  295                          suppress = FALSE;
 298  296                          print_from_struct = FALSE;
 299      -                        sav_htype = htype;
 300  297                          htype = isheader (buf, &ctf);
 301  298                          Dout(pn, 5, "loop 2: buf = %s, htype= %d/%s\n", buf, htype, header[htype].tag);
 302  299                          /* The following order is defined in the MTA documents. */
 303  300                          switch (htype) {
 304  301                          case H_CONT:
 305  302                              if (sending) {
 306  303                                  suppress = sav_suppress;
 307  304                              }
 308  305                              continue;
 309  306                          case H_TCOPY:
 310  307                          case H_MIMEVERS:
 311  308                          case H_CTYPE:
 312  309                          case H_CLEN:
 313  310                                  if (!sending) {
 314  311                                          savehdrs(buf,htype);
 315  312                                  }
 316  313                                  hptr = hdrlines[htype].head;
 317  314                                  if (htype == H_CLEN) {
 318  315                                          clen = atol (hptr->value);
 319  316                                  }
 320  317                                  /*
 321  318                                   * Use values saved in hdrlines[] structure
 322  319                                   * rather than what was read from tmp file.
 323  320                                   */
 324  321                                  print_from_struct = TRUE;
 325  322                                  /* FALLTHROUGH */
 326  323                          case H_EOH:
 327  324                          case H_AFWDFROM:
 328  325                          case H_AFWDCNT:
 329  326                          case H_RECEIVED:
 330  327                                  dumprcv(type, htype,&didrcvlines,&suppress,f);
 331  328                                  dumpaff(type, htype,&didafflines,&suppress,f);
 332  329                                  continue;       /* next header line */
 333  330                          default:
 334  331                                  pushrest = (lastc != '\n');
 335  332                                  continue;       /* next header line */
 336  333                          case FALSE:     /* end of header */
 337  334                                  break;
 338  335                          }
 339  336  
 340  337                          /* Found the blank line after the headers. */
 341  338                          if (n > 0) {
 342  339                                  if (fwrite(buf,1,n,f) != n)  {
 343  340                                          sav_errno = errno;
 344  341                                          return(FALSE);
 345  342                                  }
 346  343                          }
 347  344  
 348  345                          Dout(pn, 3,", let[%d].text = %s\n",
 349  346                                  letnum, (let[letnum].text ? "TRUE" : "FALSE"));
 350  347  
 351  348                          if ((type == TTY) && (let[letnum].text == FALSE) && !pflg) {
 352  349                                  if (fprintf (f, "\n%s\n", binmsg) < 0)
 353  350                                  {
 354  351                                          sav_errno = errno;
 355  352                                          return(FALSE);
 356  353                                  }
 357  354                                  return (TRUE);
 358  355                          }
 359  356  
 360  357                          if (n == 1 && buf[0] == '\n') {
 361  358                                  n = 0;
 362  359                          }
 363  360                          break;
 364  361                  }
 365  362  
 366  363          Dout(pn, 1, "header processed, clen/k/n = %ld/%ld/%d\n", clen, k, n);
 367  364  
 368  365          if (clen >= 0) {
 369  366                  if (((clen - n) == k) || ((clen - n) == (k - 1))) {
 370  367                          k = clen - n;
 371  368                  } else {
 372  369                          /* probable content-length mismatch. show it ALL! */
 373  370                          Dout(pn, 1, "clen conflict. using k = %ld\n", k);
 374  371                  }
 375  372          }
 376  373  
 377  374          /* copy balance of message */
 378  375          if (rtrncont)
 379  376                  while (k > 0) {
 380  377                          num = ((k < sizeof(buf)) ? k : sizeof(buf));
 381  378                          if ((n = fread (buf, 1, num, tmpf)) <= 0) {
 382  379                                  Dout(pn, 1, "content-length mismatch. return(FALSE)\n");
 383  380                                  return(FALSE);
 384  381                          }
 385  382                          k -= n;
 386  383                          if (fwrite(buf,1,n,f) != n)  {
 387  384                                  sav_errno = errno;
 388  385                                  return(FALSE);
 389  386                          }
 390  387                  }
 391  388  
 392  389          Dout(pn, 3, "body processed, k=%ld\n", k);
 393  390  
 394  391          if (rtrncont && type != ZAP && type != REMOTE) {
 395  392                  if (fwrite("\n",1,1,f) != 1)  {
 396  393                          sav_errno = errno;
 397  394                          return(FALSE);
 398  395                  }
 399  396          }
 400  397  
 401  398          return(TRUE);
 402  399  }
  
    | ↓ open down ↓ | 93 lines elided | ↑ open up ↑ | 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX