home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / comp / bugs / 2bsd / 115 < prev    next >
Encoding:
Text File  |  1993-01-25  |  153.5 KB  |  4,311 lines

  1. Newsgroups: comp.bugs.2bsd
  2. Path: sparky!uunet!europa.asd.contel.com!wlbr!sms
  3. From: sms@WLV.IIPO.GTEGSC.COM (Steven M. Schultz)
  4. Subject: 'popper' for 2.11BSD (#103)
  5. Message-ID: <1993Jan25.183814.19593@wlbr.iipo.gtegsc.com>
  6. Sender: news@wlbr.iipo.gtegsc.com (news)
  7. Nntp-Posting-Host: wlv.iipo.gtegsc.com
  8. Organization: GTE Government Systems
  9. Date: Mon, 25 Jan 93 18:38:14 GMT
  10. Lines: 4299
  11.  
  12. Subject: 'popper' for 2.11BSD (#103)
  13. Index:    local/popper 2.11BSD
  14.  
  15. Description:
  16.     A new program to be installed on the system.  All known 'long' vs
  17.     'int' bugs have been fixed (there were a lot of them).
  18.  
  19. Repeat-By:
  20.     N/A
  21. Fix:
  22.     Cut where indicated, unpack the shar file, cd /usr/src/local/popper,
  23.     make all, make install.
  24.  
  25.     If you plan on offering POP service you will need to add (or uncomment)
  26.     a line like the following to /etc/inetd.conf:
  27.  
  28. pop    stream    tcp    nowait    root    /usr/local/popper    popper
  29.  
  30. ===========================cut here=================================
  31. #! /bin/sh
  32. # This is a shell archive, meaning:
  33. # 1. Remove everything above the #! /bin/sh line.
  34. # 2. Save the resulting text in a file.
  35. # 3. Execute the file with /bin/sh (not csh) to create:
  36. #    /usr/src/local/popper
  37. # This archive created: Mon Jan 25 10:00:38 1993
  38. export PATH; PATH=/bin:/usr/bin:$PATH
  39. if test ! -d '/usr/src/local/popper'
  40. then
  41.     mkdir '/usr/src/local/popper'
  42. fi
  43. cd '/usr/src/local/popper'
  44. if test -f 'pop3.rfc1081'
  45. then
  46.     echo shar: "will not over-write existing file 'pop3.rfc1081'"
  47. else
  48. sed 's/^X//' << \SHAR_EOF > 'pop3.rfc1081'
  49. X
  50. X
  51. X
  52. X
  53. X
  54. X
  55. XNetwork Working Group                                            M. Rose
  56. XRequest for Comments: 1081                                           TWG
  57. X                                                           November 1988
  58. X
  59. X                    Post Office Protocol - Version 3
  60. X
  61. X
  62. XStatus of this Memo
  63. X
  64. X   This memo suggests a simple method for workstations to dynamically
  65. X   access mail from a mailbox server.  This RFC specifies a proposed
  66. X   protocol for the Internet community, and requests discussion and
  67. X   suggestions for improvements.  Distribution of this memo is
  68. X   unlimited.
  69. X
  70. X   This memo is based on RFC 918 (since revised as RFC 937).  Although
  71. X   similar in form to the original Post Office Protocol (POP) proposed
  72. X   for the Internet community, the protocol discussed in this memo is
  73. X   similar in spirit to the ideas investigated by the MZnet project at
  74. X   the University of California, Irvine.
  75. X
  76. X   Further, substantial work was done on examining POP in a PC-based
  77. X   environment.  This work, which resulted in additional functionality
  78. X   in this protocol, was performed by the ACIS Networking Systems Group
  79. X   at Stanford University.  The author gratefully acknowledges their
  80. X   interest.
  81. X
  82. XIntroduction
  83. X
  84. X   On certain types of smaller nodes in the Internet it is often
  85. X   impractical to maintain a message transport system (MTS).  For
  86. X   example, a workstation may not have sufficient resources (cycles,
  87. X   disk space) in order to permit a SMTP server and associated local
  88. X   mail delivery system to be kept resident and continuously running.
  89. X   Similarly, it may be expensive (or impossible) to keep a personal
  90. X   computer interconnected to an IP-style network for long amounts of
  91. X   time (the node is lacking the resource known as "connectivity").
  92. X
  93. X   Despite this, it is often very useful to be able to manage mail on
  94. X   these smaller nodes, and they often support a user agent (UA) to aid
  95. X   the tasks of mail handling.  To solve this problem, a node which can
  96. X   support an MTS entity offers a maildrop service to these less endowed
  97. X   nodes.  The Post Office Protocol - Version 3 (POP3) is intended to
  98. X   permit a workstation to dynamically access a maildrop on a server
  99. X   host in a useful fashion.  Usually, this means that the POP3 is used
  100. X   to allow a workstation to retrieve mail that the server is holding
  101. X   for it.
  102. X
  103. X
  104. X
  105. X
  106. XRose                                                            [Page 1]
  107. X
  108. XRFC 1081                          POP3                     November 1988
  109. X
  110. X
  111. X   For the remainder of this memo, the term "client host" refers to a
  112. X   host making use of the POP3 service, while the term "server host"
  113. X   refers to a host which offers the POP3 service.
  114. X
  115. XA Short Digression
  116. X
  117. X   This memo does not specify how a client host enters mail into the
  118. X   transport system, although a method consistent with the philosophy of
  119. X   this memo is presented here:
  120. X
  121. X      When the user agent on a client host wishes to enter a message
  122. X      into the transport system, it establishes an SMTP connection to
  123. X      its relay host (this relay host could be, but need not be, the
  124. X      POP3 server host for the client host).
  125. X
  126. X   If this method is followed, then the client host appears to the MTS
  127. X   as a user agent, and should NOT be regarded as a "trusted" MTS entity
  128. X   in any sense whatsoever.  This concept, along with the role of the
  129. X   POP3 as a part of a split-UA model is discussed later in this memo.
  130. X
  131. X   Initially, the server host starts the POP3 service by listening on
  132. X   TCP port 110.  When a client host wishes to make use of the service,
  133. X   it establishes a TCP connection with the server host.  When the
  134. X   connection is established, the POP3 server sends a greeting.  The
  135. X   client and POP3 server then exchange commands and responses
  136. X   (respectively) until the connection is closed or aborted.
  137. X
  138. X   Commands in the POP3 consist of a keyword possibly followed by an
  139. X   argument.  All commands are terminated by a CRLF pair.
  140. X
  141. X   Responses in the POP3 consist of a success indicator and a keyword
  142. X   possibly followed by additional information.  All responses are
  143. X   terminated by a CRLF pair.  There are currently two success
  144. X   indicators: positive ("+OK") and negative ("-ERR").
  145. X
  146. X   Responses to certain commands are multi-line.  In these cases, which
  147. X   are clearly indicated below, after sending the first line of the
  148. X   response and a CRLF, any additional lines are sent, each terminated
  149. X   by a CRLF pair.  When all lines of the response have been sent, a
  150. X   final line is sent, consisting of a termination octet (decimal code
  151. X   046, ".") and a CRLF pair.  If any line of the multi-line response
  152. X   begins with the termination octet, the line is "byte-stuffed" by
  153. X   pre-pending the termination octet to that line of the response.
  154. X   Hence a multi-line response is terminated with the five octets
  155. X   "CRLF.CRLF".  When examining a multi-line response, the client checks
  156. X   to see if the line begins with the termination octet.  If so and if
  157. X   octets other than CRLF follow, the the first octet of the line (the
  158. X   termination octet) is stripped away.  If so and if CRLF immediately
  159. X
  160. X
  161. X
  162. XRose                                                            [Page 2]
  163. X
  164. XRFC 1081                          POP3                     November 1988
  165. X
  166. X
  167. X   follows the termination character, then the response from the POP
  168. X   server is ended and the line containing ".CRLF" is not considered
  169. X   part of the multi-line response.
  170. X
  171. X   A POP3 session progresses through a number of states during its
  172. X   lifetime.  Once the TCP connection has been opened and the POP3
  173. X   server has sent the greeting, the session enters the AUTHORIZATION
  174. X   state.  In this state, the client must identify itself to the POP3
  175. X   server.  Once the client has successfully done this, the server
  176. X   acquires resources associated with the client's maildrop, and the
  177. X   session enters the TRANSACTION state.  In this state, the client
  178. X   requests actions on the part of the POP3 server.  When the client has
  179. X   finished its transactions, the session enters the UPDATE state.  In
  180. X   this state, the POP3 server releases any resources acquired during
  181. X   the TRANSACTION state and says goodbye.  The TCP connection is then
  182. X   closed.
  183. X
  184. XThe AUTHORIZATION State
  185. X
  186. X   Once the TCP connection has been opened by a POP3 client, the POP3
  187. X   server issues a one line greeting.  This can be any string terminated
  188. X   by CRLF.  An example might be:
  189. X
  190. X      S.  +OK dewey POP3 server ready (Comments to: PostMaster@UDEL.EDU)
  191. X
  192. X   Note that this greeting is a POP3 reply.  The POP3 server should
  193. X   always give a positive response as the greeting.
  194. X
  195. X   The POP3 session is now in the AUTHORIZATION state.  The client must
  196. X   now issue the USER command.  If the POP3 server responds with a
  197. X   positive success indicator ("+OK"), then the client may issue either
  198. X   the PASS command to complete the authorization, or the QUIT command
  199. X   to terminate the POP3 session.  If the POP3 server responds with a
  200. X   negative success indicator ("-ERR") to the USER command, then the
  201. X   client may either issue a new USER command or may issue the QUIT
  202. X   command.
  203. X
  204. X   When the client issues the PASS command, the POP3 server uses the
  205. X   argument pair from the USER and PASS commands to determine if the
  206. X   client should be given access to the appropriate maildrop.  If so,
  207. X   the POP3 server then acquires an exclusive-access lock on the
  208. X   maildrop.  If the lock is successfully acquired, the POP3 server
  209. X   parses the maildrop into individual messages (read note below),
  210. X   determines the last message (if any) present in the maildrop that was
  211. X   referenced by the RETR command, and responds with a positive success
  212. X   indicator.  The POP3 session now enters the TRANSACTION state.  If
  213. X   the lock can not be acquired or the client should is denied access to
  214. X   the appropriate maildrop or the maildrop can't be parsed for some
  215. X
  216. X
  217. X
  218. XRose                                                            [Page 3]
  219. X
  220. XRFC 1081                          POP3                     November 1988
  221. X
  222. X
  223. X   reason, the POP3 server responds with a negative success indicator.
  224. X   (If a lock was acquired but the POP3 server intends to respond with a
  225. X   negative success indicator, the POP3 server must release the lock
  226. X   prior to rejecting the command.)  At this point, the client may
  227. X   either issue a new USER command and start again, or the client may
  228. X   issue the QUIT command.
  229. X
  230. X                 NOTE: Minimal implementations of the POP3 need only be
  231. X                 able to break a maildrop into its component messages;
  232. X                 they need NOT be able to parse individual messages.
  233. X                 More advanced implementations may wish to have this
  234. X                 capability, for reasons discussed later.
  235. X
  236. X   After the POP3 server has parsed the maildrop into individual
  237. X   messages, it assigns a message-id to each message, and notes the size
  238. X   of the message in octets.  The first message in the maildrop is
  239. X   assigned a message-id of "1", the second is assigned "2", and so on,
  240. X   so that the n'th message in a maildrop is assigned a message-id of
  241. X   "n".  In POP3 commands and responses, all message-id's and message
  242. X   sizes are expressed in base-10 (i.e., decimal).
  243. X
  244. X   It sets the "highest number accessed" to be that of the last message
  245. X   referenced by the RETR command.
  246. X
  247. X   Here are summaries for the three POP3 commands discussed thus far:
  248. X
  249. X           USER name
  250. X               Arguments: a server specific user-id (required)
  251. X               Restrictions: may only be given in the AUTHORIZATION
  252. X                   state after the POP3 greeting or after an
  253. X                   unsuccessful USER or PASS command
  254. X               Possible Responses:
  255. X                   +OK name is welcome here
  256. X                   -ERR never heard of name
  257. X               Examples:
  258. X                   C:    USER mrose
  259. X                   S:    +OK mrose is a real hoopy frood
  260. X                     ...
  261. X                   C:    USER frated
  262. X                   S:    -ERR sorry, frated doesn't get his mail here
  263. X
  264. X           PASS string
  265. X               Arguments: a server/user-id specific password (required)
  266. X               Restrictions: may only be given in the AUTHORIZATION
  267. X                   state after a successful USER command
  268. X               Possible Responses:
  269. X                   +OK maildrop locked and ready
  270. X                   -ERR invalid password
  271. X
  272. X
  273. X
  274. XRose                                                            [Page 4]
  275. X
  276. XRFC 1081                          POP3                     November 1988
  277. X
  278. X
  279. X                   -ERR unable to lock maildrop
  280. X               Examples:
  281. X                   C:    USER mrose
  282. X                   S:    +OK mrose is a real hoopy frood
  283. X                   C:    PASS secret
  284. X                   S:    +OK mrose's maildrop has 2 messages
  285. X                         (320 octets)
  286. X                     ...
  287. X                   C:    USER mrose
  288. X                   S:    +OK mrose is a real hoopy frood
  289. X                   C:    PASS secret
  290. X                   S:    -ERR unable to lock mrose's maildrop, file
  291. X                         already locked
  292. X
  293. X           QUIT
  294. X               Arguments: none
  295. X               Restrictions: none
  296. X               Possible Responses:
  297. X                   +OK
  298. X               Examples:
  299. X                   C:    QUIT
  300. X                   S:    +OK dewey POP3 server signing off
  301. X
  302. X
  303. XThe TRANSACTION State
  304. X
  305. X   Once the client has successfully identified itself to the POP3 server
  306. X   and the POP3 server has locked and burst the appropriate maildrop,
  307. X   the POP3 session is now in the TRANSACTION state.  The client may now
  308. X   issue any of the following POP3 commands repeatedly.  After each
  309. X   command, the POP3 server issues a response.  Eventually, the client
  310. X   issues the QUIT command and the POP3 session enters the UPDATE state.
  311. X
  312. X   Here are the POP3 commands valid in the TRANSACTION state:
  313. X
  314. X           STAT
  315. X               Arguments: none
  316. X               Restrictions: may only be given in the TRANSACTION state.
  317. X               Discussion:
  318. X
  319. X                 The POP3 server issues a positive response with a line
  320. X                 containing information for the maildrop.  This line is
  321. X                 called a "drop listing" for that maildrop.
  322. X
  323. X                 In order to simplify parsing, all POP3 servers are
  324. X                 required to use a certain format for drop listings.
  325. X                 The first octets present must indicate the number of
  326. X                 messages in the maildrop.  Following this is the size
  327. X
  328. X
  329. X
  330. XRose                                                            [Page 5]
  331. X
  332. XRFC 1081                          POP3                     November 1988
  333. X
  334. X
  335. X                 of the maildrop in octets.  This memo makes no
  336. X                 requirement on what follows the maildrop size.
  337. X                 Minimal implementations should just end that line of
  338. X                 the response with a CRLF pair.  More advanced
  339. X                 implementations may include other information.
  340. X
  341. X                      NOTE: This memo STRONGLY discourages
  342. X                      implementations from supplying additional
  343. X                      information in the drop listing.  Other,
  344. X                      optional, facilities are discussed later on
  345. X                      which permit the client to parse the messages
  346. X                      in the maildrop.
  347. X
  348. X                 Note that messages marked as deleted are not counted in
  349. X                 either total.
  350. X
  351. X               Possible Responses:
  352. X                   +OK nn mm
  353. X               Examples:
  354. X                   C:    STAT
  355. X                   S:    +OK 2 320
  356. X
  357. X           LIST [msg]
  358. X               Arguments: a message-id (optionally)  If a message-id is
  359. X                   given, it may NOT refer to a message marked as
  360. X                   deleted.
  361. X               Restrictions: may only be given in the TRANSACTION state.
  362. X               Discussion:
  363. X
  364. X                 If an argument was given and the POP3 server issues a
  365. X                 positive response with a line containing information
  366. X                 for that message.  This line is called a "scan listing"
  367. X                 for that message.
  368. X
  369. X                 If no argument was given and the POP3 server issues a
  370. X                 positive response, then the response given is
  371. X                 multi-line.  After the initial +OK, for each message
  372. X                 in the maildrop, the POP3 server responds with a line
  373. X                 containing information for that message.  This line
  374. X                 is called a "scan listing" for that message.
  375. X
  376. X                 In order to simplify parsing, all POP3 servers are
  377. X                 required to use a certain format for scan listings.
  378. X                 The first octets present must be the message-id of
  379. X                 the message.  Following the message-id is the size of
  380. X                 the message in octets.  This memo makes no requirement
  381. X                 on what follows the message size in the scan listing.
  382. X                 Minimal implementations should just end that line of
  383. X
  384. X
  385. X
  386. XRose                                                            [Page 6]
  387. X
  388. XRFC 1081                          POP3                     November 1988
  389. X
  390. X
  391. X                 the response with a CRLF pair.  More advanced
  392. X                 implementations may include other information, as
  393. X                 parsed from the message.
  394. X
  395. X                      NOTE: This memo STRONGLY discourages
  396. X                      implementations from supplying additional
  397. X                      information in the scan listing.  Other, optional,
  398. X                      facilities are discussed later on which permit
  399. X                      the client to parse the messages in the maildrop.
  400. X
  401. X                 Note that messages marked as deleted are not listed.
  402. X
  403. X               Possible Responses:
  404. X                   +OK scan listing follows
  405. X                   -ERR no such message
  406. X               Examples:
  407. X                   C:    LIST
  408. X                   S:    +OK 2 messages (320 octets)
  409. X                   S:    1 120
  410. X                   S:    2 200
  411. X                   S:    .
  412. X                     ...
  413. X                   C:    LIST 2
  414. X                   S:    +OK 2 200
  415. X                     ...
  416. X                   C:    LIST 3
  417. X                   S:    -ERR no such message, only 2 messages in
  418. X                         maildrop
  419. X
  420. X           RETR msg
  421. X               Arguments: a message-id (required)  This message-id may
  422. X                   NOT refer to a message marked as deleted.
  423. X               Restrictions: may only be given in the TRANSACTION state.
  424. X               Discussion:
  425. X
  426. X                 If the POP3 server issues a positive response, then the
  427. X                 response given is multi-line.  After the initial +OK,
  428. X                 the POP3 server sends the message corresponding to the
  429. X                 given message-id, being careful to byte-stuff the
  430. X                 termination character (as with all multi-line
  431. X                 responses).
  432. X
  433. X                 If the number associated with this message is higher
  434. X                 than the "highest number accessed" in the maildrop, the
  435. X                 POP3 server updates the "highest number accessed" to
  436. X                 the number associated with this message.
  437. X
  438. X
  439. X
  440. X
  441. X
  442. XRose                                                            [Page 7]
  443. X
  444. XRFC 1081                          POP3                     November 1988
  445. X
  446. X
  447. X               Possible Responses:
  448. X                   +OK message follows
  449. X                   -ERR no such message
  450. X               Examples:
  451. X                   C:    RETR 1
  452. X                   S:    +OK 120 octets
  453. X                   S:    <the POP3 server sends the entire message here>
  454. X                   S:    .
  455. X
  456. X           DELE msg
  457. X               Arguments: a message-id (required)  This message-id
  458. X                   may NOT refer to a message marked as deleted.
  459. X               Restrictions: may only be given in the TRANSACTION state.
  460. X               Discussion:
  461. X
  462. X                 The POP3 server marks the message as deleted.  Any
  463. X                 future reference to the message-id associated with the
  464. X                 message in a POP3 command generates an error.  The POP3
  465. X                 server does not actually delete the message until the
  466. X                 POP3 session enters the UPDATE state.
  467. X
  468. X                 If the number associated with this message is higher
  469. X                 than the "highest number accessed" in the maildrop,
  470. X                 the POP3 server updates the "highest number accessed"
  471. X                 to the number associated with this message.
  472. X
  473. X               Possible Responses:
  474. X                   +OK message deleted
  475. X                   -ERR no such message
  476. X               Examples:
  477. X                   C:    DELE 1
  478. X                   S:    +OK message 1 deleted
  479. X                     ...
  480. X                   C:    DELE 2
  481. X                   S:    -ERR message 2 already deleted
  482. X
  483. X           NOOP
  484. X               Arguments: none
  485. X               Restrictions: may only be given in the TRANSACTION state.
  486. X               Discussion:
  487. X
  488. X                 The POP3 server does nothing, it merely replies with a
  489. X                 positive response.
  490. X
  491. X               Possible Responses:
  492. X                   +OK
  493. X
  494. X
  495. X
  496. X
  497. X
  498. XRose                                                            [Page 8]
  499. X
  500. XRFC 1081                          POP3                     November 1988
  501. X
  502. X
  503. X               Examples:
  504. X                   C:    NOOP
  505. X                   S:    +OK
  506. X
  507. X           LAST
  508. X               Arguments: none
  509. X               Restrictions: may only be issued in the TRANSACTION state.
  510. X               Discussion:
  511. X
  512. X                 The POP3 server issues a positive response with a line
  513. X                 containing the highest message number which accessed.
  514. X                 Zero is returned in case no message in the maildrop has
  515. X                 been accessed during previous transactions.  A client
  516. X                 may thereafter infer that messages, if any, numbered
  517. X                 greater than the response to the LAST command are
  518. X                 messages not yet accessed by the client.
  519. X
  520. X             Possible Response:
  521. X                   +OK nn
  522. X
  523. X             Examples:
  524. X                   C:      STAT
  525. X                   S:      +OK 4 320
  526. X                   C:      LAST
  527. X                   S:      +OK 1
  528. X                   C:      RETR 3
  529. X                   S:      +OK 120 octets
  530. X                   S:      <the POP3 server sends the entire message
  531. X                           here>
  532. X                   S:      .
  533. X                   C:      LAST
  534. X                   S:      +OK 3
  535. X                   C:      DELE 2
  536. X                   S:      +OK message 2 deleted
  537. X                   C:      LAST
  538. X                   S:      +OK 3
  539. X                   C:      RSET
  540. X                   S:      +OK
  541. X                   C:      LAST
  542. X                   S:      +OK 1
  543. X
  544. X           RSET
  545. X               Arguments: none
  546. X               Restrictions: may only be given in the TRANSACTION
  547. X                   state.
  548. X               Discussion:
  549. X
  550. X                 If any messages have been marked as deleted by the POP3
  551. X
  552. X
  553. X
  554. XRose                                                            [Page 9]
  555. X
  556. XRFC 1081                          POP3                     November 1988
  557. X
  558. X
  559. X                 server, they are unmarked.  The POP3 server then
  560. X                 replies with a positive response.  In addition, the
  561. X                 "highest number accessed" is also reset to the value
  562. X                 determined at the beginning of the POP3 session.
  563. X
  564. X               Possible Responses:
  565. X                   +OK
  566. X               Examples:
  567. X                   C:    RSET
  568. X                   S:    +OK maildrop has 2 messages (320 octets)
  569. X
  570. X
  571. X
  572. XThe UPDATE State
  573. X
  574. X   When the client issues the QUIT command from the TRANSACTION state,
  575. X   the POP3 session enters the UPDATE state.  (Note that if the client
  576. X   issues the QUIT command from the AUTHORIZATION state, the POP3
  577. X   session terminates but does NOT enter the UPDATE state.)
  578. X
  579. X           QUIT
  580. X               Arguments: none
  581. X               Restrictions: none
  582. X               Discussion:
  583. X
  584. X                 The POP3 server removes all messages marked as deleted
  585. X                 from the maildrop.  It then releases the
  586. X                 exclusive-access lock on the maildrop and replies as
  587. X                 to the success of
  588. X                 these operations.  The TCP connection is then closed.
  589. X
  590. X               Possible Responses:
  591. X                   +OK
  592. X               Examples:
  593. X                   C:    QUIT
  594. X                   S:    +OK dewey POP3 server signing off (maildrop
  595. X                         empty)
  596. X                     ...
  597. X                   C:    QUIT
  598. X                   S:    +OK dewey POP3 server signing off (2 messages
  599. X                         left)
  600. X                     ...
  601. X
  602. X
  603. XOptional POP3 Commands
  604. X
  605. X   The POP3 commands discussed above must be supported by all minimal
  606. X   implementations of POP3 servers.
  607. X
  608. X
  609. X
  610. XRose                                                           [Page 10]
  611. X
  612. XRFC 1081                          POP3                     November 1988
  613. X
  614. X
  615. X   The optional POP3 commands described below permit a POP3 client
  616. X   greater freedom in message handling, while preserving a simple POP3
  617. X   server implementation.
  618. X
  619. X                 NOTE: This memo STRONGLY encourages implementations to
  620. X                 support these commands in lieu of developing augmented
  621. X                 drop and scan listings.  In short, the philosophy of
  622. X                 this memo is to put intelligence in the part of the
  623. X                 POP3 client and not the POP3 server.
  624. X
  625. X           TOP msg n
  626. X               Arguments: a message-id (required) and a number.  This
  627. X                   message-id may NOT refer to a message marked as
  628. X                   deleted.
  629. X               Restrictions: may only be given in the TRANSACTION state.
  630. X               Discussion:
  631. X
  632. X                 If the POP3 server issues a positive response, then
  633. X                 the response given is multi-line.  After the initial
  634. X                 +OK, the POP3 server sends the headers of the message,
  635. X                 the blank line separating the headers from the body,
  636. X                 and then the number of lines indicated message's body,
  637. X                 being careful to byte-stuff the termination character
  638. X                 (as with all multi-line responses).
  639. X
  640. X                 Note that if the number of lines requested by the POP3
  641. X                 client is greater than than the number of lines in the
  642. X                 body, then the POP3 server sends the entire message.
  643. X
  644. X               Possible Responses:
  645. X                   +OK top of message follows
  646. X                   -ERR no such message
  647. X               Examples:
  648. X                   C:    TOP 10
  649. X                   S:    +OK
  650. X                   S:    <the POP3 server sends the headers of the
  651. X                          message, a blank line, and the first 10 lines
  652. X                          of the body of the message>
  653. X                   S:    .
  654. X                     ...
  655. X                   C:    TOP 100
  656. X                   S:    -ERR no such message
  657. X
  658. X           RPOP user
  659. X               Arguments: a client specific user-id (required)
  660. X               Restrictions: may only be given in the AUTHORIZATION
  661. X                   state after a successful USER command; in addition,
  662. X                   may only be given if the client used a reserved
  663. X
  664. X
  665. X
  666. XRose                                                           [Page 11]
  667. X
  668. XRFC 1081                          POP3                     November 1988
  669. X
  670. X
  671. X                   (privileged) TCP port to connect to the server.
  672. X               Discussion:
  673. X
  674. X                 The RPOP command may be used instead of the PASS
  675. X                 command to authenticate access to the maildrop.  In
  676. X                 order for this command to be successful, the POP3
  677. X                 client must use a reserved TCP port (port < 1024) to
  678. X                 connect tothe server.  The POP3 server uses the
  679. X                 argument pair from the USER and RPOP commands to
  680. X                 determine if the client should be given access to
  681. X                 the appropriate maildrop.  Unlike the PASS command
  682. X                 however, the POP3 server considers if the remote user
  683. X                 specified by the RPOP command who resides on the POP3
  684. X                 client host is allowed to access the maildrop for the
  685. X                 user specified by the USER command (e.g., on Berkeley
  686. X                 UNIX, the .rhosts mechanism is used).  With the
  687. X                 exception of this differing in authentication, this
  688. X                 command is identical to the PASS command.
  689. X
  690. X                 Note that the use of this feature has allowed much wider
  691. X                 penetration into numerous hosts on local networks (and
  692. X                 sometimes remote networks) by those who gain illegal
  693. X                 access to computers by guessing passwords or otherwise
  694. X                 breaking into the system.
  695. X
  696. X               Possible Responses:
  697. X                   +OK maildrop locked and ready
  698. X                   -ERR permission denied
  699. X               Examples:
  700. X                   C:    USER mrose
  701. X                   S:    +OK mrose is a real hoopy frood
  702. X                   C:    RPOP mrose
  703. X                   S:    +OK mrose's maildrop has 2 messages (320
  704. X                         octets)
  705. X
  706. X       Minimal POP3 Commands:
  707. X           USER name               valid in the AUTHORIZATION state
  708. X           PASS string
  709. X           QUIT
  710. X
  711. X           STAT                    valid in the TRANSACTION state
  712. X           LIST [msg]
  713. X           RETR msg
  714. X           DELE msg
  715. X           NOOP
  716. X           LAST
  717. X           RSET
  718. X
  719. X
  720. X
  721. X
  722. XRose                                                           [Page 12]
  723. X
  724. XRFC 1081                          POP3                     November 1988
  725. X
  726. X
  727. X           QUIT                    valid in the UPDATE state
  728. X
  729. X       Optional POP3 Commands:
  730. X           RPOP user               valid in the AUTHORIZATION state
  731. X
  732. X           TOP msg n               valid in the TRANSACTION state
  733. X
  734. X       POP3 Replies:
  735. X           +OK
  736. X           -ERR
  737. X
  738. X       Note that with the exception of the STAT command, the reply given
  739. X       by the POP3 server to any command is significant only to "+OK"
  740. X       and "-ERR".  Any text occurring after this reply may be ignored
  741. X       by the client.
  742. X
  743. XExample POP3 Session
  744. X
  745. X    S: <wait for connection on TCP port 110>
  746. X        ...
  747. X    C: <open connection>
  748. X    S:    +OK dewey POP3 server ready (Comments to: PostMaster@UDEL.EDU)
  749. X    C:    USER mrose
  750. X    S:    +OK mrose is a real hoopy frood
  751. X    C:    PASS secret
  752. X    S:    +OK mrose's maildrop has 2 messages (320 octets)
  753. X    C:    STAT
  754. X    S:    +OK 2 320
  755. X    C:    LIST
  756. X    S:    +OK 2 messages (320 octets)
  757. X    S:    1 120
  758. X    S:    2 200
  759. X    S:    .
  760. X    C:    RETR 1
  761. X    S:    +OK 120 octets
  762. X    S:    <the POP3 server sends message 1>
  763. X    S:    .
  764. X    C:    DELE 1
  765. X    S:    +OK message 1 deleted
  766. X    C:    RETR 2
  767. X    S:    +OK 200 octets
  768. X    S:    <the POP3 server sends message 2>
  769. X    S:    .
  770. X    C:    DELE 2
  771. X    S:    +OK message 2 deleted
  772. X    C:    QUIT
  773. X
  774. X
  775. X
  776. X
  777. X
  778. XRose                                                           [Page 13]
  779. X
  780. XRFC 1081                          POP3                     November 1988
  781. X
  782. X
  783. X    S:    +OK dewey POP3 server signing off (maildrop empty)
  784. X    C:  <close connection>
  785. X    S:  <wait for next connection>
  786. X
  787. XMessage Format
  788. X
  789. X   All messages transmitted during a POP3 session are assumed to conform
  790. X   to the standard for the format of Internet text messages [RFC822].
  791. X
  792. X   It is important to note that the byte count for a message on the
  793. X   server host may differ from the octet count assigned to that message
  794. X   due to local conventions for designating end-of-line.  Usually,
  795. X   during the AUTHORIZATION state of the POP3 session, the POP3 client
  796. X   can calculate the size of each message in octets when it parses the
  797. X   maildrop into messages.  For example, if the POP3 server host
  798. X   internally represents end-of-line as a single character, then the
  799. X   POP3 server simply counts each occurrence of this character in a
  800. X   message as two octets.  Note that lines in the message which start
  801. X   with the termination octet need not be counted twice, since the POP3
  802. X   client will remove all byte-stuffed termination characters when it
  803. X   receives a multi-line response.
  804. X
  805. XThe POP and the Split-UA model
  806. X
  807. X   The underlying paradigm in which the POP3 functions is that of a
  808. X   split-UA model.  The POP3 client host, being a remote PC based
  809. X   workstation, acts solely as a client to the message transport system.
  810. X   It does not provide delivery/authentication services to others.
  811. X   Hence, it is acting as a UA, on behalf of the person using the
  812. X   workstation.  Furthermore, the workstation uses SMTP to enter mail
  813. X   into the MTS.
  814. X
  815. X   In this sense, we have two UA functions which interface to the
  816. X   message transport system: Posting (SMTP) and Retrieval (POP3).  The
  817. X   entity which supports this type of environment is called a split-UA
  818. X   (since the user agent is split between two hosts which must
  819. X   interoperate to provide these functions).
  820. X
  821. X                 ASIDE:  Others might term this a remote-UA instead.
  822. X                 There are arguments supporting the use of both terms.
  823. X
  824. X   This memo has explicitly referenced TCP as the underlying transport
  825. X   agent for the POP3.  This need not be the case.  In the MZnet split-
  826. X   UA, for example, personal micro-computer systems are used which do
  827. X   not have IP-style networking capability.  To connect to the POP3
  828. X   server host, a PC establishes a terminal connection using some simple
  829. X   protocol (PhoneNet).  A program on the PC drives the connection,
  830. X   first establishing a login session as a normal user.  The login shell
  831. X
  832. X
  833. X
  834. XRose                                                           [Page 14]
  835. X
  836. XRFC 1081                          POP3                     November 1988
  837. X
  838. X
  839. X   for this pseudo-user is a program which drives the other half of the
  840. X   terminal protocol and communicates with one of two servers.  Although
  841. X   MZnet can support several PCs, a single pseudo-user login is present
  842. X   on the server host.  The user-id and password for this pseudo-user
  843. X   login is known to all members of MZnet.  Hence, the first action of
  844. X   the login shell, after starting the terminal protocol, is to demand a
  845. X   USER/PASS authorization pair from the PC.  This second level of
  846. X   authorization is used to ascertain who is interacting with the MTS.
  847. X   Although the server host is deemed to support a "trusted" MTS entity,
  848. X   PCs in MZnet are not.  Naturally, the USER/PASS authorization pair
  849. X   for a PC is known only to the owner of the PC (in theory, at least).
  850. X
  851. X   After successfully verifying the identity of the client, a modified
  852. X   SMTP server is started, and the PC posts mail with the server host.
  853. X   After the QUIT command is given to the SMTP server and it terminates,
  854. X   a modified POP3 server is started, and the PC retrieves mail from the
  855. X   server host.  After the QUIT command is given to the POP3 server and
  856. X   it terminates, the login shell for the pseudo-user terminates the
  857. X   terminal protocol and logs the job out.  The PC then closes the
  858. X   terminal connection to the server host.
  859. X
  860. X   The SMTP server used by MZnet is modified in the sense that it knows
  861. X   that it's talking to a user agent and not a "trusted" entity in the
  862. X   message transport system.  Hence, it does performs the validation
  863. X   activities normally performed by an entity in the MTS when it accepts
  864. X   a message from a UA.
  865. X
  866. X   The POP3 server used by MZnet is modified in the sense that it does
  867. X   not require a USER/PASS combination before entering the TRANSACTION
  868. X   state.  The reason for this (of course) is that the PC has already
  869. X   identified itself during the second-level authorization step
  870. X   described above.
  871. X
  872. X                 NOTE: Truth in advertising laws require that the author
  873. X                 of this memo state that MZnet has not actually been
  874. X                 fully implemented.  The concepts presented and proven
  875. X                 by the project led to the notion of the MZnet
  876. X                 split-slot model.  This notion has inspired the
  877. X                 split-UA concept described in this memo, led to the
  878. X                 author's interest in the POP, and heavily influenced
  879. X                 the the description of the POP3 herein.
  880. X
  881. X   In fact, some UAs present in the Internet already support the notion
  882. X   of posting directly to an SMTP server and retrieving mail directly
  883. X   from a POP server, even if the POP server and client resided on the
  884. X   same host!
  885. X
  886. X                 ASIDE: this discussion raises an issue which this memo
  887. X
  888. X
  889. X
  890. XRose                                                           [Page 15]
  891. X
  892. XRFC 1081                          POP3                     November 1988
  893. X
  894. X
  895. X                 purposedly avoids: how does SMTP know that it's talking
  896. X                 to a "trusted" MTS entity?
  897. X
  898. XReferences
  899. X
  900. X     [MZnet]   Stefferud, E., J. Sweet, and T. Domae, "MZnet: Mail
  901. X               Service for Personal Micro-Computer Systems",
  902. X               Proceedings, IFIP 6.5 International Conference on
  903. X               Computer Message Systems, Nottingham, U.K., May 1984.
  904. X
  905. X     [RFC821]  Postel, J., "Simple Mail Transfer Protocol",
  906. X               USC/Information Sciences Institute, August 1982.
  907. X
  908. X     [RFC822]  Crocker, D., "Standard for the Format of ARPA-Internet
  909. X               Text Messages", University of Delaware, August 1982.
  910. X
  911. X     [RFC937]  Butler, M., J. Postel, D. Chase, J. Goldberger, and J.
  912. X               Reynolds, "Post Office Protocol - Version 2", RFC 937,
  913. X               USC/Information Sciences Institute, February 1985.
  914. X
  915. X     [RFC1010] Reynolds, J., and J. Postel, "Assigned Numbers", RFC
  916. X               1010, USC/Information Sciences Institute, May 1987.
  917. X
  918. XAuthor's Address:
  919. X
  920. X
  921. X   Marshall Rose
  922. X   The Wollongong Group
  923. X   1129 San Antonio Rd.
  924. X   Palo Alto, California 94303
  925. X
  926. X   Phone: (415) 962-7100
  927. X
  928. X   Email: MRose@TWG.COM
  929. X
  930. X
  931. X
  932. X
  933. X
  934. X
  935. X
  936. X
  937. X
  938. X
  939. X
  940. X
  941. X
  942. X
  943. X
  944. X
  945. X
  946. XRose                                                           [Page 16]
  947. SHAR_EOF
  948. fi
  949. if test -f 'pop3e.rfc1082'
  950. then
  951.     echo shar: "will not over-write existing file 'pop3e.rfc1082'"
  952. else
  953. sed 's/^X//' << \SHAR_EOF > 'pop3e.rfc1082'
  954. X
  955. X
  956. X
  957. X
  958. X
  959. X
  960. XNetwork Working Group                                            M. Rose
  961. XRequest for Comments: 1082                                           TWG
  962. X                                                           November 1988
  963. X
  964. X
  965. X
  966. X                    Post Office Protocol - Version 3
  967. X                       Extended Service Offerings
  968. X
  969. XStatus of This Memo
  970. X
  971. X   This memo suggests a simple method for workstations to dynamically
  972. X   access mail from a discussion group server, as an extension to an
  973. X   earlier memo which dealt with dynamically accessing mail from a
  974. X   mailbox server using the Post Office Protocol -  Version 3 (POP3).
  975. X   This RFC specifies a proposed protocol for the Internet community,
  976. X   and requests discussion and suggestions for improvements.  All of the
  977. X   extensions described in this memo to the POP3 are OPTIONAL.
  978. X   Distribution of this memo is unlimited.
  979. X
  980. XIntroduction and Motivation
  981. X
  982. X   It is assumed that the reader is familiar with RFC 1081 that
  983. X   discusses the Post Office Protocol - Version 3 (POP3) [RFC1081].
  984. X   This memo describes extensions to the POP3 which enhance the service
  985. X   it offers to clients.  This additional service permits a client host
  986. X   to access discussion group mail, which is often kept in a separate
  987. X   spool area, using the general POP3 facilities.
  988. X
  989. X   The next section describes the evolution of discussion groups and the
  990. X   technologies currently used to implement them.  To summarize:
  991. X
  992. X       o An exploder is used to map from a single address to
  993. X       a list of addresses which subscribe to the list, and redirects
  994. X       any subsequent error reports associated with the delivery of
  995. X       each message.  This has two primary advantages:
  996. X             - Subscribers need know only a single address
  997. X             - Responsible parties get the error reports and not
  998. X               the subscribers
  999. X
  1000. X
  1001. X
  1002. X
  1003. X
  1004. X
  1005. X
  1006. X
  1007. X
  1008. X
  1009. X
  1010. X
  1011. XRose                                                            [Page 1]
  1012. X
  1013. XRFC 1082                 POP3 Extended Service             November 1988
  1014. X
  1015. X
  1016. X       o Typically, each subscription address is not a person's private
  1017. X       maildrop, but a system-wide maildrop, which can be accessed
  1018. X       by more than one user.  This has several advantages:
  1019. X             - Only a single copy of each message need traverse the
  1020. X               net for a given site (which may contain several local
  1021. X               hosts).  This conserves bandwidth and cycles.
  1022. X             - Only a single copy of each message need reside on each
  1023. X               subscribing host.  This conserves disk space.
  1024. X             - The private maildrop for each user is not cluttered
  1025. X               with discussion group mail.
  1026. X
  1027. X   Despite this optimization of resources, further economy can be
  1028. X   achieved at sites with more than one host.  Typically, sites with
  1029. X   more than one host either:
  1030. X
  1031. X        1.  Replicate discussion group mail on each host.  This
  1032. X        results in literally gigabytes of disk space committed to
  1033. X        unnecessarily store redundant information.
  1034. X
  1035. X        2.  Keep discussion group mail on one host and give all users a
  1036. X        login on that host (in addition to any other logins they may
  1037. X        have).  This is usually a gross inconvenience for users who
  1038. X        work on other hosts, or a burden to users who are forced to
  1039. X        work on that host.
  1040. X
  1041. X   As discussed in [RFC1081], the problem of giving workstations dynamic
  1042. X   access to mail from a mailbox server has been explored in great
  1043. X   detail (originally there was [RFC918], this prompted the author to
  1044. X   write [RFC1081], independently of this [RFC918] was upgraded to
  1045. X   [RFC937]).  A natural solution to the problem outlined above is to
  1046. X   keep discussion group mail on a mailbox server at each site and
  1047. X   permit different hosts at that site to employ the POP3 to access
  1048. X   discussion group mail.  If implemented properly, this avoids the
  1049. X   problems of both strategies outlined above.
  1050. X
  1051. X        ASIDE:     It might be noted that a good distributed filesystem
  1052. X                   could also solve this problem.  Sadly, "good"
  1053. X                   distributed filesystems, which do not suffer
  1054. X                   unacceptable response time for interactive use, are
  1055. X                   few and far between these days!
  1056. X
  1057. X   Given this motivation, now let's consider discussion groups, both in
  1058. X   general and from the point of view of a user agent.  Following this,
  1059. X   extensions to the POP3 defined in [RFC1081] are presented.  Finally,
  1060. X   some additional policy details are discussed along with some initial
  1061. X   experiences.
  1062. X
  1063. X
  1064. X
  1065. X
  1066. X
  1067. XRose                                                            [Page 2]
  1068. X
  1069. XRFC 1082                 POP3 Extended Service             November 1988
  1070. X
  1071. X
  1072. XWhat's in a Discussion Group
  1073. X
  1074. X   Since mailers and user agents first crawled out of the primordial
  1075. X   ARPAnet, the value of discussion groups have been appreciated,
  1076. X   (though their implementation has not always been well-understood).
  1077. X
  1078. X   Described simply, a discussion group is composed of a number of
  1079. X   subscribers with a common interest.  These subscribers post mail to a
  1080. X   single address, known as a distribution address.  From this
  1081. X   distribution address, a copy of the message is sent to each
  1082. X   subscriber.  Each group has a moderator, which is the person that
  1083. X   administrates the group.  The moderator can usually be reached at a
  1084. X   special address, known as a request address.  Usually, the
  1085. X   responsibilities of the moderator are quite simple, since the mail
  1086. X   system handles the distribution to subscribers automatically.  In
  1087. X   some cases, the interest group, instead of being distributed directly
  1088. X   to its subscribers, is put into a digest format by the moderator and
  1089. X   then sent to the subscribers.  Although this requires more work on
  1090. X   the part of the moderator, such groups tend to be better organized.
  1091. X
  1092. X   Unfortunately, there are a few problems with the scheme outlined
  1093. X   above.  First, if two users on the same host subscribe to the same
  1094. X   interest group, two copies of the message get delivered.  This is
  1095. X   wasteful of both processor and disk resources.
  1096. X
  1097. X   Second, some of these groups carry a lot of traffic.  Although
  1098. X   subscription to an group does indicate interest on the part of a
  1099. X   subscriber, it is usually not interesting to get 50 messages or so
  1100. X   delivered to the user's private maildrop each day, interspersed with
  1101. X   personal mail, that is likely to be of a much more important and
  1102. X   timely nature.
  1103. X
  1104. X   Third, if a subscriber on the distribution list for a group becomes
  1105. X   "bad" somehow, the originator of the message and not the moderator of
  1106. X   the group is notified.  It is not uncommon for a large list to have
  1107. X   10 or so bogus addresses present.  This results in the originator
  1108. X   being flooded with "error messages" from mailers across the Internet
  1109. X   stating that a given address on the list was bad.  Needless to say,
  1110. X   the originator usually could not care less if the bogus addresses got
  1111. X   a copy of the message or not.  The originator is merely interested in
  1112. X   posting a message to the group at large.  Furthermore, the moderator
  1113. X   of the group does care if there are bogus addresses on the list, but
  1114. X   ironically does not receive notification.
  1115. X
  1116. X   There are various approaches which can be used to solve some or all
  1117. X   of these problems.  Usually these involve placing an exploder agent
  1118. X   at the distribution source of the discussion group, which expands the
  1119. X   name of the group into the list of subscription addresses for the
  1120. X
  1121. X
  1122. X
  1123. XRose                                                            [Page 3]
  1124. X
  1125. XRFC 1082                 POP3 Extended Service             November 1988
  1126. X
  1127. X
  1128. X   group.  In the process, the exploder will also change the address
  1129. X   that receives error notifications to be the request address or other
  1130. X   responsible party.
  1131. X
  1132. X   A complementary approach, used in order to cut down on resource
  1133. X   utilization of all kinds, replaces all the subscribers at a single
  1134. X   host (or group of hosts under a single administration) with a single
  1135. X   address at that host.  This address maps to a file on the host,
  1136. X   usually in a spool area, which all users can access.  (Advanced
  1137. X   implementations can also implement private discussion groups this
  1138. X   way, in which a single copy of each message is kept, but is
  1139. X   accessible to only a select number of users on the host.)
  1140. X
  1141. X   The two approaches can be combined to avoid all of the problems
  1142. X   described above.
  1143. X
  1144. X   Finally, a third approach can be taken, which can be used to aid user
  1145. X   agents processing mail for the discussion group:  In order to speed
  1146. X   querying of the maildrop which contains the local host's copy of the
  1147. X   discussion group, two other items are usually associated with the
  1148. X   discussion group, on a local basis.  These are the maxima and the
  1149. X   last-date.  Each time a message is received for the group on the
  1150. X   local host, the maxima is increased by at least one.  Furthermore,
  1151. X   when a new maxima is generated, the current date is determined.  This
  1152. X   is called the last date.  As the message is entered into the local
  1153. X   maildrop, it is given the current maxima and last-date.  This permits
  1154. X   the user agent to quickly determine if new messages are present in
  1155. X   the maildrop.
  1156. X
  1157. X       NOTE:      The maxima may be characterized as a monotonically
  1158. X                  increasing quanity.  Although sucessive values of the
  1159. X                  maxima need not be consecutive, any maxima assigned
  1160. X                  is always greater than any previously assigned value.
  1161. X
  1162. XDefinition of Terms
  1163. X
  1164. X   To formalize these notions somewhat, consider the following 7
  1165. X   parameters which describe a given discussion group from the
  1166. X   perspective of the user agent (the syntax given is from [RFC822]):
  1167. X
  1168. X
  1169. X
  1170. X
  1171. X
  1172. X
  1173. X
  1174. X
  1175. X
  1176. X
  1177. X
  1178. X
  1179. XRose                                                            [Page 4]
  1180. X
  1181. XRFC 1082                 POP3 Extended Service             November 1988
  1182. X
  1183. X
  1184. X         NAME            Meaning: the name of the discussion group
  1185. X                         Syntax:  TOKEN (ALPHA *[ ALPHA / DIGIT / "-" ])
  1186. X                                  (case-insensitive recognition)
  1187. X                         Example: unix-wizards
  1188. X
  1189. X         ALIASES         Meaning: alternates names for the group, which
  1190. X                                  are locally meaningful; these are
  1191. X                                  typically used to shorten user typein
  1192. X                         Syntax:  TOKEN (case-insensitive recognition)
  1193. X                         Example: uwiz
  1194. X
  1195. X         ADDRESS         Meaning: the primary source of the group
  1196. X                         Syntax:  822 address
  1197. X                         Example: Unix-Wizards@BRL.MIL
  1198. X
  1199. X         REQUEST         Meaning: the primary moderator of the group
  1200. X                         Syntax:  822 address
  1201. X                         Example: Unix-Wizards-Request@BRL.MIL
  1202. X
  1203. X         FLAGS           Meaning: locally meaningful flags associated
  1204. X                                  with the discussion group; this memo
  1205. X                                  leaves interpretation of this
  1206. X                                  parameter to each POP3 implementation
  1207. X                         Syntax:  octal number
  1208. X                         Example: 01
  1209. X
  1210. X         MAXIMA          Meaning: the magic cookie associated with the
  1211. X                                  last message locally received for the
  1212. X                                  group; it is the property of the magic
  1213. X                                  cookie that it's value NEVER
  1214. X                                  decreases, and increases by at least
  1215. X                                  one each time a message is locally
  1216. X                                  received
  1217. X                         Syntax:  decimal number
  1218. X                         Example: 1004
  1219. X
  1220. X         LASTDATE        Meaning: the date that the last message was
  1221. X                                  locally received
  1222. X                         Syntax:  822 date
  1223. X                         Example: Thu, 19 Dec 85 10:26:48 -0800
  1224. X
  1225. X   Note that the last two values are locally determined for the maildrop
  1226. X   associated with the discussion group and with each message in that
  1227. X   maildrop.  Note however that the last message in the maildrop have a
  1228. X   different MAXIMA and LASTDATE than the discussion group.  This often
  1229. X   occurs when the maildrop has been archived.
  1230. X
  1231. X
  1232. X
  1233. X
  1234. X
  1235. XRose                                                            [Page 5]
  1236. X
  1237. XRFC 1082                 POP3 Extended Service             November 1988
  1238. X
  1239. X
  1240. X   Finally, some local systems provide mechanisms for automatically
  1241. X   archiving discussion group mail.  In some cases, a two-level archive
  1242. X   scheme is used:  current mail is kept in the standard maildrop,
  1243. X   recent mail is kept in an archive maildrop, and older mail is kept
  1244. X   off-line.  With this scheme, in addition to having a "standard"
  1245. X   maildrop for each discussion group, an "archive" maildrop may also be
  1246. X   available.  This permits a user agent to examine the most recent
  1247. X   archive using the same mechanisms as those used on the current mail.
  1248. X
  1249. XThe XTND Command
  1250. X
  1251. X   The following commands are valid only in the TRANSACTION state of the
  1252. X   POP3.  This implies that the POP3 server has already opened the
  1253. X   user's maildrop (which may be empty).  This maildrop is called the
  1254. X   "default maildrop".  The phrase "closes the current maildrop" has two
  1255. X   meanings, depending on whether the current maildrop is the default
  1256. X   maildrop or is a maildrop associated with a discussion group.
  1257. X
  1258. X   In the former context, when the current maildrop is closed any
  1259. X   messages marked as deleted are removed from the maildrop currently in
  1260. X   use.  The exclusive-access lock on the maildrop is then released
  1261. X   along with any implementation-specific resources (e.g., file-
  1262. X   descriptors).
  1263. X
  1264. X   In the latter context, a maildrop associated with a discussion group
  1265. X   is considered to be read-only to the POP3 client.  In this case, the
  1266. X   phrase "closes the current maildrop" merely means that any
  1267. X   implementation-specific resources are released.  (Hence, the POP3
  1268. X   command DELE is a no-op.)
  1269. X
  1270. X   All the new facilities are introduced via a single POP3 command,
  1271. X   XTND.  All positive reponses to the XTND command are multi-line.
  1272. X
  1273. X   The most common multi-line response to the commands contains a
  1274. X   "discussion group listing" which presents the name of the discussion
  1275. X   group along with it's maxima.  In order to simplify parsing all POP3
  1276. X   servers are required to use a certain format for discussion group
  1277. X   listings:
  1278. X
  1279. X                              NAME SP MAXIMA
  1280. X
  1281. X   This memo makes no requirement on what follows the maxima in the
  1282. X   listing.  Minimal implementations should just end that line of the
  1283. X   response with a CRLF pair.  More advanced implementations may include
  1284. X   other information, as parsed from the message.
  1285. X
  1286. X       NOTE:      This memo STRONGLY discourages implementations from
  1287. X                  supplying additional information in the listing.
  1288. X
  1289. X
  1290. X
  1291. XRose                                                            [Page 6]
  1292. X
  1293. XRFC 1082                 POP3 Extended Service             November 1988
  1294. X
  1295. X
  1296. X   XTND BBOARDS [name]
  1297. X   Arguments: the name of a discussion group (optionally)
  1298. X   Restrictions: may only be given in the TRANSACTION state.
  1299. X   Discussion:
  1300. X
  1301. X   If an argument was given, the POP3 server closes the current
  1302. X   maildrop.  The POP3 server then validates the argument as the name of
  1303. X   a discussion group.  If this is successful, it opens the maildrop
  1304. X   associated with the group, and returns a multi-line response
  1305. X   containing the discussion group listing.  If the discussion group
  1306. X   named is not valid, or the associated archive maildrop is not
  1307. X   readable by the user, then an error response is returned.
  1308. X
  1309. X   If no argument was given, the POP3 server issues a multi-line
  1310. X   response.  After the initial +OK, for each discussion group known,
  1311. X   the POP3 server responds with a line containing the listing for that
  1312. X   discussion group.  Note that only world-readable discussion groups
  1313. X   are included in the multi-line response.
  1314. X
  1315. X   In order to aid user agents, this memo requires an extension to the
  1316. X   scan listing when an "XTND BBOARDS" command has been given.
  1317. X   Normally, a scan listing, as generated by the LIST, takes the form:
  1318. X
  1319. X          MSGNO SIZE
  1320. X
  1321. X   where MSGNO is the number of the message being listed and SIZE is the
  1322. X   size of the message in octets.  When reading a maildrop accessed via
  1323. X   "XTND BBOARDS", the scan listing takes the form
  1324. X
  1325. X          MSGNO SIZE MAXIMA
  1326. X
  1327. X   where MAXIMA is the maxima that was assigned to the message when it
  1328. X   was placed in the BBoard.
  1329. X
  1330. X   Possible Responses:
  1331. X       +OK XTND
  1332. X       -ERR no such bboard
  1333. X   Examples:
  1334. X       C:    XTND BBOARDS
  1335. X       S:    +OK XTND
  1336. X       S:    system 10
  1337. X       S:    mh-users 100
  1338. X       S:    .
  1339. X       C:    XTND BBOARDS system
  1340. X       S:    + OK XTND
  1341. X       S:    system 10
  1342. X       S:    .
  1343. X
  1344. X
  1345. X
  1346. X
  1347. XRose                                                            [Page 7]
  1348. X
  1349. XRFC 1082                 POP3 Extended Service             November 1988
  1350. X
  1351. X
  1352. X   XTND ARCHIVE name
  1353. X   Arguments: the name of a discussion group (required)
  1354. X   Restrictions: may only be given in the TRANSACTION state.
  1355. X   Discussion:
  1356. X
  1357. X   The POP3 server closes the current maildrop.  The POP3 server then
  1358. X   validates the argument as the name of a discussion group.  If this is
  1359. X   successful, it opens the archive maildrop associated with the group,
  1360. X   and returns a multi-line response containing the discussion group
  1361. X   listing.  If the discussion group named is not valid, or the
  1362. X   associated archive maildrop is not readable by the user, then an
  1363. X   error response is returned.
  1364. X
  1365. X   In addition, the scan listing generated by the LIST command is
  1366. X   augmented (as described above).
  1367. X
  1368. X   Possible Responses:
  1369. X       +OK XTND
  1370. X       -ERR no such bboard Examples:
  1371. X       C:    XTND ARCHIVE system
  1372. X       S:    + OK XTND
  1373. X       S:    system 3
  1374. X       S:    .
  1375. X
  1376. X   XTND X-BBOARDS name
  1377. X   Arguments: the name of a discussion group (required)
  1378. X   Restrictions: may only be given in the TRANSACTION state.
  1379. X   Discussion:
  1380. X
  1381. X   The POP3 server validates the argument as the name of a
  1382. X   discussion group.  If this is unsuccessful, then an error
  1383. X   response is returned.  Otherwise a multi-line response is
  1384. X   returned.  The first 14 lines of this response (after the
  1385. X   initial +OK) are defined in this memo.  Minimal implementations
  1386. X   need not include other information (and may omit certain
  1387. X   information, outputing a bare CRLF pair).  More advanced
  1388. X   implementations may include other information.
  1389. X
  1390. X           Line    Information (refer to "Definition of Terms")
  1391. X           ----    -----------
  1392. X             1     NAME
  1393. X             2     ALIASES, separated by SP
  1394. X             3     system-specific: maildrop
  1395. X             4     system-specific: archive maildrop
  1396. X             5     system-specific: information
  1397. X             6     system-specific: maildrop map
  1398. X             7     system-specific: encrypted password
  1399. X             8     system-specific: local leaders, separated by SP
  1400. X
  1401. X
  1402. X
  1403. XRose                                                            [Page 8]
  1404. X
  1405. XRFC 1082                 POP3 Extended Service             November 1988
  1406. X
  1407. X
  1408. X             9     ADDRESS
  1409. X            10     REQUEST
  1410. X            11     system-specific: incoming feed
  1411. X            12     system-specific: outgoing feeds
  1412. X            13     FLAGS SP MAXIMA
  1413. X            14     LASTDATE
  1414. X
  1415. X   Most of this information is entirely too specific to the UCI Version
  1416. X   of the Rand MH Message Handling System [MRose85].  Nevertheless,
  1417. X   lines 1, 2, 9, 10, 13, and 14 are of general interest, regardless of
  1418. X   the implementation.
  1419. X
  1420. X           Possible Responses:
  1421. X               +OK XTND
  1422. X               -ERR no such bboard
  1423. X           Examples:
  1424. X               C:    XTND X-BBOARDS system
  1425. X               S:    + OK XTND
  1426. X               S:    system
  1427. X               S:    local general
  1428. X               S:    /usr/bboards/system.mbox
  1429. X               S:    /usr/bboards/archive/system.mbox
  1430. X               S:    /usr/bboards/.system.cnt
  1431. X               S:    /usr/bboards/.system.map
  1432. X               S:    *
  1433. X               S:    mother
  1434. X               S:    system@nrtc.northrop.com
  1435. X               S:    system-request@nrtc.northrop.com
  1436. X               S:
  1437. X               S:    dist-system@nrtc-gremlin.northrop.com
  1438. X               S:    01 10
  1439. X               S:    Thu, 19 Dec 85 00:08:49 -0800
  1440. X               S:    .
  1441. X
  1442. XPolicy Notes
  1443. X
  1444. X   Depending on the particular entity administrating the POP3 service
  1445. X   host, two additional policies might be implemented:
  1446. X
  1447. X   1.  Private Discussion Groups
  1448. X
  1449. X   In the general case, discussion groups are world-readable, any user,
  1450. X   once logged in (via a terminal, terminal server, or POP3, etc.), is
  1451. X   able to read the maildrop for each discussion group known to the POP3
  1452. X   service host.  Nevertheless, it is desirable, usually for privacy
  1453. X   reasons, to implement private discussion groups as well.
  1454. X
  1455. X   Support of this is consistent with the extensions outlined in this
  1456. X
  1457. X
  1458. X
  1459. XRose                                                            [Page 9]
  1460. X
  1461. XRFC 1082                 POP3 Extended Service             November 1988
  1462. X
  1463. X
  1464. X   memo.  Once the AUTHORIZATION state has successfully concluded, the
  1465. X   POP3 server grants the user access to exactly those discussion groups
  1466. X   the POP3 service host permits the authenticated user to access.  As a
  1467. X   "security" feature, discussion groups associated with unreadable
  1468. X   maildrops should not be listed in a positive response to the XTND
  1469. X   BBOARDS command.
  1470. X
  1471. X   2.  Anonymous POP3 Users
  1472. X
  1473. X   In order to minimize the authentication problem, a policy permitting
  1474. X   "anonymous" access to the world-readable maildrops for discussion
  1475. X   groups on the POP3 server may be implemented.
  1476. X
  1477. X   Support of this is consistent with the extensions outlined in this
  1478. X   memo.  The POP3 server can be modified to accept a USER command for a
  1479. X   well-known pseudonym (i.e., "anonymous") which is valid with any PASS
  1480. X   command.  As a "security" feature, it is advisable to limit this kind
  1481. X   of access to only hosts at the local site, or to hosts named in an
  1482. X   access list.
  1483. X
  1484. XExperiences and Conclusions
  1485. X
  1486. X   All of the facilities described in this memo and in [RFC1081] have
  1487. X   been implemented in MH #6.1.  Initial experiences have been, on the
  1488. X   whole, very positive.
  1489. X
  1490. X   After the first implementation, some performance tuning was required.
  1491. X   This consisted primarily of caching the datastructures which describe
  1492. X   discussion groups in the POP3 server.  A second optimization
  1493. X   pertained to the client:  the program most commonly used to read
  1494. X   BBoards in MH was modified to retrieve messages only when needed.
  1495. X   Two schemes are used:
  1496. X
  1497. X         o If only the headers (and the first few lines of the body) of
  1498. X           the message are required (e.g., for a scan listing), then only
  1499. X           these are retrieved.  The resulting output is then cached, on
  1500. X           a per-message basis.
  1501. X
  1502. X         o If the entire message is required, then it is retrieved intact,
  1503. X            and cached locally.
  1504. X
  1505. X   With these optimizations, response time is quite adequate when the
  1506. X   POP3 server and client are connected via a high-speed local area
  1507. X   network.  In fact, the author uses this mechanism to access certain
  1508. X   private discussion groups over the Internet.  In this case, response
  1509. X   is still good.  When a 9.6Kbps modem is inserted in the path,
  1510. X   response went from good to almost tolerable (fortunately the author
  1511. X   only reads a few discussion groups in this fashion).
  1512. X
  1513. X
  1514. X
  1515. XRose                                                           [Page 10]
  1516. X
  1517. XRFC 1082                 POP3 Extended Service             November 1988
  1518. X
  1519. X
  1520. X   To conclude: the POP3 is a good thing, not only for personal mail but
  1521. X   for discussion group mail as well.
  1522. X
  1523. X
  1524. XReferences
  1525. X
  1526. X     [RFC1081] Rose, M., "Post Office Protocol - Verison 3 (POP3)", RFC
  1527. X               1081, TWG, November 1988.
  1528. X
  1529. X     [MRose85] Rose, M., and J. Romine, "The Rand MH Message Handling
  1530. X               System: User's Manual", University of California, Irvine,
  1531. X               November 1985.
  1532. X
  1533. X     [RFC822]  Crocker, D., "Standard for the Format of ARPA-Internet
  1534. X               Text Messages", RFC 822, University of Delaware, August
  1535. X               1982.
  1536. X
  1537. X     [RFC918]  Reynolds, J., "Post Office Protocol", RFC 918,
  1538. X               USC/Information Sciences Institute, October 1984.
  1539. X
  1540. X     [RFC937]  Butler, M., J. Postel, D. Chase, J. Goldberger, and J.
  1541. X               Reynolds, "Post Office Protocol - Version 2", RFC 937,
  1542. X               USC/Information Sciences Institute, February 1985.
  1543. X
  1544. XAuthor's Address:
  1545. X
  1546. X
  1547. X   Marshall Rose
  1548. X   The Wollongong Group
  1549. X   1129 San Antonio Rd.
  1550. X   Palo Alto, California 94303
  1551. X
  1552. X   Phone: (415) 962-7100
  1553. X
  1554. X   Email: MRose@TWG.COM
  1555. X
  1556. X
  1557. X
  1558. X
  1559. X
  1560. X
  1561. X
  1562. X
  1563. X
  1564. X
  1565. X
  1566. X
  1567. X
  1568. X
  1569. X
  1570. X
  1571. XRose                                                           [Page 11]
  1572. X
  1573. SHAR_EOF
  1574. fi
  1575. if test -f 'pop_dele.c'
  1576. then
  1577.     echo shar: "will not over-write existing file 'pop_dele.c'"
  1578. else
  1579. sed 's/^X//' << \SHAR_EOF > 'pop_dele.c'
  1580. X/*
  1581. X * Copyright (c) 1989 Regents of the University of California.
  1582. X * All rights reserved.  The Berkeley software License Agreement
  1583. X * specifies the terms and conditions for redistribution.
  1584. X */
  1585. X
  1586. X#ifndef lint
  1587. Xstatic char copyright[] = "Copyright (c) 1990 Regents of the University of California.\nAll rights reserved.\n";
  1588. Xstatic char SccsId[] = "@(#)@(#)pop_dele.c    2.1  2.1 3/18/91";
  1589. X#endif not lint
  1590. X
  1591. X#include <stdio.h>
  1592. X#include <sys/types.h>
  1593. X#include <ctype.h>
  1594. X#include "popper.h"
  1595. X
  1596. X/* 
  1597. X *  dele:   Delete a message from the POP maildrop
  1598. X */
  1599. Xpop_dele (p)
  1600. XPOP     *   p;
  1601. X{
  1602. X    MsgInfoList     *   mp;         /*  Pointer to message info list */
  1603. X    int                 msg_num;
  1604. X
  1605. X    /*  Convert the message number parameter to an integer */
  1606. X    msg_num = atoi(p->pop_parm[1]);
  1607. X
  1608. X    /*  Is requested message out of range? */
  1609. X    if ((msg_num < 1) || (msg_num > p->msg_count))
  1610. X        return (pop_msg (p,POP_FAILURE,"Message %u does not exist.",msg_num));
  1611. X
  1612. X    /*  Get a pointer to the message in the message list */
  1613. X    mp = &(p->mlp[msg_num-1]);
  1614. X
  1615. X    /*  Is the message already flagged for deletion? */
  1616. X    if (mp->del_flag)
  1617. X        return (pop_msg (p,POP_FAILURE,"Message %u has already been deleted.",
  1618. X            msg_num));
  1619. X
  1620. X    /*  Flag the message for deletion */
  1621. X    mp->del_flag = TRUE;
  1622. X
  1623. X#ifdef DEBUG
  1624. X    if(p->debug)
  1625. X        pop_log(p,POP_DEBUG,"Deleting message %u at offset %ld of length %ld\n",
  1626. X            mp->number,mp->offset,mp->length);
  1627. X#endif DEBUG
  1628. X
  1629. X    /*  Update the messages_deleted and bytes_deleted counters */
  1630. X    p->msgs_deleted++;
  1631. X    p->bytes_deleted += mp->length;
  1632. X
  1633. X    /*  Update the last-message-accessed number if it is lower than 
  1634. X        the deleted message */
  1635. X    if (p->last_msg < msg_num) p->last_msg = msg_num;
  1636. X
  1637. X    return (pop_msg (p,POP_SUCCESS,"Message %u has been deleted.",msg_num));
  1638. X}
  1639. SHAR_EOF
  1640. fi
  1641. if test -f 'pop_dropcopy.c'
  1642. then
  1643.     echo shar: "will not over-write existing file 'pop_dropcopy.c'"
  1644. else
  1645. sed 's/^X//' << \SHAR_EOF > 'pop_dropcopy.c'
  1646. X/*
  1647. X * Copyright (c) 1989 Regents of the University of California.
  1648. X * All rights reserved.  The Berkeley software License Agreement
  1649. X * specifies the terms and conditions for redistribution.
  1650. X */
  1651. X
  1652. X#ifndef lint
  1653. Xstatic char copyright[] = "Copyright (c) 1990 Regents of the University of California.\nAll rights reserved.\n";
  1654. Xstatic char SccsId[] = "@(#)@(#)pop_dropcopy.c    2.6  2.6 4/3/91";
  1655. X#endif not lint
  1656. X
  1657. X#include <errno.h>
  1658. X#include <stdio.h>
  1659. X#include <sys/types.h>
  1660. X#include <strings.h>
  1661. X#include <sys/stat.h>
  1662. X#include <sys/file.h>
  1663. X#include <pwd.h>
  1664. X#include "popper.h"
  1665. X
  1666. Xextern int      errno;
  1667. Xextern int      sys_nerr;
  1668. Xextern char    *sys_errlist[];
  1669. X
  1670. X/* 
  1671. X *  dropcopy:   Make a temporary copy of the user's mail drop and 
  1672. X *  save a stream pointer for it.
  1673. X */
  1674. X
  1675. Xpop_dropcopy(p,pwp)
  1676. XPOP     *   p;
  1677. Xstruct passwd    *    pwp;
  1678. X{
  1679. X    int                     mfd;                    /*  File descriptor for 
  1680. X                                                        the user's maildrop */
  1681. X    int                     dfd;                    /*  File descriptor for 
  1682. X                                                        the SERVER maildrop */
  1683. X    FILE            *tf;            /*  The temp file */
  1684. X    char            template[POP_TMPSIZE];  /*  Temp name holder */
  1685. X    char                    buffer[BUFSIZ];         /*  Read buffer */
  1686. X    long                    offset;                 /*  Old/New boundary */
  1687. X    int                     nchar;                  /*  Bytes written/read */
  1688. X    struct stat             mybuf;                  /*  For lstat() */
  1689. X
  1690. X    /*  Create a temporary maildrop into which to copy the updated maildrop */
  1691. X    (void)sprintf(p->temp_drop,POP_DROP,p->user);
  1692. X
  1693. X#ifdef DEBUG
  1694. X    if(p->debug)
  1695. X        pop_log(p,POP_DEBUG,"Creating temporary maildrop '%s'",
  1696. X            p->temp_drop);
  1697. X#endif DEBUG
  1698. X
  1699. X    /* Here we work to make sure the user doesn't cause us to remove or
  1700. X     * write over existing files by limiting how much work we do while
  1701. X     * running as root.
  1702. X     */
  1703. X
  1704. X    /* First create a unique file.  Would prefer mkstemp, but Ultrix...*/
  1705. X    strcpy(template,POP_TMPDROP);
  1706. X    (void) mktemp(template);
  1707. X    if ( (tf=fopen(template,"w+")) == NULL ) {    /* failure, bail out    */
  1708. X        pop_log(p,POP_PRIORITY,
  1709. X            "Unable to create temporary temporary maildrop '%s': %s",template,
  1710. X                (errno < sys_nerr) ? sys_errlist[errno] : "") ;
  1711. X        return pop_msg(p,POP_FAILURE,
  1712. X        "System error, can't create temporary file.");
  1713. X    }
  1714. X
  1715. X    /* Now give this file to the user    */
  1716. X    (void) chown(template,pwp->pw_uid, pwp->pw_gid);
  1717. X    (void) chmod(template,0600);
  1718. X
  1719. X    /* Now link this file to the temporary maildrop.  If this fails it
  1720. X     * is probably because the temporary maildrop already exists.  If so,
  1721. X     * this is ok.  We can just go on our way, because by the time we try
  1722. X     * to write into the file we will be running as the user.
  1723. X     */
  1724. X    (void) link(template,p->temp_drop);
  1725. X    (void) fclose(tf);
  1726. X    (void) unlink(template);
  1727. X
  1728. X    /* Now we run as the user. */
  1729. X    (void) setuid(pwp->pw_uid);
  1730. X    (void) setgid(pwp->pw_gid);
  1731. X
  1732. X#ifdef DEBUG
  1733. X    if(p->debug)pop_log(p,POP_DEBUG,"uid = %u, gid = %u",getuid(),getgid());
  1734. X#endif DEBUG
  1735. X
  1736. X    /* Open for append,  this solves the crash recovery problem */
  1737. X    if ((dfd = open(p->temp_drop,O_RDWR|O_APPEND|O_CREAT,0600)) == -1){
  1738. X        pop_log(p,POP_PRIORITY,
  1739. X            "Unable to open temporary maildrop '%s': %s",p->temp_drop,
  1740. X                (errno < sys_nerr) ? sys_errlist[errno] : "") ;
  1741. X        return pop_msg(p,POP_FAILURE,
  1742. X        "System error, can't open temporary file, do you own it?");
  1743. X    }
  1744. X
  1745. X    /*  Lock the temporary maildrop */
  1746. X    if ( flock (dfd, LOCK_EX|LOCK_NB) == -1 ) 
  1747. X    switch(errno) {
  1748. X        case EWOULDBLOCK:
  1749. X            return pop_msg(p,POP_FAILURE,
  1750. X                 "Maildrop lock busy!  Is another session active?");
  1751. X            /* NOTREACHED */
  1752. X        default:
  1753. X            return pop_msg(p,POP_FAILURE,"flock: '%s': %s", p->temp_drop,
  1754. X                (errno < sys_nerr) ? sys_errlist[errno] : "");
  1755. X            /* NOTREACHED */
  1756. X        }
  1757. X    
  1758. X    /* May have grown or shrunk between open and lock! */
  1759. X    offset = lseek(dfd,0L,L_XTND);
  1760. X
  1761. X    /*  Open the user's maildrop, If this fails,  no harm in assuming empty */
  1762. X    if ((mfd = open(p->drop_name,O_RDWR)) > 0) {
  1763. X
  1764. X        /*  Lock the maildrop */
  1765. X        if (flock (mfd,LOCK_EX) == -1) {
  1766. X            (void)close(mfd) ;
  1767. X            return pop_msg(p,POP_FAILURE, "flock: '%s': %s", p->temp_drop,
  1768. X                (errno < sys_nerr) ? sys_errlist[errno] : "");
  1769. X        }
  1770. X
  1771. X        /*  Copy the actual mail drop into the temporary mail drop */
  1772. X        while ( (nchar=read(mfd,buffer,BUFSIZ)) > 0 )
  1773. X            if ( nchar != write(dfd,buffer,nchar) ) {
  1774. X                nchar = -1 ;
  1775. X                break ;
  1776. X            }
  1777. X
  1778. X        if ( nchar != 0 ) {
  1779. X            /* Error adding new mail.  Truncate to original size,
  1780. X               and leave the maildrop as is.  The user will not 
  1781. X               see the new mail until the error goes away.
  1782. X               Should let them process the current backlog,  in case
  1783. X               the error is a quota problem requiring deletions! */
  1784. X            (void)ftruncate(dfd,offset) ;
  1785. X        } else {
  1786. X            /* Mail transferred!  Zero the mail drop NOW,  that we
  1787. X               do not have to do gymnastics to figure out what's new
  1788. X               and what is old later */
  1789. X            (void)ftruncate(mfd,0L) ;
  1790. X        }
  1791. X
  1792. X        /*  Close the actual mail drop */
  1793. X        (void)close (mfd);
  1794. X    }
  1795. X
  1796. X    /*  Acquire a stream pointer for the temporary maildrop */
  1797. X    if ( (p->drop = fdopen(dfd,"a+")) == NULL ) {
  1798. X        (void)close(dfd) ;
  1799. X        return pop_msg(p,POP_FAILURE,"Cannot assign stream for %s",
  1800. X            p->temp_drop);
  1801. X    }
  1802. X
  1803. X    rewind (p->drop);
  1804. X
  1805. X    return(POP_SUCCESS);
  1806. X}
  1807. SHAR_EOF
  1808. fi
  1809. if test -f 'pop_dropinfo.c'
  1810. then
  1811.     echo shar: "will not over-write existing file 'pop_dropinfo.c'"
  1812. else
  1813. sed 's/^X//' << \SHAR_EOF > 'pop_dropinfo.c'
  1814. X/*
  1815. X * Copyright (c) 1989 Regents of the University of California.
  1816. X * All rights reserved.  The Berkeley software License Agreement
  1817. X * specifies the terms and conditions for redistribution.
  1818. X */
  1819. X
  1820. X#ifndef lint
  1821. Xstatic char copyright[] = "Copyright (c) 1990 Regents of the University of California.\nAll rights reserved.\n";
  1822. Xstatic char SccsId[] = "@(#)@(#)pop_dropinfo.c    2.1  2.1 3/18/91";
  1823. X#endif not lint
  1824. X
  1825. X#include <errno.h>
  1826. X#include <stdio.h>
  1827. X#include <sys/types.h>
  1828. X#include <strings.h>
  1829. X#include <sys/stat.h>
  1830. X#include <sys/file.h>
  1831. X#include "popper.h"
  1832. X
  1833. Xextern int      errno;
  1834. Xextern int      sys_nerr;
  1835. Xextern char    *sys_errlist[];
  1836. X
  1837. X/* 
  1838. X *  dropinfo:   Extract information about the POP maildrop and store 
  1839. X *  it for use by the other POP routines.
  1840. X */
  1841. X
  1842. Xpop_dropinfo(p)
  1843. XPOP     *   p;
  1844. X{
  1845. X    char                    buffer[BUFSIZ];         /*  Read buffer */
  1846. X    MsgInfoList         *   mp;                     /*  Pointer to message 
  1847. X                                                        info list */
  1848. X    register int            msg_num;                /*  Current message 
  1849. X                                                        counter */
  1850. X    int                     nchar;                  /*  Bytes written/read */
  1851. X
  1852. X    /*  Initialize maildrop status variables in the POP parameter block */
  1853. X    p->msg_count = 0;
  1854. X    p->msgs_deleted = 0;
  1855. X    p->last_msg = 0;
  1856. X    p->bytes_deleted = 0;
  1857. X    p->drop_size = 0;
  1858. X
  1859. X    /*  Allocate memory for message information structures */
  1860. X    p->msg_count = ALLOC_MSGS;
  1861. X    p->mlp = (MsgInfoList *)calloc((unsigned)p->msg_count,sizeof(MsgInfoList));
  1862. X    if (p->mlp == NULL){
  1863. X        (void)fclose (p->drop);
  1864. X        p->msg_count = 0;
  1865. X        return pop_msg (p,POP_FAILURE,
  1866. X            "Can't build message list for '%s': Out of memory", p->user);
  1867. X    }
  1868. X
  1869. X    rewind (p->drop);
  1870. X
  1871. X    /*  Scan the file, loading the message information list with 
  1872. X        information about each message */
  1873. X
  1874. X    for (msg_num = p->drop_size = 0, mp = p->mlp - 1;
  1875. X             fgets(buffer,MAXMSGLINELEN,p->drop);) {
  1876. X
  1877. X        nchar  = strlen(buffer);
  1878. X
  1879. X        if (strncmp(buffer,"From ",5) == 0) {
  1880. X
  1881. X            if (++msg_num > p->msg_count) {
  1882. X                p->mlp=(MsgInfoList *) realloc(p->mlp,
  1883. X                    (p->msg_count+=ALLOC_MSGS)*sizeof(MsgInfoList));
  1884. X                if (p->mlp == NULL){
  1885. X                    (void)fclose (p->drop);
  1886. X                    p->msg_count = 0;
  1887. X                    return pop_msg (p,POP_FAILURE,
  1888. X                        "Can't build message list for '%s': Out of memory",
  1889. X                            p->user);
  1890. X                }
  1891. X                mp = p->mlp + msg_num - 2;
  1892. X            }
  1893. X#ifdef DEBUG
  1894. X            if(p->debug)
  1895. X                pop_log(p,POP_DEBUG,
  1896. X                    "Msg %u at offset %ld is %ld octets long and has %u lines.",
  1897. X                        mp->number,mp->offset,mp->length,mp->lines);
  1898. X#endif DEBUG
  1899. X            ++mp;
  1900. X            mp->number = msg_num;
  1901. X            mp->length = 0;
  1902. X            mp->lines = 0;
  1903. X            mp->offset = ftell(p->drop) - nchar;
  1904. X            mp->del_flag = FALSE;
  1905. X            mp->retr_flag = FALSE;
  1906. X#ifdef DEBUG
  1907. X            if(p->debug)
  1908. X                pop_log(p,POP_DEBUG, "Msg %u being added to list", mp->number);
  1909. X#endif DEBUG
  1910. X        }
  1911. X        mp->length += nchar;
  1912. X        p->drop_size += nchar;
  1913. X        mp->lines++;
  1914. X    }
  1915. X    p->msg_count = msg_num;
  1916. X
  1917. X#ifdef DEBUG
  1918. X    if(p->debug && msg_num > 0) {
  1919. X        register    i;
  1920. X        for (i = 0, mp = p->mlp; i < p->msg_count; i++, mp++)
  1921. X            pop_log(p,POP_DEBUG,
  1922. X                "Msg %u at offset %ld is %ld octets long and has %u lines.",
  1923. X                    mp->number,mp->offset,mp->length,mp->lines);
  1924. X    }
  1925. X#endif DEBUG
  1926. X
  1927. X    return(POP_SUCCESS);
  1928. X}
  1929. SHAR_EOF
  1930. fi
  1931. if test -f 'pop_get_command.c'
  1932. then
  1933.     echo shar: "will not over-write existing file 'pop_get_command.c'"
  1934. else
  1935. sed 's/^X//' << \SHAR_EOF > 'pop_get_command.c'
  1936. X/*
  1937. X * Copyright (c) 1989 Regents of the University of California.
  1938. X * All rights reserved.  The Berkeley software License Agreement
  1939. X * specifies the terms and conditions for redistribution.
  1940. X */
  1941. X
  1942. X#ifndef lint
  1943. Xstatic char copyright[] = "Copyright (c) 1990 Regents of the University of California.\nAll rights reserved.\n";
  1944. Xstatic char SccsId[] = "@(#)@(#)pop_get_command.c    2.1  2.1 3/18/91";
  1945. X#endif not lint
  1946. X
  1947. X#include <stdio.h>
  1948. X#include <sys/types.h>
  1949. X#include <strings.h>
  1950. X#include "popper.h"
  1951. X
  1952. X/* 
  1953. X *  get_command:    Extract the command from an input line form a POP client
  1954. X */
  1955. X
  1956. Xstatic state_table states[] = {
  1957. X        auth1,  "user", 1,  1,  pop_user,   {auth1, auth2},
  1958. X        auth2,  "pass", 1,  1,  pop_pass,   {auth1, trans},
  1959. X#ifdef RPOP
  1960. X        auth2,  "rpop", 1,  1,  pop_rpop,   {auth1, trans},
  1961. X#endif RPOP
  1962. X        auth1,  "quit", 0,  0,  pop_quit,   {halt,  halt},
  1963. X        auth2,  "quit", 0,  0,  pop_quit,   {halt,  halt},
  1964. X        trans,  "stat", 0,  0,  pop_stat,   {trans, trans},
  1965. X        trans,  "list", 0,  1,  pop_list,   {trans, trans},
  1966. X        trans,  "retr", 1,  1,  pop_send,   {trans, trans},
  1967. X        trans,  "dele", 1,  1,  pop_dele,   {trans, trans},
  1968. X        trans,  "noop", 0,  0,  NULL,       {trans, trans},
  1969. X        trans,  "rset", 0,  0,  pop_rset,   {trans, trans},
  1970. X        trans,  "top",  2,  2,  pop_send,   {trans, trans},
  1971. X        trans,  "last", 0,  0,  pop_last,   {trans, trans},
  1972. X        trans,  "xtnd", 1,  99, pop_xtnd,   {trans, trans},
  1973. X        trans,  "quit", 0,  0,  pop_updt,   {halt,  halt},
  1974. X        (state) 0,  NULL,   0,  0,  NULL,       {halt,  halt},
  1975. X};
  1976. X
  1977. Xstate_table *pop_get_command(p,mp)
  1978. XPOP             *   p;
  1979. Xregister char   *   mp;         /*  Pointer to unparsed line 
  1980. X                                    received from the client */
  1981. X{
  1982. X    state_table     *   s;
  1983. X    char                buf[MAXMSGLINELEN];
  1984. X
  1985. X    /*  Save a copy of the original client line */
  1986. X#ifdef DEBUG
  1987. X    if(p->debug) strcpy (buf,mp);
  1988. X#endif DEBUG
  1989. X
  1990. X    /*  Parse the message into the parameter array */
  1991. X    if ((p->parm_count = pop_parse(p,mp)) < 0) return(NULL);
  1992. X
  1993. X    /*  Do not log cleartext passwords */
  1994. X#ifdef DEBUG
  1995. X    if(p->debug){
  1996. X        if(strcmp(p->pop_command,"pass") == 0)
  1997. X            pop_log(p,POP_DEBUG,"Received: \"%s xxxxxxxxx\"",p->pop_command);
  1998. X        else {
  1999. X            /*  Remove trailing <LF> */
  2000. X            buf[strlen(buf)-2] = '\0';
  2001. X            pop_log(p,POP_DEBUG,"Received: \"%s\"",buf);
  2002. X        }
  2003. X    }
  2004. X#endif DEBUG
  2005. X
  2006. X    /*  Search for the POP command in the command/state table */
  2007. X    for (s = states; s->command; s++) {
  2008. X
  2009. X        /*  Is this a valid command for the current operating state? */
  2010. X        if (strcmp(s->command,p->pop_command) == 0
  2011. X             && s->ValidCurrentState == p->CurrentState) {
  2012. X
  2013. X            /*  Were too few parameters passed to the command? */
  2014. X            if (p->parm_count < s->min_parms)
  2015. X                return((state_table *)pop_msg(p,POP_FAILURE,
  2016. X                    "Too few arguments for the %s command.",p->pop_command));
  2017. X
  2018. X            /*  Were too many parameters passed to the command? */
  2019. X            if (p->parm_count > s->max_parms)
  2020. X                return((state_table *)pop_msg(p,POP_FAILURE,
  2021. X                    "Too many arguments for the %s command.",p->pop_command));
  2022. X
  2023. X            /*  Return a pointer to the entry for this command in 
  2024. X                the command/state table */
  2025. X            return (s);
  2026. X        }
  2027. X    }
  2028. X    /*  The client command was not located in the command/state table */
  2029. X    return((state_table *)pop_msg(p,POP_FAILURE,
  2030. X        "Unknown command: \"%s\".",p->pop_command));
  2031. X}
  2032. SHAR_EOF
  2033. fi
  2034. if test -f 'pop_get_subcommand.c'
  2035. then
  2036.     echo shar: "will not over-write existing file 'pop_get_subcommand.c'"
  2037. else
  2038. sed 's/^X//' << \SHAR_EOF > 'pop_get_subcommand.c'
  2039. X/*
  2040. X * Copyright (c) 1989 Regents of the University of California.
  2041. X * All rights reserved.  The Berkeley software License Agreement
  2042. X * specifies the terms and conditions for redistribution.
  2043. X */
  2044. X
  2045. X#ifndef lint
  2046. Xstatic char copyright[] = "Copyright (c) 1990 Regents of the University of California.\nAll rights reserved.\n";
  2047. Xstatic char SccsId[] = "@(#)@(#)pop_get_subcommand.c    2.1  2.1 3/18/91";
  2048. X#endif not lint
  2049. X
  2050. X#include <stdio.h>
  2051. X#include <sys/types.h>
  2052. X#include <strings.h>
  2053. X#include "popper.h"
  2054. X
  2055. X/* 
  2056. X *  get_subcommand: Extract a POP XTND subcommand from a client input line
  2057. X */
  2058. X
  2059. Xstatic xtnd_table subcommands[] = {
  2060. X        "xmit",     0,  0,  pop_xmit,
  2061. X        NULL
  2062. X};
  2063. X
  2064. Xxtnd_table *pop_get_subcommand(p)
  2065. XPOP     *   p;
  2066. X{
  2067. X    xtnd_table      *   s;
  2068. X
  2069. X    /*  Search for the POP command in the command/state table */
  2070. X    for (s = subcommands; s->subcommand; s++) {
  2071. X
  2072. X        if (strcmp(s->subcommand,p->pop_subcommand) == 0) {
  2073. X
  2074. X            /*  Were too few parameters passed to the subcommand? */
  2075. X            if ((p->parm_count-1) < s->min_parms)
  2076. X                return((xtnd_table *)pop_msg(p,POP_FAILURE,
  2077. X                    "Too few arguments for the %s %s command.",
  2078. X                        p->pop_command,p->pop_subcommand));
  2079. X
  2080. X            /*  Were too many parameters passed to the subcommand? */
  2081. X            if ((p->parm_count-1) > s->max_parms)
  2082. X                return((xtnd_table *)pop_msg(p,POP_FAILURE,
  2083. X                    "Too many arguments for the %s %s command.",
  2084. X                        p->pop_command,p->pop_subcommand));
  2085. X
  2086. X            /*  Return a pointer to the entry for this subcommand 
  2087. X                in the XTND command table */
  2088. X            return (s);
  2089. X        }
  2090. X    }
  2091. X    /*  The client subcommand was not located in the XTND command table */
  2092. X    return((xtnd_table *)pop_msg(p,POP_FAILURE,
  2093. X        "Unknown command: \"%s %s\".",p->pop_command,p->pop_subcommand));
  2094. X}
  2095. SHAR_EOF
  2096. fi
  2097. if test -f 'pop_init.c'
  2098. then
  2099.     echo shar: "will not over-write existing file 'pop_init.c'"
  2100. else
  2101. sed 's/^X//' << \SHAR_EOF > 'pop_init.c'
  2102. X/*
  2103. X * Copyright (c) 1989 Regents of the University of California.
  2104. X * All rights reserved.  The Berkeley software License Agreement
  2105. X * specifies the terms and conditions for redistribution.
  2106. X */
  2107. X
  2108. X#ifndef lint
  2109. Xstatic char copyright[] = "Copyright (c) 1990 Regents of the University of California.\nAll rights reserved.\n";
  2110. Xstatic char SccsId[] = "@(#)@(#)pop_init.c    2.1  2.1 3/18/91";
  2111. X#endif not lint
  2112. X
  2113. X#include <errno.h>
  2114. X#include <stdio.h>
  2115. X#include <sys/types.h>
  2116. X#include <sys/socket.h>
  2117. X#include <netinet/in.h>
  2118. X#include <netdb.h>
  2119. X#include <arpa/inet.h>
  2120. X#include "popper.h"
  2121. X
  2122. Xextern int      errno;
  2123. X
  2124. X/* 
  2125. X *  init:   Start a Post Office Protocol session
  2126. X */
  2127. X
  2128. Xpop_init(p,argcount,argmessage)
  2129. XPOP     *       p;
  2130. Xint             argcount;
  2131. Xchar    **      argmessage;
  2132. X{
  2133. X
  2134. X    struct sockaddr_in      cs;                 /*  Communication parameters */
  2135. X    struct hostent      *   ch;                 /*  Client host information */
  2136. X    int                     errflag = 0;
  2137. X    int                     c;
  2138. X    int                     len;
  2139. X    extern char         *   optarg;
  2140. X    int                     options = 0;
  2141. X    int                     sp = 0;             /*  Socket pointer */
  2142. X    char                *   trace_file_name;
  2143. X
  2144. X    /*  Initialize the POP parameter block */
  2145. X    bzero ((char *)p,(int)sizeof(POP));
  2146. X
  2147. X    /*  Save my name in a global variable */
  2148. X    p->myname = argmessage[0];
  2149. X
  2150. X    /*  Get the name of our host */
  2151. X    (void)gethostname(p->myhost,MAXHOSTNAMELEN);
  2152. X
  2153. X    /*  Open the log file */
  2154. X#ifdef SYSLOG42
  2155. X    (void)openlog(p->myname,0);
  2156. X#else
  2157. X    (void)openlog(p->myname,POP_LOGOPTS,POP_FACILITY);
  2158. X#endif
  2159. X
  2160. X    /*  Process command line arguments */
  2161. X    while ((c = getopt(argcount,argmessage,"dt:")) != EOF)
  2162. X        switch (c) {
  2163. X
  2164. X            /*  Debugging requested */
  2165. X            case 'd':
  2166. X                p->debug++;
  2167. X                options |= SO_DEBUG;
  2168. X                break;
  2169. X
  2170. X            /*  Debugging trace file specified */
  2171. X            case 't':
  2172. X                p->debug++;
  2173. X                if ((p->trace = fopen(optarg,"a+")) == NULL) {
  2174. X                    pop_log(p,POP_PRIORITY,
  2175. X                        "Unable to open trace file \"%s\", err = %d",
  2176. X                            optarg,errno);
  2177. X                    exit(-1);
  2178. X                }
  2179. X                trace_file_name = optarg;
  2180. X                break;
  2181. X
  2182. X            /*  Unknown option received */
  2183. X            default:
  2184. X                errflag++;
  2185. X        }
  2186. X
  2187. X    /*  Exit if bad options specified */
  2188. X    if (errflag) {
  2189. X        (void)fprintf(stderr,"Usage: %s [-d]\n",argmessage[0]);
  2190. X        exit(-1);
  2191. X    }
  2192. X
  2193. X    /*  Get the address and socket of the client to whom I am speaking */
  2194. X    len = sizeof(cs);
  2195. X    if (getpeername(sp,(struct sockaddr *)&cs,&len) < 0){
  2196. X        pop_log(p,POP_PRIORITY,
  2197. X            "Unable to obtain socket and address of client, err = %d",errno);
  2198. X        exit(-1);
  2199. X    }
  2200. X
  2201. X    /*  Save the dotted decimal form of the client's IP address 
  2202. X        in the POP parameter block */
  2203. X    p->ipaddr = inet_ntoa(cs.sin_addr);
  2204. X
  2205. X    /*  Save the client's port */
  2206. X    p->ipport = ntohs(cs.sin_port);
  2207. X
  2208. X    /*  Get the canonical name of the host to whom I am speaking */
  2209. X    ch = gethostbyaddr((char *) &cs.sin_addr, sizeof(cs.sin_addr), AF_INET);
  2210. X    if (ch == NULL){
  2211. X        pop_log(p,POP_PRIORITY,
  2212. X            "Unable to get canonical name of client, err = %d",errno);
  2213. X        p->client = p->ipaddr;
  2214. X    }
  2215. X    /*  Save the cannonical name of the client host in 
  2216. X        the POP parameter block */
  2217. X    else {
  2218. X
  2219. X#ifndef BIND43
  2220. X        p->client = ch->h_name;
  2221. X#else
  2222. X#       include <arpa/nameser.h>
  2223. X#       include <resolv.h>
  2224. X
  2225. X        /*  Distrust distant nameservers */
  2226. X        extern struct state     _res;
  2227. X        struct hostent      *   ch_again;
  2228. X        char            *   *   addrp;
  2229. X
  2230. X        /*  We already have a fully-qualified name */
  2231. X        _res.options &= ~RES_DEFNAMES;
  2232. X
  2233. X        /*  See if the name obtained for the client's IP 
  2234. X            address returns an address */
  2235. X        if ((ch_again = gethostbyname(ch->h_name)) == NULL) {
  2236. X            pop_log(p,POP_PRIORITY,
  2237. X                "Client at \"%s\" resolves to an unknown host name \"%s\"",
  2238. X                    p->ipaddr,ch->h_name);
  2239. X            p->client = p->ipaddr;
  2240. X        }
  2241. X        else {
  2242. X            /*  Save the host name (the previous value was 
  2243. X                destroyed by gethostbyname) */
  2244. X            p->client = ch_again->h_name;
  2245. X
  2246. X            /*  Look for the client's IP address in the list returned 
  2247. X                for its name */
  2248. X            for (addrp=ch_again->h_addr_list; *addrp; ++addrp)
  2249. X                if (bcmp(*addrp,&(cs.sin_addr),sizeof(cs.sin_addr)) == 0) break;
  2250. X
  2251. X            if (!*addrp) {
  2252. X                pop_log (p,POP_PRIORITY,
  2253. X                    "Client address \"%s\" not listed for its host name \"%s\"",
  2254. X                        p->ipaddr,ch->h_name);
  2255. X                p->client = p->ipaddr;
  2256. X            }
  2257. X        }
  2258. X#endif BIND43
  2259. X    }
  2260. X
  2261. X    /*  Create input file stream for TCP/IP communication */
  2262. X    if ((p->input = fdopen(sp,"r")) == NULL){
  2263. X        pop_log(p,POP_PRIORITY,
  2264. X            "Unable to open communication stream for input, err = %d",errno);
  2265. X        exit (-1);
  2266. X    }
  2267. X
  2268. X    /*  Create output file stream for TCP/IP communication */
  2269. X    if ((p->output = fdopen(sp,"w")) == NULL){
  2270. X        pop_log(p,POP_PRIORITY,
  2271. X            "Unable to open communication stream for output, err = %d",errno);
  2272. X        exit (-1);
  2273. X    }
  2274. X
  2275. X    pop_log(p,POP_PRIORITY,
  2276. X        "(v%s) Servicing request from \"%s\" at %s\n",
  2277. X            VERSION,p->client,p->ipaddr);
  2278. X
  2279. X#ifdef DEBUG
  2280. X    if (p->trace)
  2281. X        pop_log(p,POP_PRIORITY,
  2282. X            "Tracing session and debugging information in file \"%s\"",
  2283. X                trace_file_name);
  2284. X    else if (p->debug)
  2285. X        pop_log(p,POP_PRIORITY,"Debugging turned on");
  2286. X#endif DEBUG
  2287. X
  2288. X    return(POP_SUCCESS);
  2289. X}
  2290. SHAR_EOF
  2291. fi
  2292. if test -f 'pop_last.c'
  2293. then
  2294.     echo shar: "will not over-write existing file 'pop_last.c'"
  2295. else
  2296. sed 's/^X//' << \SHAR_EOF > 'pop_last.c'
  2297. X/*
  2298. X * Copyright (c) 1989 Regents of the University of California.
  2299. X * All rights reserved.  The Berkeley software License Agreement
  2300. X * specifies the terms and conditions for redistribution.
  2301. X */
  2302. X
  2303. X#ifndef lint
  2304. Xstatic char copyright[] = "Copyright (c) 1990 Regents of the University of California.\nAll rights reserved.\n";
  2305. Xstatic char SccsId[] = "@(#)@(#)pop_last.c    2.1  2.1 3/18/91";
  2306. X#endif not lint
  2307. X
  2308. X#include <stdio.h>
  2309. X#include <sys/types.h>
  2310. X#include "popper.h"
  2311. X
  2312. X/* 
  2313. X *  last:   Display the last message touched in a POP session
  2314. X */
  2315. X
  2316. Xint pop_last (p)
  2317. XPOP     *   p;
  2318. X{
  2319. X    return (pop_msg(p,POP_SUCCESS,"%u is the last message seen.",p->last_msg));
  2320. X}
  2321. SHAR_EOF
  2322. fi
  2323. if test -f 'pop_list.c'
  2324. then
  2325.     echo shar: "will not over-write existing file 'pop_list.c'"
  2326. else
  2327. sed 's/^X//' << \SHAR_EOF > 'pop_list.c'
  2328. X/*
  2329. X * Copyright (c) 1989 Regents of the University of California.
  2330. X * All rights reserved.  The Berkeley software License Agreement
  2331. X * specifies the terms and conditions for redistribution.
  2332. X */
  2333. X
  2334. X#ifndef lint
  2335. Xstatic char copyright[] = "Copyright (c) 1990 Regents of the University of California.\nAll rights reserved.\n";
  2336. Xstatic char SccsId[] = "@(#)@(#)pop_list.c    2.1  2.1 3/18/91";
  2337. X#endif not lint
  2338. X
  2339. X#include <stdio.h>
  2340. X#include <sys/types.h>
  2341. X#include "popper.h"
  2342. X
  2343. X/* 
  2344. X *  list:   List the contents of a POP maildrop
  2345. X */
  2346. X
  2347. Xint pop_list (p)
  2348. XPOP     *   p;
  2349. X{
  2350. X    MsgInfoList         *   mp;         /*  Pointer to message info list */
  2351. X    register int            i;
  2352. X    register int            msg_num;
  2353. X
  2354. X    /*  Was a message number provided? */
  2355. X    if (p->parm_count > 0) {
  2356. X        msg_num = atoi(p->pop_parm[1]);
  2357. X
  2358. X        /*  Is requested message out of range? */
  2359. X        if ((msg_num < 1) || (msg_num > p->msg_count))
  2360. X            return (pop_msg (p,POP_FAILURE,
  2361. X                "Message %u does not exist.",msg_num));
  2362. X
  2363. X        /*  Get a pointer to the message in the message list */
  2364. X        mp = &p->mlp[msg_num-1];
  2365. X
  2366. X        /*  Is the message already flagged for deletion? */
  2367. X        if (mp->del_flag)
  2368. X            return (pop_msg (p,POP_FAILURE,
  2369. X                "Message %u has been deleted.",msg_num));
  2370. X
  2371. X        /*  Display message information */
  2372. X        return (pop_msg(p,POP_SUCCESS,"%u %ld",msg_num,mp->length));
  2373. X    }
  2374. X    
  2375. X    /*  Display the entire list of messages */
  2376. X    pop_msg(p,POP_SUCCESS,
  2377. X        "%u messages (%ld octets)",
  2378. X            p->msg_count-p->msgs_deleted,p->drop_size-p->bytes_deleted);
  2379. X
  2380. X    /*  Loop through the message information list.  Skip deleted messages */
  2381. X    for (i = p->msg_count, mp = p->mlp; i > 0; i--, mp++) {
  2382. X        if (!mp->del_flag) 
  2383. X            (void)fprintf(p->output,"%u %ld\r\n",mp->number,mp->length);
  2384. X    }
  2385. X
  2386. X    /*  "." signals the end of a multi-line transmission */
  2387. X    (void)fprintf(p->output,".\r\n");
  2388. X    (void)fflush(p->output);
  2389. X
  2390. X    return(POP_SUCCESS);
  2391. X}
  2392. SHAR_EOF
  2393. fi
  2394. if test -f 'pop_log.c'
  2395. then
  2396.     echo shar: "will not over-write existing file 'pop_log.c'"
  2397. else
  2398. sed 's/^X//' << \SHAR_EOF > 'pop_log.c'
  2399. X/*
  2400. X * Copyright (c) 1989 Regents of the University of California.
  2401. X * All rights reserved.  The Berkeley software License Agreement
  2402. X * specifies the terms and conditions for redistribution.
  2403. X */
  2404. X
  2405. X#ifndef lint
  2406. Xstatic char copyright[] = "Copyright (c) 1990 Regents of the University of California.\nAll rights reserved.\n";
  2407. Xstatic char SccsId[] = "@(#)@(#)pop_log.c    2.1  2.1 3/18/91";
  2408. X#endif not lint
  2409. X
  2410. X#include <stdio.h>
  2411. X#include <sys/types.h>
  2412. X#include <varargs.h>
  2413. X#include "popper.h"
  2414. X
  2415. X/* 
  2416. X *  log:    Make a log entry
  2417. X */
  2418. X
  2419. Xstatic char msgbuf[MAXLINELEN];
  2420. X
  2421. Xpop_log(va_alist)
  2422. Xva_dcl
  2423. X{
  2424. X    va_list     ap;
  2425. X    POP     *   p;
  2426. X    int         stat;
  2427. X    char    *   format;
  2428. X
  2429. X    va_start(ap);
  2430. X    p = va_arg(ap,POP *);
  2431. X    stat = va_arg(ap,int);
  2432. X    format = va_arg(ap,char *);
  2433. X    va_end(ap);
  2434. X
  2435. X#ifdef HAVE_VSPRINTF
  2436. X        vsprintf(msgbuf,format,ap);
  2437. X#else
  2438. X        (void)sprintf (msgbuf,format,((int *)ap)[0],((int *)ap)[1],((int *)ap)[2],
  2439. X                ((int *)ap)[3],((int *)ap)[4],((int *)ap)[5]);
  2440. X#endif HAVE_VSPRINTF
  2441. X
  2442. X    if (p->debug && p->trace) {
  2443. X        (void)fprintf(p->trace,"%s\n",msgbuf);
  2444. X        (void)fflush(p->trace);
  2445. X    }
  2446. X    else {
  2447. X        syslog (stat,"%s",msgbuf);
  2448. X    }
  2449. X
  2450. X    return(stat);
  2451. X}
  2452. SHAR_EOF
  2453. fi
  2454. if test -f 'pop_lower.c'
  2455. then
  2456.     echo shar: "will not over-write existing file 'pop_lower.c'"
  2457. else
  2458. sed 's/^X//' << \SHAR_EOF > 'pop_lower.c'
  2459. X/*
  2460. X * Copyright (c) 1989 Regents of the University of California.
  2461. X * All rights reserved.  The Berkeley software License Agreement
  2462. X * specifies the terms and conditions for redistribution.
  2463. X */
  2464. X
  2465. X#ifndef lint
  2466. Xstatic char copyright[] = "Copyright (c) 1990 Regents of the University of California.\nAll rights reserved.\n";
  2467. Xstatic char SccsId[] = "@(#)@(#)pop_lower.c    2.1  2.1 3/18/91";
  2468. X#endif not lint
  2469. X
  2470. X#include <stdio.h>
  2471. X#include <sys/types.h>
  2472. X#include <ctype.h>
  2473. X
  2474. X/* 
  2475. X *  lower:  Convert a string to lowercase
  2476. X */
  2477. X
  2478. Xpop_lower (buf)
  2479. Xchar        *   buf;
  2480. X{
  2481. X    char        *   mp;
  2482. X
  2483. X    for (mp = buf; *mp; mp++)
  2484. X        if (isupper(*mp) && isupper(*mp)) *mp = (char)tolower((int)*mp);
  2485. X}
  2486. SHAR_EOF
  2487. fi
  2488. if test -f 'pop_msg.c'
  2489. then
  2490.     echo shar: "will not over-write existing file 'pop_msg.c'"
  2491. else
  2492. sed 's/^X//' << \SHAR_EOF > 'pop_msg.c'
  2493. X/*
  2494. X * Copyright (c) 1989 Regents of the University of California.
  2495. X * All rights reserved.  The Berkeley software License Agreement
  2496. X * specifies the terms and conditions for redistribution.
  2497. X */
  2498. X
  2499. X#ifndef lint
  2500. Xstatic char copyright[] = "Copyright (c) 1990 Regents of the University of California.\nAll rights reserved.\n";
  2501. Xstatic char SccsId[] = "@(#)@(#)pop_msg.c    2.1  2.1 3/18/91";
  2502. X#endif not lint
  2503. X
  2504. X#include <stdio.h>
  2505. X#include <sys/types.h>
  2506. X#include <strings.h>
  2507. X#include <varargs.h>
  2508. X#include "popper.h"
  2509. X
  2510. X/* 
  2511. X *  msg:    Send a formatted line to the POP client
  2512. X */
  2513. X
  2514. Xpop_msg(va_alist)
  2515. Xva_dcl
  2516. X{
  2517. X    POP             *   p;
  2518. X    int                 stat;               /*  POP status indicator */
  2519. X    char            *   format;             /*  Format string for the message */
  2520. X    va_list             ap;
  2521. X    register char   *   mp;
  2522. X    char                message[MAXLINELEN];
  2523. X
  2524. X    va_start(ap);
  2525. X    p = va_arg(ap, POP *);
  2526. X    stat = va_arg(ap, int);
  2527. X    format = va_arg(ap, char *);
  2528. X    va_end(ap);
  2529. X
  2530. X    /*  Point to the message buffer */
  2531. X    mp = message;
  2532. X
  2533. X    /*  Format the POP status code at the beginning of the message */
  2534. X    if (stat == POP_SUCCESS)
  2535. X        (void)sprintf (mp,"%s ",POP_OK);
  2536. X    else
  2537. X        (void)sprintf (mp,"%s ",POP_ERR);
  2538. X
  2539. X    /*  Point past the POP status indicator in the message message */
  2540. X    mp += strlen(mp);
  2541. X
  2542. X    /*  Append the message (formatted, if necessary) */
  2543. X    if (format) 
  2544. X#ifdef HAVE_VSPRINTF
  2545. X        vsprintf(mp,format,ap);
  2546. X#else
  2547. X        (void)sprintf(mp,format,((int *)ap)[0],((int *)ap)[1],((int *)ap)[2],
  2548. X                ((int *)ap)[3],((int *)ap)[4]);
  2549. X#endif HAVE_VSPRINTF
  2550. X    
  2551. X    /*  Log the message if debugging is turned on */
  2552. X#ifdef DEBUG
  2553. X    if (p->debug && stat == POP_SUCCESS)
  2554. X        pop_log(p,POP_DEBUG,"%s",message);
  2555. X#endif DEBUG
  2556. X
  2557. X    /*  Log the message if a failure occurred */
  2558. X    if (stat != POP_SUCCESS) 
  2559. X        pop_log(p,POP_PRIORITY,"%s",message);
  2560. X
  2561. X    /*  Append the <CR><LF> */
  2562. X    (void)strcat(message, "\r\n");
  2563. X        
  2564. X    /*  Send the message to the client */
  2565. X    (void)fputs(message,p->output);
  2566. X    (void)fflush(p->output);
  2567. X
  2568. X    return(stat);
  2569. X}
  2570. SHAR_EOF
  2571. fi
  2572. if test -f 'pop_parse.c'
  2573. then
  2574.     echo shar: "will not over-write existing file 'pop_parse.c'"
  2575. else
  2576. sed 's/^X//' << \SHAR_EOF > 'pop_parse.c'
  2577. X/*
  2578. X * Copyright (c) 1989 Regents of the University of California.
  2579. X * All rights reserved.  The Berkeley software License Agreement
  2580. X * specifies the terms and conditions for redistribution.
  2581. X */
  2582. X
  2583. X#ifndef lint
  2584. Xstatic char copyright[] = "Copyright (c) 1990 Regents of the University of California.\nAll rights reserved.\n";
  2585. Xstatic char SccsId[] = "@(#)@(#)pop_parse.c    2.1  2.1 3/18/91";
  2586. X#endif not lint
  2587. X
  2588. X#include <stdio.h>
  2589. X#include <sys/types.h>
  2590. X#include <ctype.h>
  2591. X#include "popper.h"
  2592. X
  2593. X/* 
  2594. X *  parse:  Parse a raw input line from a POP client 
  2595. X *  into null-delimited tokens
  2596. X */
  2597. X
  2598. Xpop_parse(p,buf)
  2599. XPOP         *   p;
  2600. Xchar        *   buf;        /*  Pointer to a message containing 
  2601. X                                the line from the client */
  2602. X{
  2603. X    char            *   mp;
  2604. X    register int        i;
  2605. X    
  2606. X    /*  Loop through the POP command array */
  2607. X    for (mp = buf, i = 0; ; i++) {
  2608. X    
  2609. X        /*  Skip leading spaces and tabs in the message */
  2610. X        while (isspace(*mp))mp++;
  2611. X
  2612. X        /*  Are we at the end of the message? */
  2613. X        if (*mp == 0) break;
  2614. X
  2615. X        /*  Have we already obtained the maximum allowable parameters? */
  2616. X        if (i >= MAXPARMCOUNT) {
  2617. X            pop_msg(p,POP_FAILURE,"Too many arguments supplied.");
  2618. X            return(-1);
  2619. X        }
  2620. X
  2621. X        /*  Point to the start of the token */
  2622. X        p->pop_parm[i] = mp;
  2623. X
  2624. X        /*  Search for the first space character (end of the token) */
  2625. X        while (!isspace(*mp) && *mp) mp++;
  2626. X
  2627. X        /*  Delimit the token with a null */
  2628. X        if (*mp) *mp++ = 0;
  2629. X    }
  2630. X
  2631. X    /*  Were any parameters passed at all? */
  2632. X    if (i == 0) return (-1);
  2633. X
  2634. X    /*  Convert the first token (POP command) to lower case */
  2635. X    pop_lower(p->pop_command);
  2636. X
  2637. X    /*  Return the number of tokens extracted minus the command itself */
  2638. X    return (i-1);
  2639. X    
  2640. X}
  2641. SHAR_EOF
  2642. fi
  2643. if test -f 'pop_pass.c'
  2644. then
  2645.     echo shar: "will not over-write existing file 'pop_pass.c'"
  2646. else
  2647. sed 's/^X//' << \SHAR_EOF > 'pop_pass.c'
  2648. X/*
  2649. X * Copyright (c) 1989 Regents of the University of California.
  2650. X * All rights reserved.  The Berkeley software License Agreement
  2651. X * specifies the terms and conditions for redistribution.
  2652. X */
  2653. X
  2654. X#ifndef lint
  2655. Xstatic char copyright[] = "Copyright (c) 1990 Regents of the University of California.\nAll rights reserved.\n";
  2656. Xstatic char SccsId[] = "@(#)@(#)pop_pass.c    2.3  2.3 4/2/91";
  2657. X#endif not lint
  2658. X
  2659. X#include <stdio.h>
  2660. X#include <sys/types.h>
  2661. X#include <strings.h>
  2662. X#include <pwd.h>
  2663. X#include "popper.h"
  2664. X
  2665. X/* 
  2666. X *  pass:   Obtain the user password from a POP client
  2667. X */
  2668. X
  2669. Xint pop_pass (p)
  2670. XPOP     *   p;
  2671. X{
  2672. X    register struct passwd  *   pw;
  2673. X    char *crypt();
  2674. X
  2675. X    /*  Look for the user in the password file */
  2676. X    if ((pw = getpwnam(p->user)) == NULL)
  2677. X        return (pop_msg(p,POP_FAILURE,
  2678. X            "Password supplied for \"%s\" is incorrect.",p->user));
  2679. X
  2680. X    /*  We don't accept connections from users with null passwords */
  2681. X    if (pw->pw_passwd == NULL)
  2682. X        return (pop_msg(p,POP_FAILURE,
  2683. X            "Password supplied for \"%s\" is incorrect.",p->user));
  2684. X
  2685. X    /*  Compare the supplied password with the password file entry */
  2686. X    if (strcmp (crypt (p->pop_parm[1], pw->pw_passwd), pw->pw_passwd) != 0)
  2687. X        return (pop_msg(p,POP_FAILURE,
  2688. X            "Password supplied for \"%s\" is incorrect.",p->user));
  2689. X
  2690. X    /*  Build the name of the user's maildrop */
  2691. X    (void)sprintf(p->drop_name,"%s/%s",POP_MAILDIR,p->user);
  2692. X
  2693. X    /*  Make a temporary copy of the user's maildrop */
  2694. X    /*    and set the group and user id */
  2695. X    if (pop_dropcopy(p,pw) != POP_SUCCESS) return (POP_FAILURE);
  2696. X
  2697. X    /*  Get information about the maildrop */
  2698. X    if (pop_dropinfo(p) != POP_SUCCESS) return(POP_FAILURE);
  2699. X
  2700. X    /*  Initialize the last-message-accessed number */
  2701. X    p->last_msg = 0;
  2702. X
  2703. X    /*  Authorization completed successfully */
  2704. X    return (pop_msg (p,POP_SUCCESS,
  2705. X        "%s has %u message(s) (%ld octets).",
  2706. X            p->user,p->msg_count,p->drop_size));
  2707. X}
  2708. SHAR_EOF
  2709. fi
  2710. if test -f 'pop_quit.c'
  2711. then
  2712.     echo shar: "will not over-write existing file 'pop_quit.c'"
  2713. else
  2714. sed 's/^X//' << \SHAR_EOF > 'pop_quit.c'
  2715. X/*
  2716. X * Copyright (c) 1989 Regents of the University of California.
  2717. X * All rights reserved.  The Berkeley software License Agreement
  2718. X * specifies the terms and conditions for redistribution.
  2719. X */
  2720. X
  2721. X#ifndef lint
  2722. Xstatic char copyright[] = "Copyright (c) 1990 Regents of the University of California.\nAll rights reserved.\n";
  2723. Xstatic char SccsId[] = "@(#)@(#)pop_quit.c    2.1  2.1 3/18/91";
  2724. X#endif not lint
  2725. X
  2726. X#include <stdio.h>
  2727. X#include <sys/types.h>
  2728. X#include "popper.h"
  2729. X
  2730. X/* 
  2731. X *  quit:   Terminate a POP session
  2732. X */
  2733. X
  2734. Xint pop_quit (p)
  2735. XPOP     *   p;
  2736. X{
  2737. X    /*  Release the message information list */
  2738. X    if (p->mlp) free ((char *)p->mlp);
  2739. X
  2740. X    return(POP_SUCCESS);
  2741. X}
  2742. SHAR_EOF
  2743. fi
  2744. if test -f 'pop_rset.c'
  2745. then
  2746.     echo shar: "will not over-write existing file 'pop_rset.c'"
  2747. else
  2748. sed 's/^X//' << \SHAR_EOF > 'pop_rset.c'
  2749. X/*
  2750. X * Copyright (c) 1989 Regents of the University of California.
  2751. X * All rights reserved.  The Berkeley software License Agreement
  2752. X * specifies the terms and conditions for redistribution.
  2753. X */
  2754. X
  2755. X#ifndef lint
  2756. Xstatic char copyright[] = "Copyright (c) 1990 Regents of the University of California.\nAll rights reserved.\n";
  2757. Xstatic char SccsId[] = "@(#)@(#)pop_rset.c    2.1  2.1 3/18/91";
  2758. X#endif not lint
  2759. X
  2760. X#include <stdio.h>
  2761. X#include <sys/types.h>
  2762. X#include "popper.h"
  2763. X
  2764. X/* 
  2765. X *  rset:   Unflag all messages flagged for deletion in a POP maildrop
  2766. X */
  2767. X
  2768. Xint pop_rset (p)
  2769. XPOP     *   p;
  2770. X{
  2771. X    MsgInfoList     *   mp;         /*  Pointer to the message info list */
  2772. X    register int        i;
  2773. X
  2774. X    /*  Unmark all the messages */
  2775. X    for (i = p->msg_count, mp = p->mlp; i > 0; i--, mp++)
  2776. X        mp->del_flag = FALSE; 
  2777. X    
  2778. X    /*  Reset the messages-deleted and bytes-deleted counters */
  2779. X    p->msgs_deleted = 0;
  2780. X    p->bytes_deleted = 0;
  2781. X    
  2782. X    /*  Reset the last-message-access flag */
  2783. X    p->last_msg = 0;
  2784. X
  2785. X    return (pop_msg(p,POP_SUCCESS,"Maildrop has %u messages (%ld octets)",
  2786. X        p->msg_count,p->drop_size));
  2787. X}
  2788. SHAR_EOF
  2789. fi
  2790. if test -f 'pop_send.c'
  2791. then
  2792.     echo shar: "will not over-write existing file 'pop_send.c'"
  2793. else
  2794. sed 's/^X//' << \SHAR_EOF > 'pop_send.c'
  2795. X/*
  2796. X * Copyright (c) 1989 Regents of the University of California.
  2797. X * All rights reserved.  The Berkeley software License Agreement
  2798. X * specifies the terms and conditions for redistribution.
  2799. X */
  2800. X
  2801. X#ifndef lint
  2802. Xstatic char copyright[] = "Copyright (c) 1990 Regents of the University of California.\nAll rights reserved.\n";
  2803. Xstatic char SccsId[] = "@(#)@(#)pop_send.c    2.1  2.1 3/18/91";
  2804. X#endif not lint
  2805. X
  2806. X#include <stdio.h>
  2807. X#include <sys/types.h>
  2808. X#include <strings.h>
  2809. X#include "popper.h"
  2810. X
  2811. X/* 
  2812. X *  send:   Send the header and a specified number of lines 
  2813. X *          from a mail message to a POP client.
  2814. X */
  2815. X
  2816. Xpop_send(p)
  2817. XPOP     *   p;
  2818. X{
  2819. X    MsgInfoList         *   mp;         /*  Pointer to message info list */
  2820. X    register int            msg_num;
  2821. X    register int            msg_lines;
  2822. X    char                    buffer[MAXMSGLINELEN];
  2823. X
  2824. X    /*  Convert the first parameter into an integer */
  2825. X    msg_num = atoi(p->pop_parm[1]);
  2826. X
  2827. X    /*  Is requested message out of range? */
  2828. X    if ((msg_num < 1) || (msg_num > p->msg_count))
  2829. X        return (pop_msg (p,POP_FAILURE,"Message %u does not exist.",msg_num));
  2830. X
  2831. X    /*  Get a pointer to the message in the message list */
  2832. X    mp = &p->mlp[msg_num-1];
  2833. X
  2834. X    /*  Is the message flagged for deletion? */
  2835. X    if (mp->del_flag)
  2836. X        return (pop_msg (p,POP_FAILURE,
  2837. X            "Message %u has been deleted.",msg_num));
  2838. X
  2839. X    /*  If this is a TOP command, get the number of lines to send */
  2840. X    if (strcmp(p->pop_command,"top") == 0) {
  2841. X        /*  Convert the second parameter into an integer */
  2842. X        msg_lines = atoi(p->pop_parm[2]);
  2843. X    }
  2844. X    else {
  2845. X        /*  Assume that a RETR (retrieve) command was issued */
  2846. X        msg_lines = -1;
  2847. X        /*  Flag the message as retreived */
  2848. X        mp->retr_flag = TRUE;
  2849. X    }
  2850. X    
  2851. X    /*  Display the number of bytes in the message */
  2852. X    pop_msg(p,POP_SUCCESS,"%ld octets",mp->length);
  2853. X
  2854. X    /*  Position to the start of the message */
  2855. X    (void)fseek(p->drop,mp->offset,0);
  2856. X
  2857. X    /*  Skip the first line (the sendmail "From" line) */
  2858. X    (void)fgets (buffer,MAXMSGLINELEN,p->drop);
  2859. X
  2860. X    /*  Send the header of the message followed by a blank line */
  2861. X    while (fgets(buffer,MAXMSGLINELEN,p->drop)) {
  2862. X        pop_sendline (p,buffer);
  2863. X        /*  A single newline (blank line) signals the 
  2864. X            end of the header.  sendline() converts this to a NULL, 
  2865. X            so that's what we look for. */
  2866. X        if (*buffer == 0) break;
  2867. X    }
  2868. X    /*  Send the message body */
  2869. X    while (fgets(buffer,MAXMSGLINELEN,p->drop)) {
  2870. X        /*  Look for the start of the next message */
  2871. X        if (strncmp(buffer,"From ",5) == 0) break;
  2872. X        /*  Decrement the lines sent (for a TOP command) */
  2873. X        if (msg_lines >= 0 && msg_lines-- == 0) break;
  2874. X        pop_sendline(p,buffer);
  2875. X    }
  2876. X    /*  "." signals the end of a multi-line transmission */
  2877. X    (void)fputs(".\r\n",p->output);
  2878. X    (void)fflush(p->output);
  2879. X
  2880. X    return(POP_SUCCESS);
  2881. X}
  2882. X
  2883. X/*
  2884. X *  sendline:   Send a line of a multi-line response to a client.
  2885. X */
  2886. Xpop_sendline(p,buffer)
  2887. XPOP         *   p;
  2888. Xchar        *   buffer;
  2889. X{
  2890. X    char        *   bp;
  2891. X
  2892. X    /*  Byte stuff lines that begin with the temirnation octet */
  2893. X    if (*buffer == POP_TERMINATE) (void)fputc(POP_TERMINATE,p->output);
  2894. X
  2895. X    /*  Look for a <NL> in the buffer */
  2896. X    if (bp = index(buffer,NEWLINE)) *bp = 0;
  2897. X
  2898. X    /*  Send the line to the client */
  2899. X    (void)fputs(buffer,p->output);
  2900. X
  2901. X#ifdef DEBUG
  2902. X    if(p->debug)pop_log(p,POP_DEBUG,"Sending line \"%s\"",buffer);
  2903. X#endif DEBUG
  2904. X
  2905. X    /*  Put a <CR><NL> if a newline was removed from the buffer */
  2906. X    if (bp) (void)fputs ("\r\n",p->output);
  2907. X}
  2908. SHAR_EOF
  2909. fi
  2910. if test -f 'pop_stat.c'
  2911. then
  2912.     echo shar: "will not over-write existing file 'pop_stat.c'"
  2913. else
  2914. sed 's/^X//' << \SHAR_EOF > 'pop_stat.c'
  2915. X/*
  2916. X * Copyright (c) 1989 Regents of the University of California.
  2917. X * All rights reserved.  The Berkeley software License Agreement
  2918. X * specifies the terms and conditions for redistribution.
  2919. X */
  2920. X
  2921. X#ifndef lint
  2922. Xstatic char copyright[] = "Copyright (c) 1990 Regents of the University of California.\nAll rights reserved.\n";
  2923. Xstatic char SccsId[] = "@(#)@(#)pop_stat.c    2.2  2.2 3/18/91";
  2924. X#endif not lint
  2925. X
  2926. X#include <stdio.h>
  2927. X#include <sys/types.h>
  2928. X#include "popper.h"
  2929. X
  2930. X/* 
  2931. X *  stat:   Display the status of a POP maildrop to its client
  2932. X */
  2933. X
  2934. Xint pop_stat (p)
  2935. XPOP     *   p;
  2936. X{
  2937. X#ifdef DEBUG
  2938. X    if (p->debug) pop_log(p,POP_DEBUG,"%u message(s) (%ld octets).",p->msg_count-p->msgs_deleted,p->drop_size-p->bytes_deleted);
  2939. X#endif DEBUG
  2940. X    return (pop_msg (p,POP_SUCCESS,
  2941. X        "%u %ld",p->msg_count-p->msgs_deleted,p->drop_size-p->bytes_deleted));
  2942. X}
  2943. SHAR_EOF
  2944. fi
  2945. if test -f 'pop_updt.c'
  2946. then
  2947.     echo shar: "will not over-write existing file 'pop_updt.c'"
  2948. else
  2949. sed 's/^X//' << \SHAR_EOF > 'pop_updt.c'
  2950. X/*
  2951. X * Copyright (c) 1989 Regents of the University of California.
  2952. X * All rights reserved.  The Berkeley software License Agreement
  2953. X * specifies the terms and conditions for redistribution.
  2954. X */
  2955. X
  2956. X#ifndef lint
  2957. Xstatic char copyright[] = "Copyright (c) 1990 Regents of the University of California.\nAll rights reserved.\n";
  2958. Xstatic char SccsId[] = "@(#)@(#)pop_updt.c    2.3  2.3 3/20/91";
  2959. X#endif not lint
  2960. X
  2961. X#include <errno.h>
  2962. X#include <stdio.h>
  2963. X#include <sys/types.h>
  2964. X#include <strings.h>
  2965. X#include <sys/stat.h>
  2966. X#include <sys/file.h>
  2967. X#include "popper.h"
  2968. X
  2969. Xextern int      errno;
  2970. X
  2971. Xstatic char standard_error[] =
  2972. X    "Error error updating primary drop. Mailbox unchanged";
  2973. X
  2974. X/* 
  2975. X *  updt:   Apply changes to a user's POP maildrop
  2976. X */
  2977. X
  2978. Xint pop_updt (p)
  2979. XPOP     *   p;
  2980. X{
  2981. X    FILE                *   md;                     /*  Stream pointer for 
  2982. X                                                        the user's maildrop */
  2983. X    int                     mfd;                    /*  File descriptor for
  2984. X                                                        above */
  2985. X    char                    buffer[BUFSIZ];         /*  Read buffer */
  2986. X
  2987. X    MsgInfoList         *   mp;                     /*  Pointer to message 
  2988. X                                                        info list */
  2989. X    register int            msg_num;                /*  Current message 
  2990. X                                                        counter */
  2991. X    register int            status_written;         /*  Status header field 
  2992. X                                                        written */
  2993. X    int                     nchar;                  /* Bytes read/written */
  2994. X
  2995. X    long                    offset;                 /* New mail offset */
  2996. X
  2997. X#ifdef DEBUG
  2998. X    if (p->debug) {
  2999. X        pop_log(p,POP_DEBUG,"Performing maildrop update...");
  3000. X        pop_log(p,POP_DEBUG,"Checking to see if all messages were deleted");
  3001. X    }
  3002. X#endif DEBUG
  3003. X
  3004. X    if (p->msgs_deleted == p->msg_count) {
  3005. X        /* Truncate before close, to avoid race condition,  DO NOT UNLINK!
  3006. X           Another process may have opened,  and not yet tried to lock */
  3007. X        (void)ftruncate ((int)fileno(p->drop),0L);
  3008. X        (void)fclose(p->drop) ;
  3009. X        return (POP_SUCCESS);
  3010. X    }
  3011. X
  3012. X#ifdef DEBUG
  3013. X    if (p->debug) 
  3014. X        pop_log(p,POP_DEBUG,"Opening mail drop \"%s\"",p->drop_name);
  3015. X#endif DEBUG
  3016. X
  3017. X    /*  Open the user's real maildrop */
  3018. X    if ((mfd = open(p->drop_name,O_RDWR|O_CREAT,0600)) == -1 ||
  3019. X        (md = fdopen(mfd,"r+")) == NULL) {
  3020. X        return pop_msg(p,POP_FAILURE,standard_error);
  3021. X    }
  3022. X
  3023. X    /*  Lock the user's real mail drop */
  3024. X    if ( flock(mfd,LOCK_EX) == -1 ) {
  3025. X        (void)fclose(md) ;
  3026. X        return pop_msg(p,POP_FAILURE, "flock: '%s': %s", p->temp_drop,
  3027. X            (errno < sys_nerr) ? sys_errlist[errno] : "");
  3028. X    }
  3029. X
  3030. X    /* Go to the right places */
  3031. X    offset = lseek((int)fileno(p->drop),0L,L_XTND) ; 
  3032. X
  3033. X    /*  Append any messages that may have arrived during the session 
  3034. X        to the temporary maildrop */
  3035. X    while ((nchar=read(mfd,buffer,BUFSIZ)) > 0)
  3036. X        if ( nchar != write((int)fileno(p->drop),buffer,nchar) ) {
  3037. X            nchar = -1;
  3038. X            break ;
  3039. X        }
  3040. X    if ( nchar != 0 ) {
  3041. X        (void)fclose(md) ;
  3042. X        (void)ftruncate((int)fileno(p->drop),offset) ;
  3043. X        (void)fclose(p->drop) ;
  3044. X        return pop_msg(p,POP_FAILURE,standard_error);
  3045. X    }
  3046. X
  3047. X    rewind(md);
  3048. X    (void)ftruncate(mfd,0L) ;
  3049. X
  3050. X    /* Synch stdio and the kernel for the POP drop */
  3051. X    rewind(p->drop);
  3052. X    (void)lseek((int)fileno(p->drop),0L,L_SET);
  3053. X
  3054. X    /*  Transfer messages not flagged for deletion from the temporary 
  3055. X        maildrop to the new maildrop */
  3056. X#ifdef DEBUG
  3057. X    if (p->debug) 
  3058. X        pop_log(p,POP_DEBUG,"Creating new maildrop \"%s\" from \"%s\"",
  3059. X                p->drop_name,p->temp_drop);
  3060. X#endif DEBUG
  3061. X
  3062. X    for (msg_num = 0; msg_num < p->msg_count; ++msg_num) {
  3063. X
  3064. X        int doing_body;
  3065. X
  3066. X        /*  Get a pointer to the message information list */
  3067. X        mp = &p->mlp[msg_num];
  3068. X
  3069. X        if (mp->del_flag) {
  3070. X#ifdef DEBUG
  3071. X            if(p->debug)
  3072. X                pop_log(p,POP_DEBUG,
  3073. X                    "Message %u flagged for deletion.",mp->number);
  3074. X#endif DEBUG
  3075. X            continue;
  3076. X        }
  3077. X
  3078. X        (void)fseek(p->drop,mp->offset,0);
  3079. X
  3080. X#ifdef DEBUG
  3081. X        if(p->debug)
  3082. X            pop_log(p,POP_DEBUG,"Copying message %u.",mp->number);
  3083. X#endif DEBUG
  3084. X        for(status_written = doing_body = 0 ;
  3085. X            fgets(buffer,MAXMSGLINELEN,p->drop);) {
  3086. X
  3087. X            if (doing_body == 0) { /* Header */
  3088. X
  3089. X                /*  Update the message status */
  3090. X                if (strncasecmp(buffer,"Status:",7) == 0) {
  3091. X                    if (mp->retr_flag)
  3092. X                        (void)fputs("Status: RO\n",md);
  3093. X                    else
  3094. X                        (void)fputs(buffer, md);
  3095. X                    status_written++;
  3096. X                    continue;
  3097. X                }
  3098. X                /*  A blank line signals the end of the header. */
  3099. X                if (*buffer == '\n') {
  3100. X                    doing_body = 1;
  3101. X                    if (status_written == 0) {
  3102. X                        if (mp->retr_flag)
  3103. X                            (void)fputs("Status: RO\n\n",md);
  3104. X                        else
  3105. X                            (void)fputs("Status: U\n\n",md);
  3106. X                    }
  3107. X                    else (void)fputs ("\n", md);
  3108. X                    continue;
  3109. X                }
  3110. X                /*  Save another header line */
  3111. X                (void)fputs (buffer, md);
  3112. X            } 
  3113. X            else { /* Body */ 
  3114. X                if (strncmp(buffer,"From ",5) == 0) break;
  3115. X                (void)fputs (buffer, md);
  3116. X            }
  3117. X        }
  3118. X    }
  3119. X
  3120. X    /* flush and check for errors now!  The new mail will writen
  3121. X       without stdio,  since we need not separate messages */
  3122. X
  3123. X    (void)fflush(md) ;
  3124. X    if (ferror(md)) {
  3125. X        (void)ftruncate(mfd,0L) ;
  3126. X        (void)fclose(md) ;
  3127. X        (void)fclose(p->drop) ;
  3128. X        return pop_msg(p,POP_FAILURE,standard_error);
  3129. X    }
  3130. X
  3131. X    /* Go to start of new mail if any */
  3132. X    (void)lseek((int)fileno(p->drop),offset,L_SET);
  3133. X
  3134. X    while((nchar=read((int)fileno(p->drop),buffer,BUFSIZ)) > 0)
  3135. X        if ( nchar != write(mfd,buffer,nchar) ) {
  3136. X            nchar = -1;
  3137. X            break ;
  3138. X        }
  3139. X    if ( nchar != 0 ) {
  3140. X        (void)ftruncate(mfd,0L) ;
  3141. X        (void)fclose(md) ;
  3142. X        (void)fclose(p->drop) ;
  3143. X        return pop_msg(p,POP_FAILURE,standard_error);
  3144. X    }
  3145. X
  3146. X    /*  Close the maildrop and empty temporary maildrop */
  3147. X    (void)fclose(md);
  3148. X    (void)ftruncate((int)fileno(p->drop),0L);
  3149. X    (void)fclose(p->drop);
  3150. X
  3151. X    return(pop_quit(p));
  3152. X}
  3153. SHAR_EOF
  3154. fi
  3155. if test -f 'pop_user.c'
  3156. then
  3157.     echo shar: "will not over-write existing file 'pop_user.c'"
  3158. else
  3159. sed 's/^X//' << \SHAR_EOF > 'pop_user.c'
  3160. X/*
  3161. X * Copyright (c) 1989 Regents of the University of California.
  3162. X * All rights reserved.  The Berkeley software License Agreement
  3163. X * specifies the terms and conditions for redistribution.
  3164. X */
  3165. X
  3166. X#ifndef lint
  3167. Xstatic char copyright[] = "Copyright (c) 1990 Regents of the University of California.\nAll rights reserved.\n";
  3168. Xstatic char SccsId[] = "@(#)@(#)pop_user.c    2.1  2.1 3/18/91";
  3169. X#endif not lint
  3170. X
  3171. X#include <stdio.h>
  3172. X#include <sys/types.h>
  3173. X#include <strings.h>
  3174. X#include "popper.h"
  3175. X
  3176. X/* 
  3177. X *  user:   Prompt for the user name at the start of a POP session
  3178. X */
  3179. X
  3180. Xint pop_user (p)
  3181. XPOP     *   p;
  3182. X{
  3183. X    /*  Save the user name */
  3184. X    (void)strcpy(p->user, p->pop_parm[1]);
  3185. X
  3186. X    /*  Tell the user that the password is required */
  3187. X    return (pop_msg(p,POP_SUCCESS,"Password required for %s.",p->user));
  3188. X}
  3189. SHAR_EOF
  3190. fi
  3191. if test -f 'pop_xmit.c'
  3192. then
  3193.     echo shar: "will not over-write existing file 'pop_xmit.c'"
  3194. else
  3195. sed 's/^X//' << \SHAR_EOF > 'pop_xmit.c'
  3196. X/*
  3197. X * Copyright (c) 1989 Regents of the University of California.
  3198. X * All rights reserved.  The Berkeley software License Agreement
  3199. X * specifies the terms and conditions for redistribution.
  3200. X */
  3201. X
  3202. X#ifndef lint
  3203. Xstatic char copyright[] = "Copyright (c) 1990 Regents of the University of California.\nAll rights reserved.\n";
  3204. Xstatic char SccsId[] = "@(#)@(#)pop_xmit.c    2.1  2.1 3/18/91";
  3205. X#endif not lint
  3206. X
  3207. X#include <stdio.h>
  3208. X#include <sys/types.h>
  3209. X#include <sys/file.h>
  3210. X#include <sys/wait.h>
  3211. X#include "popper.h"
  3212. X
  3213. X/*
  3214. X *  xmit:   POP XTND function to receive a message from 
  3215. X *          a client and send it in the mail
  3216. X */
  3217. X
  3218. Xpop_xmit (p)
  3219. XPOP     *   p;
  3220. X{
  3221. X    FILE                *   tmp;                    /*  File descriptor for 
  3222. X                                                        temporary file */
  3223. X    char                    buffer[MAXLINELEN];     /*  Read buffer */
  3224. X    char                    temp_xmit[MAXDROPLEN];  /*  Name of the temporary 
  3225. X                                                        filedrop */
  3226. X    union   wait            stat;
  3227. X    int                     id, pid;
  3228. X
  3229. X    /*  Create a temporary file into which to copy the user's message */
  3230. X    (void)mktemp((char *)strcpy(temp_xmit,POP_TMPXMIT));
  3231. X#ifdef DEBUG
  3232. X    if(p->debug)
  3233. X        pop_log(p,POP_DEBUG,
  3234. X            "Creating temporary file for sending a mail message \"%s\"\n",
  3235. X                temp_xmit);
  3236. X#endif DEBUG
  3237. X    if ((tmp = fopen(temp_xmit,"w+")) == NULL)
  3238. X        return (pop_msg(p,POP_FAILURE,
  3239. X            "Unable to create temporary message file \"%s\", errno = %d",
  3240. X                temp_xmit,errno));
  3241. X
  3242. X    /*  Tell the client to start sending the message */
  3243. X    pop_msg(p,POP_SUCCESS,"Start sending the message.");
  3244. X
  3245. X    /*  Receive the message */
  3246. X#ifdef DEBUG
  3247. X    if(p->debug)pop_log(p,POP_DEBUG,"Receiving mail message");
  3248. X#endif DEBUG
  3249. X    while (fgets(buffer,MAXLINELEN,p->input)){
  3250. X        /*  Look for initial period */
  3251. X#ifdef DEBUG
  3252. X        if(p->debug)pop_log(p,POP_DEBUG,"Receiving: \"%s\"",buffer);
  3253. X#endif DEBUG
  3254. X        if (*buffer == '.') {
  3255. X            /*  Exit on end of message */
  3256. X            if (strcmp(buffer,".\r\n") == 0) break;
  3257. X        }
  3258. X        (void)fputs (buffer,tmp);
  3259. X    }
  3260. X    (void)fclose (tmp);
  3261. X
  3262. X#ifdef DEBUG
  3263. X    if(p->debug)pop_log(p,POP_DEBUG,"Forking for \"%s\"",MAIL_COMMAND);
  3264. X#endif DEBUG
  3265. X    /*  Send the message */
  3266. X    switch (pid = fork()) {
  3267. X        case 0:
  3268. X            (void)fclose (p->input);
  3269. X            (void)fclose (p->output);       
  3270. X            (void)close(0);
  3271. X            if (open(temp_xmit,O_RDONLY,0) < 0) (void)_exit(1);
  3272. X            (void)execl (MAIL_COMMAND,"send-mail","-t","-oem",NULLCP);
  3273. X            (void)_exit(1);
  3274. X        case -1:
  3275. X#ifdef DEBUG
  3276. X            if (!p->debug) (void)unlink (temp_xmit);
  3277. X#endif DEBUG
  3278. X            return (pop_msg(p,POP_FAILURE,
  3279. X                "Unable to execute \"%s\"",MAIL_COMMAND));
  3280. X        default:
  3281. X            while((id = wait(&stat)) >=0 && id != pid);
  3282. X            if (!p->debug) (void)unlink (temp_xmit);
  3283. X            if (stat.w_retcode)
  3284. X                return (pop_msg(p,POP_FAILURE,"Unable to send message"));
  3285. X            return (pop_msg (p,POP_SUCCESS,"Message sent successfully"));
  3286. X    }
  3287. X
  3288. X}
  3289. SHAR_EOF
  3290. fi
  3291. if test -f 'pop_xtnd.c'
  3292. then
  3293.     echo shar: "will not over-write existing file 'pop_xtnd.c'"
  3294. else
  3295. sed 's/^X//' << \SHAR_EOF > 'pop_xtnd.c'
  3296. X/*
  3297. X * Copyright (c) 1989 Regents of the University of California.
  3298. X * All rights reserved.  The Berkeley software License Agreement
  3299. X * specifies the terms and conditions for redistribution.
  3300. X */
  3301. X
  3302. X#ifndef lint
  3303. Xstatic char copyright[] = "Copyright (c) 1990 Regents of the University of California.\nAll rights reserved.\n";
  3304. Xstatic char SccsId[] = "@(#)@(#)pop_xtnd.c    2.1  2.1 3/18/91";
  3305. X#endif not lint
  3306. X
  3307. X#include <stdio.h>
  3308. X#include <sys/types.h>
  3309. X#include "popper.h"
  3310. X
  3311. X/* 
  3312. X *  xtnd:   Handle extensions to the POP protocol suite
  3313. X */
  3314. X
  3315. Xextern  xtnd_table  *   pop_get_subcommand();
  3316. X
  3317. Xint pop_xtnd (p)
  3318. XPOP     *   p;
  3319. X{
  3320. X    xtnd_table  *   x;
  3321. X
  3322. X    /*  Convert the XTND subcommand to lower case */
  3323. X    pop_lower(p->pop_subcommand);
  3324. X
  3325. X    /*  Search for the subcommand in the XTND command table */
  3326. X    if ((x = pop_get_subcommand(p)) == NULL) return(POP_FAILURE);
  3327. X
  3328. X    /*  Call the function associated with this subcommand */
  3329. X    if (x->function) return((*x->function)(p));
  3330. X
  3331. X    /*  Otherwise assume NOOP */
  3332. X    return (pop_msg(p,POP_SUCCESS,NULL));
  3333. X}
  3334. SHAR_EOF
  3335. fi
  3336. if test -f 'popper.c'
  3337. then
  3338.     echo shar: "will not over-write existing file 'popper.c'"
  3339. else
  3340. sed 's/^X//' << \SHAR_EOF > 'popper.c'
  3341. X/*
  3342. X * Copyright (c) 1989 Regents of the University of California.
  3343. X * All rights reserved.  The Berkeley software License Agreement
  3344. X * specifies the terms and conditions for redistribution.
  3345. X */
  3346. X
  3347. X#ifndef lint
  3348. Xstatic char copyright[] = "Copyright (c) 1990 Regents of the University of California.\nAll rights reserved.\n";
  3349. Xstatic char SccsId[] = "@(#)@(#)popper.c    2.1  2.1 3/18/91";
  3350. X#endif not lint
  3351. X
  3352. X#include <stdio.h>
  3353. X#include <sys/types.h>
  3354. X#include "popper.h"
  3355. X
  3356. Xextern  state_table *   pop_get_command();
  3357. X
  3358. X/* 
  3359. X *  popper: Handle a Post Office Protocol version 3 session
  3360. X */
  3361. Xmain (argc, argv)
  3362. Xint         argc;
  3363. Xchar    **  argv;
  3364. X{
  3365. X    POP                 p;
  3366. X    state_table     *   s;
  3367. X    char                message[MAXLINELEN];
  3368. X
  3369. X    /*  Start things rolling */
  3370. X    pop_init(&p,argc,argv);
  3371. X
  3372. X    /*  Tell the user that we are listenting */
  3373. X    pop_msg(&p,POP_SUCCESS,
  3374. X        "UCB Pop server (version %s) at %s starting.",VERSION,p.myhost);
  3375. X
  3376. X    /*  State loop.  The POP server is always in a particular state in 
  3377. X        which a specific suite of commands can be executed.  The following 
  3378. X        loop reads a line from the client, gets the command, and processes 
  3379. X        it in the current context (if allowed) or rejects it.  This continues 
  3380. X        until the client quits or an error occurs. */
  3381. X
  3382. X    for (p.CurrentState=auth1;p.CurrentState!=halt&&p.CurrentState!=error;) {
  3383. X
  3384. X        /*  Obtain a line from the client */
  3385. X        if (fgets(message,MAXLINELEN,p.input) == NULL) {
  3386. X            p.CurrentState = error;
  3387. X            pop_msg(&p,POP_FAILURE,"POP server at %s signing off.",p.myhost);
  3388. X        }
  3389. X        else {
  3390. X            /*  Search for the command in the command/state table */
  3391. X            if ((s = pop_get_command(&p,message)) == NULL) continue;
  3392. X
  3393. X            /*  Call the function associated with this command in 
  3394. X                the current state */
  3395. X            if (s->function) p.CurrentState = s->result[(*s->function)(&p)];
  3396. X
  3397. X            /*  Otherwise assume NOOP and send an OK message to the client */
  3398. X            else {
  3399. X                p.CurrentState = s->success_state;
  3400. X                pop_msg(&p,POP_SUCCESS,NULL);
  3401. X            }
  3402. X        }       
  3403. X    }
  3404. X
  3405. X    /*  Say goodbye to the client */
  3406. X    pop_msg(&p,POP_SUCCESS,"Pop server at %s signing off.",p.myhost);
  3407. X
  3408. X    /*  Log the end of activity */
  3409. X    pop_log(&p,POP_PRIORITY,
  3410. X        "(v%s) Ending request from \"%s\" at %s\n",VERSION,p.client,p.ipaddr);
  3411. X
  3412. X    /*  Stop logging */
  3413. X    closelog();
  3414. X
  3415. X    return(0);
  3416. X}
  3417. X
  3418. X#ifdef STRNCASECMP
  3419. X/*
  3420. X *  Perform a case-insensitive string comparision
  3421. X */
  3422. X#include <ctype.h>
  3423. Xstrncasecmp(str1,str2,len)
  3424. Xregister char   *   str1;
  3425. Xregister char   *   str2;
  3426. Xregister int        len;
  3427. X{
  3428. X    register int    i;
  3429. X    char            a,
  3430. X                    b;
  3431. X
  3432. X    for (i=len-1;i>=0;i--){
  3433. X        a = str1[i];
  3434. X        b = str2[i];
  3435. X        if (isupper(a)) a = tolower(str1[i]);
  3436. X        if (isupper(b)) b = tolower(str2[i]);
  3437. X        if (a > b) return (1);
  3438. X        if (a < b) return(-1);
  3439. X    }
  3440. X    return(0);
  3441. X}
  3442. X#endif STRNCASECMP
  3443. SHAR_EOF
  3444. fi
  3445. if test -f 'popper.h'
  3446. then
  3447.     echo shar: "will not over-write existing file 'popper.h'"
  3448. else
  3449. sed 's/^X//' << \SHAR_EOF > 'popper.h'
  3450. X/*
  3451. X * Copyright (c) 1989 Regents of the University of California.
  3452. X * All rights reserved.  The Berkeley software License Agreement
  3453. X * specifies the terms and conditions for redistribution.
  3454. X *
  3455. X * static char copyright[] = "Copyright (c) 1990 Regents of the University of California.\nAll rights reserved.\n";
  3456. X * static char SccsId[] = "@(#)@(#)popper.h    2.2  2.2 4/2/91";
  3457. X *
  3458. X */
  3459. X
  3460. X/*  LINTLIBRARY */
  3461. X
  3462. X/* 
  3463. X *  Header file for the POP programs
  3464. X */
  3465. X
  3466. X#include <syslog.h>
  3467. X#include "version.h"
  3468. X
  3469. X#define NULLCP          ((char *) 0)
  3470. X#define SPACE           32
  3471. X#define TAB             9
  3472. X#define TRUE            1
  3473. X#define FALSE           0
  3474. X#define NEWLINE         '\n'
  3475. X
  3476. X#define MAXHOSTNAMELEN  256
  3477. X#define MAXUSERNAMELEN  65
  3478. X#define MAXDROPLEN      64
  3479. X#define MAXLINELEN      1024
  3480. X#define MAXMSGLINELEN   1024
  3481. X#define MAXCMDLEN       4
  3482. X#define MAXPARMCOUNT    5
  3483. X#define MAXPARMLEN      10
  3484. X#define ALLOC_MSGS  20
  3485. X#define MAIL_COMMAND    "/usr/lib/sendmail"
  3486. X
  3487. X#define POP_FACILITY    LOG_LOCAL0
  3488. X#define POP_PRIORITY    LOG_NOTICE
  3489. X#define POP_DEBUG       LOG_DEBUG
  3490. X#define POP_LOGOPTS     0
  3491. X#define POP_MAILDIR     "/usr/spool/mail"
  3492. X#define POP_DROP        "/usr/spool/mail/.%s.pop"
  3493. X    /* POP_TMPSIZE needs to be big enough to hold the string
  3494. X     * defined by POP_TMPDROP.  POP_DROP and POP_TMPDROP
  3495. X     * must be in the same filesystem.
  3496. X     */
  3497. X#define POP_TMPDROP     "/usr/spool/mail/tmpXXXXXX"
  3498. X#define POP_TMPSIZE    256
  3499. X#define POP_TMPXMIT     "/tmp/xmitXXXXXX"
  3500. X#define POP_OK          "+OK"
  3501. X#define POP_ERR         "-ERR"
  3502. X#define POP_SUCCESS     1
  3503. X#define POP_FAILURE     0
  3504. X#define POP_TERMINATE   '.'
  3505. X
  3506. Xextern int              errno;
  3507. Xextern int              sys_nerr;
  3508. Xextern char         *   sys_errlist[];
  3509. Xextern char         *   sys_siglist[];
  3510. X
  3511. X#define pop_command         pop_parm[0]     /*  POP command is first token */
  3512. X#define pop_subcommand      pop_parm[1]     /*  POP XTND subcommand is the 
  3513. X                                                second token */
  3514. X
  3515. Xtypedef enum {                              /*  POP processing states */
  3516. X    auth1,                                  /*  Authorization: waiting for 
  3517. X                                                USER command */
  3518. X    auth2,                                  /*  Authorization: waiting for 
  3519. X                                                PASS command */
  3520. X    trans,                                  /*  Transaction */
  3521. X    update,                                 /*  Update:  session ended, 
  3522. X                                                process maildrop changes */
  3523. X    halt,                                   /*  (Halt):  stop processing 
  3524. X                                                and exit */
  3525. X    error                                   /*  (Error): something really 
  3526. X                                                bad happened */
  3527. X} state;
  3528. X
  3529. Xtypedef struct {                                /*  State information for 
  3530. X                                                    each POP command */
  3531. X    state       ValidCurrentState;              /*  The operating state of 
  3532. X                                                    the command */
  3533. X    char   *    command;                        /*  The POP command */
  3534. X    int         min_parms;                      /*  Minimum number of parms 
  3535. X                                                    for the command */
  3536. X    int         max_parms;                      /*  Maximum number of parms 
  3537. X                                                    for the command */
  3538. X    int         (*function) ();                 /*  The function that process 
  3539. X                                                    the command */
  3540. X    state       result[2];                      /*  The resulting state after 
  3541. X                                                    command processing */
  3542. X#define success_state   result[0]               /*  State when a command 
  3543. X                                                    succeeds */
  3544. X} state_table;
  3545. X
  3546. Xtypedef struct {                                /*  Table of extensions */
  3547. X    char   *    subcommand;                     /*  The POP XTND subcommand */
  3548. X    int         min_parms;                      /*  Minimum number of parms for
  3549. X                                                    the subcommand */
  3550. X    int         max_parms;                      /*  Maximum number of parms for
  3551. X                                                    the subcommand */
  3552. X    int         (*function) ();                 /*  The function that processes 
  3553. X                                                    the subcommand */
  3554. X} xtnd_table;
  3555. X
  3556. Xtypedef struct {                                /*  Message information */
  3557. X    int         number;                         /*  Message number relative to 
  3558. X                                                    the beginning of list */
  3559. X    long        length;                         /*  Length of message in 
  3560. X                                                    bytes */
  3561. X    int         lines;                          /*  Number of (null-terminated)                                                     lines in the message */
  3562. X    long        offset;                         /*  Offset from beginning of 
  3563. X                                                    file */
  3564. X    int         del_flag;                       /*  Flag indicating if message 
  3565. X                                                    is marked for deletion */
  3566. X    int         retr_flag;                      /*  Flag indicating if message 
  3567. X                                                    was retrieved */
  3568. X} MsgInfoList;
  3569. X
  3570. Xtypedef struct  {                               /*  POP parameter block */
  3571. X    int                 debug;                  /*  Debugging requested */
  3572. X    char            *   myname;                 /*  The name of this POP 
  3573. X                                                    daemon program */
  3574. X    char                myhost[MAXHOSTNAMELEN]; /*  The name of our host 
  3575. X                                                    computer */
  3576. X    char            *   client;                 /*  Canonical name of client 
  3577. X                                                    computer */
  3578. X    char            *   ipaddr;                 /*  Dotted-notation format of 
  3579. X                                                    client IP address */
  3580. X    unsigned short      ipport;                 /*  Client port for privileged 
  3581. X                                                    operations */
  3582. X    char                user[MAXUSERNAMELEN];   /*  Name of the POP user */
  3583. X    state               CurrentState;           /*  The current POP operational                                                     state */
  3584. X    MsgInfoList     *   mlp;                    /*  Message information list */
  3585. X    int                 msg_count;              /*  Number of messages in 
  3586. X                                                    the maildrop */
  3587. X    int                 msgs_deleted;           /*  Number of messages flagged 
  3588. X                                                    for deletion */
  3589. X    int                 last_msg;               /*  Last message touched by 
  3590. X                                                    the user */
  3591. X    long                bytes_deleted;          /*  Number of maildrop bytes 
  3592. X                                                    flagged for deletion */
  3593. X    char                drop_name[MAXDROPLEN];  /*  The name of the user's 
  3594. X                                                    maildrop */
  3595. X    char                temp_drop[MAXDROPLEN];  /*  The name of the user's 
  3596. X                                                    temporary maildrop */
  3597. X    long                drop_size;              /*  Size of the maildrop in
  3598. X                                                    bytes */
  3599. X    FILE            *   drop;                   /*  (Temporary) mail drop */
  3600. X    FILE            *   input;                  /*  Input TCP/IP communication 
  3601. X                                                    stream */
  3602. X    FILE            *   output;                 /*  Output TCP/IP communication                                                     stream */
  3603. X    FILE            *   trace;                  /*  Debugging trace file */
  3604. X    char            *   pop_parm[MAXPARMCOUNT]; /*  Parse POP parameter list */
  3605. X    int                 parm_count;             /*  Number of parameters in 
  3606. X                                                    parsed list */
  3607. X} POP;
  3608. X
  3609. Xextern int  pop_dele();
  3610. Xextern int  pop_last();
  3611. Xextern int  pop_list();
  3612. Xextern int  pop_pass();
  3613. Xextern int  pop_quit();
  3614. Xextern int  pop_rset();
  3615. Xextern int  pop_send();
  3616. Xextern int  pop_stat();
  3617. Xextern int  pop_updt();
  3618. Xextern int  pop_user();
  3619. Xextern int  pop_xtnd();
  3620. Xextern int  pop_xmit();
  3621. Xextern long lseek();
  3622. X
  3623. X#ifdef    pdp11
  3624. X#define pop_get_subcommand Apop_get_command
  3625. X#define pop_dropcopy Apop_dropcopy
  3626. X#define pop_sendline p_sndline
  3627. X#endif
  3628. SHAR_EOF
  3629. fi
  3630. if test -f 'version.h'
  3631. then
  3632.     echo shar: "will not over-write existing file 'version.h'"
  3633. else
  3634. sed 's/^X//' << \SHAR_EOF > 'version.h'
  3635. X/*
  3636. X * Copyright (c) 1989 Regents of the University of California.
  3637. X * All rights reserved.  The Berkeley software License Agreement
  3638. X * specifies the terms and conditions for redistribution.
  3639. X *
  3640. X * static char copyright[] = "Copyright (c) 1990 Regents of the University of California.\nAll rights reserved.\n";
  3641. X * static char SccsId[] = "@(#)@(#)version.h    2.6  2.6 4/3/91";
  3642. X *
  3643. X */
  3644. X
  3645. X/*
  3646. X *  Current version of this POP implementation
  3647. X */
  3648. X
  3649. X#define VERSION         "1.831beta"
  3650. SHAR_EOF
  3651. fi
  3652. if test -f 'popper.8'
  3653. then
  3654.     echo shar: "will not over-write existing file 'popper.8'"
  3655. else
  3656. sed 's/^X//' << \SHAR_EOF > 'popper.8'
  3657. X.\" Copyright (c) 1980 Regents of the University of California.
  3658. X.\" All rights reserved.
  3659. X.\"
  3660. X.\" Redistribution and use in source and binary forms are permitted
  3661. X.\" provided that this notice is preserved and that due credit is given
  3662. X.\" to the University of California at Berkeley. The name of the University
  3663. X.\" may not be used to endorse or promote products derived from this
  3664. X.\" software without specific prior written permission. This software
  3665. X.\" is provided ``as is'' without express or implied warranty.
  3666. X.\"
  3667. X.\" @(#)@(#)popper.8    2.3    2.3    (CCS)   4/2/91     Copyright (c) 1990 Regents of the University of California.\nAll rights reserved.\n
  3668. X.\"
  3669. X.TH popper 8 "August 1990"
  3670. X.UC 6
  3671. X.ad
  3672. X.SH NAME
  3673. Xpopper \- pop 3 server
  3674. X.SH SYNOPSIS
  3675. X.B /usr/etc/popper
  3676. X[ -d ]
  3677. X[ -t trace-file]
  3678. X.SH DESCRIPTION
  3679. X.I Popper
  3680. Xis an implementation of the Post Office Protocol server that runs on a
  3681. Xvariety of Unix computers to manage electronic mail for Macintosh
  3682. Xand MS-DOS computers.  The server was developed at the University of
  3683. XCalifornia at Berkeley and conforms fully to the specifications in RFC
  3684. X1081 and RFC 1082.  The Berkeley server also has extensions to
  3685. Xsend electronic mail on behalf of a client.
  3686. X.PP
  3687. XThe 
  3688. X.B \-d
  3689. Xflag sets the socket to debugging and turns on debugging.  All debugging
  3690. Xinformation is saved using syslog(8).  The 
  3691. X.B \-t trace\-file
  3692. Xflag turns on debugging and saves the trace information in
  3693. X.I trace\-file
  3694. Xusing fprintf(s).
  3695. X.SH HOW TO OBTAIN THE SERVER
  3696. X.PP
  3697. XThe POP server is available via anonymous ftp from ftp.CC.Berkeley.EDU
  3698. X(128.32.136.9, 128.32.206.12).  It is in two files in the pub directory:
  3699. Xa compressed
  3700. Xtar file popper.tar.Z and a Macintosh StuffIt archive in BinHex format
  3701. Xcalled MacPOP.sit.hqx.
  3702. X.SH THE POP TRANSACTION CYCLE
  3703. X.PP
  3704. XThe Berkeley POP server is a single program (called popper) that is
  3705. Xlaunched by inetd when it gets a service request on the POP TCP port.
  3706. X(The official port number specified in RFC 1081 for POP version 3 is
  3707. Xport 110.  However, some POP3 clients attempt to contact the server at
  3708. Xport 109, the POP version 2 port.  Unless you are running both POP2 and
  3709. XPOP3 servers, you can simply define both ports for use by the POP3
  3710. Xserver.  This is explained in the installation instructions later on.)
  3711. XThe popper program initializes and verifies that the peer IP address is
  3712. Xregistered in the local domain, logging a warning message when a
  3713. Xconnection is made to a client whose IP address does not have a
  3714. Xcanonical name.  For systems using BSD 4.3 bind, it also checks to see
  3715. Xif a cannonical name lookup for the client returns the same peer IP
  3716. Xaddress, logging a warning message if it does not.  The the server
  3717. Xenters the authorization state, during which the client must correctly
  3718. Xidentify itself by providing a valid Unix userid and password on the
  3719. Xserver's host machine.  No other exchanges are allowed during this
  3720. Xstate (other than a request to quit.)  If authentication fails, a
  3721. Xwarning message is logged and the session ends.  Once the user is
  3722. Xidentified, popper changes its user and group ids to match that of the
  3723. Xuser and enters the transaction state.  The server makes a temporary
  3724. Xcopy of the user's maildrop (ordinarily in /usr/spool/mail) which is
  3725. Xused for all subsequent transactions.  These include the bulk of POP
  3726. Xcommands to retrieve mail, delete mail, undelete mail, and so forth.  A
  3727. XBerkeley extension also allows the user to submit a mail parcel to the
  3728. Xserver who mails it using the sendmail program (this extension is
  3729. Xsupported in the HyperMail client distributed with the server).  When
  3730. Xthe client quits, the server enters the final update state during which
  3731. Xthe network connection is terminated and the user's maildrop is updated
  3732. Xwith the (possibly) modified temporary maildrop.
  3733. X.SH LOGGING
  3734. X.PP
  3735. XThe POP server uses syslog to keep a record of its activities.  On
  3736. Xsystems with BSD 4.3 syslogging, the server logs (by default) to the
  3737. X"local0" facility at priority "notice" for all messages except
  3738. Xdebugging which is logged at priority "debug".  The default log file is
  3739. X/usr/spool/mqueue/POPlog.  These can be changed, if desired.  On
  3740. Xsystems with 4.2 syslogging all messages are logged to the local log
  3741. Xfile, usually /usr/spool/mqueue/syslog.
  3742. X.SH DEBUGGING
  3743. X.PP
  3744. XThe popper program will log debugging information when the -d parameter
  3745. Xis specified after its invocation in the inetd.conf file.  Care should
  3746. Xbe exercised in using this option since it generates considerable
  3747. Xoutput in the syslog file.  Alternatively, the "-t <file-name>" option
  3748. Xwill place debugging information into file "<file-name>" using fprintf
  3749. Xinstead of syslog.
  3750. X.PP
  3751. XFor SunOS version 3.5, the popper program is launched by inetd from
  3752. X/etc/servers.  This file does not allow you to specify command line
  3753. Xarguments.  Therefore, if you want to enable debugging, you can specify
  3754. Xa shell script in /etc/servers to be launched instead of popper and in
  3755. Xthis script call popper with the desired arguments.
  3756. X.PP
  3757. XYou can confirm that the POP server is running on Unix by telneting to
  3758. Xport 110 (or 109 if you set it up that way).  For example:
  3759. X.PP
  3760. X.nf
  3761. X%telnet myhost 110
  3762. XTrying...
  3763. XConnected to myhost.berkeley.edu.
  3764. XEscape character is '^]'.
  3765. X+OK UCB Pop server (version 1.6) at myhost starting.
  3766. Xquit
  3767. XConnection closed by foreign host.
  3768. X.fi
  3769. X.SH VERSION 1.7 RELEASE NOTES
  3770. XExtensive re-write of the maildrop processing code contributed by 
  3771. XViktor Dukhovni <viktor@math.princeton.edu> that greatly reduces the
  3772. Xpossibility that the maildrop can be corrupted as the result of
  3773. Xsimultaneous access by two or more processes.
  3774. X.PP
  3775. XAdded "pop_dropcopy" module to create a temporary maildrop from
  3776. Xthe existing, standard maildrop as root before the setuid and 
  3777. Xsetgid for the user is done.  This allows the temporary maildrop
  3778. Xto be created in a mail spool area that is not world read-writable.
  3779. X.PP
  3780. XThis version does *not* send the sendmail "From " delimiter line
  3781. Xin response to a TOP or RETR command.
  3782. X.PP
  3783. XEncased all debugging code in #ifdef DEBUG constructs.  This code can
  3784. Xbe included by specifying the DEGUG compiler flag.  Note:  You still
  3785. Xneed to use the -d or -t option to obtain debugging output.
  3786. X.SH LIMITATIONS
  3787. XThe POP server copies the user's entire maildrop to /tmp and
  3788. Xthen operates on that copy.  If the maildrop is particularly
  3789. Xlarge, or inadequate space is available in /tmp, then the
  3790. Xserver will refuse to continue and terminate the connection.
  3791. X.PP
  3792. XSimultaneous modification of a single maildrop can result in 
  3793. Xconfusing results.  For example, manipulating messages in a
  3794. Xmaildrop using the Unix /usr/ucb/mail command while a copy of
  3795. Xit is being processed by the POP server can cause the changes
  3796. Xmade by one program to be lost when the other terminates.  This
  3797. Xproblem is being worked on and will be fixed in a later
  3798. Xrelease.
  3799. X.SH FILES
  3800. X.nf
  3801. X/usr/spool/mail         mail files
  3802. X/etc/inetd.conf         pop program invocation
  3803. X/etc/syslog.conf        logging specifications
  3804. X.fi
  3805. X.SH "SEE ALSO"
  3806. Xinetd(8), 
  3807. XRFC1081, 
  3808. XRFC1082
  3809. X.SH AUTHORS
  3810. XBob Campbell, Edward Moy, Austin Shelton, Marshall T Rose, and cast of
  3811. Xthousands at Rand, UDel, UCI, and elsewhere
  3812. SHAR_EOF
  3813. fi
  3814. if test -f 'README'
  3815. then
  3816.     echo shar: "will not over-write existing file 'README'"
  3817. else
  3818. sed 's/^X//' << \SHAR_EOF > 'README'
  3819. X@(#)@(#)README    2.6   2.6 4/2/91
  3820. X
  3821. X
  3822. XThe Post Office Protocol Server:  Installation Guide
  3823. X
  3824. X
  3825. X
  3826. XIntroduction
  3827. X
  3828. XThe Post Office Protocol server runs on a variety of Unix[1] computers
  3829. Xto manage electronic mail for Macintosh and MS-DOS computers.  The
  3830. Xserver was developed at the University of California at Berkeley and
  3831. Xconforms fully to the specifications in RFC 1081[2] and RFC 1082[3].
  3832. XThe Berkeley server also has extensions to send electronic mail on
  3833. Xbehalf of a client.
  3834. X
  3835. XThis guide explains how to install the POP server on your Unix
  3836. Xcomputer.  It assumes that you are not only familiar with Unix but also
  3837. Xcapable of performing Unix system administration.
  3838. X
  3839. X
  3840. XHow to Obtain the Server
  3841. X
  3842. XThe POP server is available via anonymous ftp from ftp.CC.Berkeley.EDU
  3843. X(128.32.136.9, 128.32.206.12).  It is in two files in the pub directory:
  3844. Xa compressed tar file popper-version.tar.Z and a Macintosh StuffIt archive
  3845. Xin BinHex format called MacPOP.sit.hqx.
  3846. X
  3847. X
  3848. XContents of the Distribution
  3849. X
  3850. XThe distribution contains the following:
  3851. X
  3852. X+   All of the C source necessary to create the server program.
  3853. X
  3854. X+   A visual representation of how the POP system works.
  3855. X
  3856. X+   Reprints of RFC 1081 and RFC 1082.
  3857. X
  3858. X+   A HyperCard stack POP client implementation using MacTCP.
  3859. X
  3860. X+   A man page for the popper daemon.
  3861. X
  3862. X+   This guide.
  3863. X
  3864. X
  3865. XCompatibility
  3866. X
  3867. XThe Berkeley POP server has been successfully tested on the following
  3868. XUnix operating systems:
  3869. X
  3870. X+   Berkeley Systems Distribution 4.3
  3871. X
  3872. X+   Sun Microsystems Operating System versions 3.5 and 4.0
  3873. X
  3874. X+   Ultrix version 2.3
  3875. X
  3876. XThe following POP clients operate correctly with the Berkeley POP server:
  3877. X
  3878. X+   The Berkeley HyperMail HyperCard stack for the Apple Macintosh 
  3879. X    (distributed with the server).
  3880. X
  3881. X+   The Stanford University Macintosh Internet Protocol MacMH program.
  3882. X
  3883. X+   The Stanford University Personal Computer Internet Protocol MH 
  3884. X    program.
  3885. X
  3886. X+   The mh version 6.0 programs for Unix.
  3887. X
  3888. X
  3889. XSupport
  3890. X
  3891. XThe Berkeley POP server is not officially supported and is without any
  3892. Xwarranty, explicit or implied.  However, we are interested in your
  3893. Xexperiences using the server.  Bugs, comments and suggestions should be
  3894. Xsent electronically to netinfo@garnet.Berkeley.EDU.
  3895. X
  3896. X
  3897. XOperational Characteristics
  3898. X
  3899. XThe POP Transaction Cycle
  3900. X
  3901. XThe Berkeley POP server is a single program (called popper) that is
  3902. Xlaunched by inetd when it gets a service request on the POP TCP port.
  3903. X(The official port number specified in RFC 1081 for POP version 3 is
  3904. Xport 110.  However, some POP3 clients attempt to contact the server at
  3905. Xport 109, the POP version 2 port.  Unless you are running both POP2 and
  3906. XPOP3 servers, you can simply define both ports for use by the POP3
  3907. Xserver.  This is explained in the installation instructions later on.)
  3908. XThe popper program initializes and verifies that the peer IP address is
  3909. Xregistered in the local domain, logging a warning message when a
  3910. Xconnection is made to a client whose IP address does not have a
  3911. Xcanonical name.  For systems using BSD 4.3 bind, it also checks to see
  3912. Xif a cannonical name lookup for the client returns the same peer IP
  3913. Xaddress, logging a warning message if it does not.  The the server
  3914. Xenters the authorization state, during which the client must correctly
  3915. Xidentify itself by providing a valid Unix userid and password on the
  3916. Xserver's host machine.  No other exchanges are allowed during this
  3917. Xstate (other than a request to quit.)  If authentication fails, a
  3918. Xwarning message is logged and the session ends.  Once the user is
  3919. Xidentified, popper changes its user and group ids to match that of the
  3920. Xuser and enters the transaction state.  The server makes a temporary
  3921. Xcopy of the user's maildrop (ordinarily in /usr/spool/mail) which is
  3922. Xused for all subsequent transactions.  These include the bulk of POP
  3923. Xcommands to retrieve mail, delete mail, undelete mail, and so forth.  A
  3924. XBerkeley extension also allows the user to submit a mail parcel to the
  3925. Xserver who mails it using the sendmail program (this extension is
  3926. Xsupported in the HyperMail client distributed with the server).  When
  3927. Xthe client quits, the server enters the final update state during which
  3928. Xthe network connection is terminated and the user's maildrop is updated
  3929. Xwith the (possibly) modified temporary maildrop.
  3930. X
  3931. X
  3932. XLogging
  3933. X
  3934. XThe POP server uses syslog to keep a record of its activities.  On
  3935. Xsystems with BSD 4.3 syslogging, the server logs (by default) to the
  3936. X"local0" facility at priority "notice" for all messages except
  3937. Xdebugging which is logged at priority "debug".  The default log file is
  3938. X/usr/spool/mqueue/POPlog.  These can be changed, if desired.  On
  3939. Xsystems with 4.2 syslogging all messages are logged to the local log
  3940. Xfile, usually /usr/spool/mqueue/syslog.
  3941. X
  3942. XProblems
  3943. X
  3944. XIf the filesystem which holds the /usr/spool/mail fills up users will 
  3945. Xexperience difficulties.  The filesystem must have enough space to hold
  3946. X(approximately) two copies of the largest mail box.  Popper (v1.81 and
  3947. Xabove) is designed to be robust in the face of this problem, but you may
  3948. Xend up with a situation where some of the user's mail is in
  3949. X
  3950. X    /usr/spool/mail/.userid.pop
  3951. X
  3952. Xand some of the mail is in
  3953. X
  3954. X    /usr/spool/mail/userid
  3955. X
  3956. XIf this happens the System Administrator should clear enough disk space
  3957. Xso that the filesystem has at least as much free disk as both mailboxes
  3958. Xhold and probably a little more.  Then the user should initiate a POP
  3959. Xsession, and do nothing but quit.  If the POP session ends without an
  3960. Xerror the user can then use POP or another mail program to clean up his/her
  3961. Xmailbox.
  3962. X
  3963. XAlternatively, the System Administrator can combine the two files (but
  3964. Xpopper will do this for you if there is enough disk space).
  3965. X
  3966. X
  3967. XDebugging
  3968. X
  3969. XThe popper program will log debugging information when the -d parameter
  3970. Xis specified after its invocation in the inetd.conf file.  Care should
  3971. Xbe exercised in using this option since it generates considerable
  3972. Xoutput in the syslog file.  Alternatively, the "-t <file-name>" option
  3973. Xwill place debugging information into file "<file-name>" using fprintf
  3974. Xinstead of syslog.  (To enable debugging, you must edit the Makefile
  3975. Xto add -DDEBUG to the compiler options.)
  3976. X
  3977. XFor SunOS version 3.5, the popper program is launched by inetd from
  3978. X/etc/servers.  This file does not allow you to specify command line
  3979. Xarguments.  Therefore, if you want to enable debugging, you can specify
  3980. Xa shell script in /etc/servers to be launched instead of popper and in
  3981. Xthis script call popper with the desired arguments.
  3982. X
  3983. X
  3984. XInstallation
  3985. X
  3986. X1.  Examine this file for the latest information, warnings, etc.
  3987. X
  3988. X2.  Check the Makefile for conformity with your system.
  3989. X
  3990. X3.  Issue the make command in the directory containing the popper 
  3991. X    source.
  3992. X
  3993. X4.  Issue the make install command in the directory containing the 
  3994. X    popper source to copy the program to /usr/etc.
  3995. X
  3996. X5.  Enable syslogging:
  3997. X
  3998. X    +   For systems with 4.3 syslogging:
  3999. X
  4000. X        Add the following line to the /etc/syslog.conf file:
  4001. X
  4002. X            local0.notice;local0.debug  /usr/spool/mqueue/POPlog
  4003. X
  4004. X        Create the empty file /usr/spool/mqueue/POPlog.
  4005. X
  4006. X        Kill and restart the syslogd daemon.
  4007. X
  4008. X    +   For systems with 4.2 syslogging:
  4009. X
  4010. X        Be sure that you are logging messages of priority 7 and higher.  
  4011. X        For example:
  4012. X
  4013. X            7/usr/spool/mqueue/syslog
  4014. X            9/dev/null
  4015. X
  4016. X6.  Update /etc/services:
  4017. X
  4018. X    Add the following line to the /etc/services file:
  4019. X
  4020. X        pop 110/tcp
  4021. X
  4022. X    Note:  This is the official port number for version 3 of the
  4023. X    Post Office Protocol as defined in RFC 1081.  However, some
  4024. X    POP3 clients use port 109, the port number for the previous
  4025. X    version (2) of POP.  Therefore you may also want to add the
  4026. X    following line to the /etc/services file:
  4027. X
  4028. X    pop2    109/tcp
  4029. X
  4030. X    For Sun systems running yp, also do the following:
  4031. X
  4032. X    +   Change to the /var/yp directory.
  4033. X
  4034. X    +   Issue the make services command.
  4035. X
  4036. X7.  Update the inetd daemon configuration.  Include the second line ONLY if you
  4037. X    are running the server at both ports.
  4038. X
  4039. X    +   On BSD 4.3 and SunOS 4.0 systems, add the following line to the 
  4040. X        /etc/inetd.conf file:
  4041. X
  4042. X        pop stream tcp nowait root /usr/etc/popper popper
  4043. X        pop2 stream tcp nowait root /usr/etc/popper popper
  4044. X
  4045. X    +   On Ultrix systems, add the following line to the 
  4046. X        /etc/inetd.conf file:
  4047. X
  4048. X        pop stream tcp nowait /usr/etc/popper popper
  4049. X        pop2 stream tcp nowait /usr/etc/popper popper
  4050. X
  4051. X    +   On SunOS 3.5 systems, add the following line to the 
  4052. X        /etc/servers file:
  4053. X
  4054. X        pop tcp /usr/etc/popper
  4055. X        pop2 tcp /usr/etc/popper
  4056. X
  4057. X        Kill and restart the inetd daemon.
  4058. X
  4059. XYou can confirm that the POP server is running on Unix by telneting to
  4060. Xport 110 (or 109 if you set it up that way).  For example:
  4061. X
  4062. X%telnet myhost 110
  4063. XTrying...
  4064. XConnected to myhost.berkeley.edu.
  4065. XEscape character is '^]'.
  4066. X+OK UCB Pop server (version 1.6) at myhost starting.
  4067. Xquit
  4068. XConnection closed by foreign host.
  4069. X
  4070. X
  4071. XRelease Notes
  4072. X
  4073. X1.83    Make sure that everything we do as root is non-destructive.
  4074. X
  4075. X1.82    Make the /usr/spool/mail/.userid.pop file owned by the user rather
  4076. X    than owned by root.
  4077. X
  4078. X1.81    There were two versions of 1.7 floating around, 1.7b4 and 1.7b5.
  4079. X    The difference is that 1.7b5 attempted to save disk space on 
  4080. X    /usr/spool/mail by deleting the users permanent maildrop after
  4081. X    making the temporary copy.  Unfortunately, if compiled with 
  4082. X    -DDEBUG, this version could easily wipe out a users' mail file.
  4083. X    This is now fixed.
  4084. X
  4085. X    This version also fixes a security hole for systems that have
  4086. X    /usr/spool/mail writeable by all users.
  4087. X
  4088. X    With this version we go to all new SCCS IDs for all files.  This
  4089. X    is unfortunate, and we hope it is not too much of a problem.
  4090. X
  4091. X    Thanks to Steve Dorner of UIUC for pointing out the major problem.
  4092. X
  4093. X1.7     Extensive re-write of the maildrop processing code contributed by 
  4094. X        Viktor Dukhovni <viktor@math.princeton.edu> that greatly reduces the
  4095. X        possibility that the maildrop can be corrupted as the result of
  4096. X        simultaneous access by two or more processes.
  4097. X
  4098. X        Added "pop_dropcopy" module to create a temporary maildrop from
  4099. X        the existing, standard maildrop as root before the setuid and 
  4100. X        setgid for the user is done.  This allows the temporary maildrop
  4101. X        to be created in a mail spool area that is not world read-writable.
  4102. X
  4103. X        This version does *not* send the sendmail "From " delimiter line
  4104. X        in response to a TOP or RETR command.
  4105. X
  4106. X        Encased all debugging code in #ifdef DEBUG constructs.  This code can
  4107. X        be included by specifying the DEGUG compiler flag.  Note:  You still
  4108. X        need to use the -d or -t option to obtain debugging output.
  4109. X
  4110. X1.6     Corrects a bug that causes the server to crash on SunOS
  4111. X        4.0 systems.
  4112. X
  4113. X        Uses varargs and vsprintf (if available) in pop_log and
  4114. X        pop_msg.  This is enabled by the "HAVE_VSPRINTF"
  4115. X        compiler flag.
  4116. X
  4117. X        For systems with BSD 4.3 bind, performs a cannonical
  4118. X        name lookup and searches the returned address(es) for
  4119. X        the client's address, logging a warning message if it
  4120. X        is not located.  This is enabled by the "BIND43"
  4121. X        comiler flag.
  4122. X
  4123. X        Removed all the includes from popper.h and distributed
  4124. X        them throughout the porgrams files, as needed.
  4125. X
  4126. X        Reformatted the source to convert tabs to spaces and
  4127. X        shorten lines for display on 80-column terminals.
  4128. X
  4129. X1.5     Creates the temporary maildrop with mode "600" and
  4130. X        immediately unlinks it.
  4131. X
  4132. X        Uses client's IP address in lieu of a canonical name if
  4133. X        the latter cannot be obtained.
  4134. X
  4135. X        Added "-t <file-name>" option.  The presence of this
  4136. X        option causes debugging output to be placed in the file
  4137. X        "file-name" using fprintf instead of the system log
  4138. X        file using syslog.
  4139. X
  4140. X        Corrected maildrop parsing problem.
  4141. X
  4142. X1.4     Copies user's mail into a temporary maildrop on which
  4143. X        all subsequent activity is performed.
  4144. X
  4145. X        Added "pop_log" function and replaced "syslog" calls
  4146. X        throughout the code with it.
  4147. X
  4148. X1.3     Corrected updating of Status: header line.
  4149. X
  4150. X        Added strncasecmp for systems that do not have one.
  4151. X        Used strncasecmp in all appropriate places.  This is
  4152. X        enabled by the STRNCASECMP compiler flag.
  4153. X
  4154. X1.2     Support for version 4.2 syslogging added.  This is
  4155. X        enabled by the SYSLOG42 compiler flag.
  4156. X
  4157. X1.1     Several bugs fixed.
  4158. X
  4159. X1.0     Original version.
  4160. X
  4161. X
  4162. XLimitations
  4163. X
  4164. X+   The POP server copies the user's entire maildrop to /tmp and
  4165. X    then operates on that copy.  If the maildrop is particularly
  4166. X    large, or inadequate space is available in /tmp, then the
  4167. X    server will refuse to continue and terminate the connection.
  4168. X
  4169. X+   Simultaneous modification of a single maildrop can result in 
  4170. X    confusing results.  For example, manipulating messages in a
  4171. X    maildrop using the Unix /usr/ucb/mail command while a copy of
  4172. X    it is being processed by the POP server can cause the changes
  4173. X    made by one program to be lost when the other terminates.  This
  4174. X    problem is being worked on and will be fixed in a later
  4175. X    release.
  4176. X
  4177. X
  4178. XCredits
  4179. X
  4180. XThe POP server was written by Edward Moy and Austin Shelton with
  4181. Xcontributions from Robert Campbell (U.C. Berkeley) and Viktor Dukhovni
  4182. X(Princeton University).  Edward Moy wrote the HyperMail stack and drew
  4183. Xthe POP operation diagram.  This installation guide was written by
  4184. XAustin Shelton.
  4185. X
  4186. X
  4187. XFootnotes
  4188. X
  4189. X[1] Copyright (c) 1990 Regents of the University of California.
  4190. X    All rights reserved.  The Berkeley software License Agreement
  4191. X    specifies the terms and conditions for redistribution.  Unix is
  4192. X    a registered trademark of AT&T corporation.  HyperCard and
  4193. X    Macintosh are registered trademarks of Apple Corporation.
  4194. X
  4195. X[2] M. Rose, Post Office Protocol - Version 3.  RFC  1081, NIC, 
  4196. X    November 1988.
  4197. X
  4198. X[3] M. Rose, Post Office Protocol - Version 3 Extended Service 
  4199. X    Offerings.  RFC 1082, NIC, November 1988.
  4200. SHAR_EOF
  4201. fi
  4202. if test -f 'Makefile'
  4203. then
  4204.     echo shar: "will not over-write existing file 'Makefile'"
  4205. else
  4206. sed 's/^X//' << \SHAR_EOF > 'Makefile'
  4207. X#@(#)@(#)Makefile    2.5  2.5 4/3/91
  4208. X
  4209. XCSRCS        =    pop_dele.c pop_dropcopy.c pop_dropinfo.c \
  4210. X            pop_get_command.c pop_get_subcommand.c pop_init.c \
  4211. X            pop_last.c pop_list.c pop_log.c pop_lower.c \
  4212. X            pop_msg.c pop_parse.c pop_pass.c pop_quit.c \
  4213. X            pop_rset.c pop_send.c pop_stat.c pop_updt.c \
  4214. X            pop_user.c pop_xtnd.c pop_xmit.c popper.c
  4215. X
  4216. XOBJS        =    pop_dele.o pop_dropcopy.o pop_dropinfo.o \
  4217. X            pop_get_command.o pop_get_subcommand.o pop_init.o \
  4218. X            pop_last.o pop_list.o pop_log.o pop_lower.o \
  4219. X            pop_msg.o pop_parse.o pop_pass.o pop_quit.o \
  4220. X            pop_rset.o pop_send.o pop_stat.o pop_updt.o \
  4221. X            pop_user.o pop_xtnd.o pop_xmit.o popper.o
  4222. X
  4223. XDOCS        =    README pop3.rfc1081 pop3e.rfc1082 popper.8
  4224. X
  4225. XINCLUDES    =    popper.h version.h
  4226. X
  4227. XSRCS        =    ${CSRCS} ${INCLUDES}
  4228. X
  4229. XSCCS        =    /usr/ucb/sccs
  4230. X
  4231. XREL        =
  4232. X
  4233. XMAKEFILE    =    Makefile
  4234. X
  4235. X#               Options are:
  4236. X#               BIND43          -    If you are using BSD 4.3 domain 
  4237. X#                    name service.
  4238. X#        DEBUG        -    Include the debugging code.  Note:  You
  4239. X#                    still have to use the -d or -t flag to
  4240. X#                    enable debugging.
  4241. X#               HAVE_VSPRINTF   -    If the vsprintf functions are available 
  4242. X#                    on your system.
  4243. X#               SYSLOG42        -    For BSD 4.2 syslog (default is BSD 4.3 
  4244. X#                    syslog).
  4245. X#               STRNCASECMP     -    If you do not have strncasecmp()
  4246. X
  4247. XCFLAGS        =    -O -DBIND43
  4248. X
  4249. XTARGET        =    popper
  4250. X
  4251. XTAR        =    ${TARGET}.tar
  4252. X
  4253. XINSTALLDIR    =    /usr/etc
  4254. X
  4255. XMANPAGE        =    popper.8
  4256. X
  4257. XCATPAGE        =    popper.0
  4258. X
  4259. XMANDIR        =    /usr/local/man/cat8
  4260. X
  4261. X
  4262. X
  4263. X${TARGET}: ${OBJS}
  4264. X    cc  -i ${OBJS} -o ${TARGET}
  4265. X
  4266. Xtar: ${SRCS} ${DOCS} ${MAKEFILE}
  4267. X    rm -f ${TAR} *.Z*
  4268. X    tar -cvf ${TAR} ${SRCS} ${DOCS} ${MAKEFILE}
  4269. X    compress ${TAR}
  4270. X    uuencode ${TAR}.Z ${TAR}.Z > ${TAR}.Z.uuencoded
  4271. X    split -300 ${TAR}.Z.uuencoded
  4272. X    mv xaa ${TAR}.Z.uuencoded.xaa
  4273. X    mv xab ${TAR}.Z.uuencoded.xab
  4274. X    mv xac ${TAR}.Z.uuencoded.xac
  4275. X    mv xad ${TAR}.Z.uuencoded.xad
  4276. X    mv xae ${TAR}.Z.uuencoded.xae
  4277. X
  4278. Xclean:
  4279. X    rm -f core *.o *.Z*
  4280. X    ${SCCS} clean
  4281. X
  4282. Xinstall: ${TARGET}
  4283. X    install -c -m 700 -o root -g staff ${TARGET} ${INSTALLDIR}
  4284. X
  4285. Xinstallman:
  4286. X    rm -f ${CATPAGE}
  4287. X    nroff -man ${MANPAGE} > ${CATPAGE}
  4288. X    install -c -m 644 -o root -g staff ${CATPAGE} ${MANDIR}
  4289. X
  4290. Xedit:
  4291. X    ${SCCS} edit ${REL} ${SRCS}
  4292. X
  4293. Xadmin:
  4294. X    ${SCCS} admin -ft"Copyright (c) 1990 Regents of the University of California.\nAll rights reserved.\n" ${SRCS}
  4295. X
  4296. Xsources: ${SRCS}
  4297. X
  4298. X${SRCS}:
  4299. X    ${SCCS} get ${REL} $@ -p | expand -4 > $@
  4300. X
  4301. X${DOCS}:
  4302. X    ${SCCS} get README -p | expand -4 > README
  4303. X    ${SCCS} get popper.8 -p | expand -4 > popper.8
  4304. X    
  4305. X${OBJS}:    popper.h version.h
  4306. SHAR_EOF
  4307. fi
  4308. cd ..
  4309. exit 0
  4310. #    End of shell archive
  4311.