1
2 static char rcsid[] = "@(#)$Id: calendar.c,v 1.3 1996/03/14 17:27:54 wfp5p Exp $";
3
4 /*******************************************************************************
5 * The Elm Mail System - $Revision: 1.3 $ $State: Exp $
6 *
7 * Copyright (c) 1988-1995 USENET Community Trust
8 * Copyright (c) 1986,1987 Dave Taylor
9 *******************************************************************************
10 * Bug reports, patches, comments, suggestions should be sent to:
11 *
12 * Bill Pemberton, Elm Coordinator
13 * flash@virginia.edu
14 *
15 *******************************************************************************
16 * $Log: calendar.c,v $
17 * Revision 1.3 1996/03/14 17:27:54 wfp5p
18 * Alpha 9
19 *
20 * Revision 1.2 1995/09/29 17:42:01 wfp5p
21 * Alpha 8 (Chip's big changes)
22 *
23 * Revision 1.1.1.1 1995/04/19 20:38:35 wfp5p
24 * Initial import of elm 2.4 PL0 as base for elm 2.5.
25 *
26 ******************************************************************************/
27
28 /** This routine implements a rather snazzy idea suggested by Warren
29 Carithers of the Rochester Institute of Technology that allows
30 mail to contain entries formatted in a manner that will allow direct
31 copying into a users calendar program.
32
33 All lines in the current message beginning with "->", e.g.
34
35 -> Mon 04/21 1:00p meet with chairman candidate
36
37 get copied into the user's calendar file.
38
39 **/
40
41 #include "elm_defs.h"
42 #include "elm_globals.h"
43
44 #ifdef ENABLE_CALENDAR /* if not defined, this will be an empty file */
45
46 #include "s_error.h"
47
48 void
scan_calendar()49 scan_calendar()
50 {
51 FILE *calendar;
52 int count;
53 int err;
54
55 /* First step is to open the calendar file for appending... **/
56
57 if (can_open(calendar_file, "a") != 0) {
58 err = errno;
59 dprint(2, (debugfile,
60 "Error: wrong permissions to append to calendar %s\n",
61 calendar_file));
62 dprint(2, (debugfile, "** - %s **\n", strerror(err)));
63 error1(catgets(elm_msg_cat, ErrorSet, ErrorCalendarCanOpen,
64 "Not able to append to file %s!"), calendar_file);
65 return;
66 }
67
68 save_file_stats(calendar_file);
69
70 if ((calendar = fopen(calendar_file,"a")) == NULL) {
71 err = errno;
72 dprint(2, (debugfile,
73 "Error: couldn't append to calendar file %s (scan)\n",
74 calendar_file));
75 dprint(2, (debugfile, "** - %s **\n", strerror(err)));
76 error1(catgets(elm_msg_cat, ErrorSet, ErrorCalendarAppend,
77 "Couldn't append to file %s!"), calendar_file);
78 return;
79 }
80
81 count = extract_info(calendar);
82
83 fclose(calendar);
84
85 restore_file_stats(calendar_file);
86
87 if (count > 0) {
88 if (count > 1)
89 error1(catgets(elm_msg_cat, ErrorSet, ErrorCalendarSavedPlural,
90 "%d entries saved in calendar file."), count);
91 else
92 error(catgets(elm_msg_cat, ErrorSet, ErrorCalendarSaved,
93 "1 entry saved in calendar file."));
94 } else
95 error(catgets(elm_msg_cat, ErrorSet, ErrorCalendarNoneSaved,
96 "No calendar entries found in that message."));
97
98 return;
99 }
100
101 int
extract_info(save_to_fd)102 extract_info(save_to_fd)
103 FILE *save_to_fd;
104 {
105 /** Save the relevant parts of the current message to the given
106 calendar file. The only parameter is an opened file
107 descriptor, positioned at the end of the existing file **/
108
109 register int entries = 0, lines;
110 int line_length;
111 char buffer[SLEN], *cp, *is_cal_entry();
112 struct header_rec *hdr;
113
114 hdr = curr_folder.headers[curr_folder.curr_mssg-1];
115
116 /** get to the first line of the message desired **/
117
118 if (fseek(curr_folder.fp, hdr->offset, 0) == -1) {
119 dprint(1,(debugfile,
120 "ERROR: Attempt to seek %d bytes into file failed (%s)",
121 hdr->offset, "extract_info"));
122 error1(catgets(elm_msg_cat, ErrorSet, ErrorCalendarSeek,
123 "ELM [seek] failed trying to read %d bytes into file."),
124 hdr->offset);
125 return(0);
126 }
127
128 /* how many lines in message? */
129
130 lines = hdr->lines;
131
132 /* now while not EOF & still in message... scan it! */
133
134 while (lines) {
135
136 if((line_length = mail_gets(buffer, SLEN, curr_folder.fp)) == 0)
137 break;
138
139 if(buffer[line_length - 1] == '\n')
140 lines--; /* got a full line */
141
142 if((cp = is_cal_entry(buffer)) != NULL) {
143 entries++;
144 fprintf(save_to_fd,"%s", cp);
145 }
146
147 }
148 dprint(4,(debugfile,
149 "Got %d calender entr%s.\n", entries, entries > 1? "ies":"y"));
150
151 return(entries);
152 }
153
154 char *
is_cal_entry(string)155 is_cal_entry(string)
156 register char *string;
157 {
158 /* If string is of the form
159 * {optional white space} ->{optional white space} {stuff}
160 * return a pointer to stuff, otherwise return NULL.
161 */
162 while( whitespace(*string) )
163 string++; /* strip leading W/S */
164
165 if(strncmp(string, "->", 2) == 0) {
166 for(string +=2 ; whitespace(*string); string++)
167 ;
168 return(string);
169 }
170 return(NULL);
171 }
172
173 #endif
174