source: zwrite.c @ 4b464a4

barnowl_perlaimdebianowlrelease-1.10release-1.4release-1.5release-1.6release-1.7release-1.8release-1.9
Last change on this file since 4b464a4 was 4b464a4, checked in by James M. Kretchmar <kretch@mit.edu>, 22 years ago
Messages now have a direciton (in, out or none). Filters can this direction Outbound messages are no longer type 'admin' but are of the appropriate message type (i.e. 'zephyr') and are direction 'out'. Smartnarrow now works on outgoing messages 'info' updated to show more information for admin and outgoing messages Renamed pretty_sender to short_zuser and renamed long_sender to long_zuser
  • Property mode set to 100644
File size: 4.9 KB
Line 
1#include <string.h>
2#include "owl.h"
3
4static const char fileIdent[] = "$Id$";
5
6int owl_zwrite_create_and_send_from_line(char *cmd, char *msg) {
7  owl_zwrite z;
8  int rv;
9  rv = owl_zwrite_create_from_line(&z, cmd);
10  if (rv) return(rv);
11  owl_zwrite_send_message(&z, msg);
12  owl_zwrite_free(&z);
13  return(0);
14}
15
16int owl_zwrite_create_from_line(owl_zwrite *z, char *line) {
17  int argc, badargs, myargc;
18  char **argv, **myargv;
19
20  badargs=0;
21 
22  /* set the defaults */
23  strcpy(z->realm, "");
24  strcpy(z->class, "message");
25  strcpy(z->inst, "personal");
26  strcpy(z->opcode, "");
27  z->cc=0;
28  z->noping=0;
29  owl_list_create(&(z->recips));
30
31  /* parse the command line for options */
32  argv=myargv=owl_parseline(line, &argc);
33  if (argc<0) {
34    owl_function_makemsg("Unbalanced quotes");
35    return(-1);
36  }
37  myargc=argc;
38  if (myargc && *(myargv[0])!='-') {
39    myargc--;
40    myargv++;
41  }
42  while (myargc) {
43    if (!strcmp(myargv[0], "-c")) {
44      if (myargc<2) {
45        badargs=1;
46        break;
47      }
48      strcpy(z->class, myargv[1]);
49      myargv+=2;
50      myargc-=2;
51    } else if (!strcmp(myargv[0], "-i")) {
52      if (myargc<2) {
53        badargs=1;
54        break;
55      }
56      strcpy(z->inst, myargv[1]);
57      myargv+=2;
58      myargc-=2;
59    } else if (!strcmp(myargv[0], "-r")) {
60      if (myargc<2) {
61        badargs=1;
62        break;
63      }
64      strcpy(z->realm, myargv[1]);
65      myargv+=2;
66      myargc-=2;
67    } else if (!strcmp(myargv[0], "-O")) {
68      if (myargc<2) {
69        badargs=1;
70        break;
71      }
72      strcpy(z->opcode, myargv[1]);
73      myargv+=2;
74      myargc-=2;
75    } else if (!strcmp(myargv[0], "-C")) {
76      z->cc=1;
77      myargv++;
78      myargc--;
79    } else if (!strcmp(myargv[0], "-n")) {
80      z->noping=1;
81      myargv++;
82      myargc--;
83    } else {
84      /* anything unattached is a recipient */
85      owl_list_append_element(&(z->recips), strdup(myargv[0]));
86      myargv++;
87      myargc--;
88    }
89  }
90
91  owl_parsefree(argv, argc);
92
93  if (badargs) {
94    return(-1);
95  }
96
97  if (!strcasecmp(z->class, "message") &&
98      !strcasecmp(z->inst, "personal") &&
99      owl_list_get_size(&(z->recips))==0) {
100    /* do the makemsg somewhere else */
101    owl_function_makemsg("You must specify a recipient");
102    return(-1);
103  }
104
105  return(0);
106}
107
108void owl_zwrite_send_ping(owl_zwrite *z) {
109  int i, j;
110  char to[LINE];
111
112  if (z->noping) return;
113 
114  if (strcasecmp(z->class, "message") ||
115      strcasecmp(z->inst, "personal")) {
116    return;
117  }
118
119  /* if there are no recipients we won't send a ping, which
120     is what we want */
121  j=owl_list_get_size(&(z->recips));
122  for (i=0; i<j; i++) {
123    if (strcmp(z->realm, "")) {
124      sprintf(to, "%s@%s", (char *) owl_list_get_element(&(z->recips), i), z->realm);
125    } else {
126      strcpy(to, owl_list_get_element(&(z->recips), i));
127    }
128    send_ping(to);
129  }
130
131}
132
133void owl_zwrite_send_message(owl_zwrite *z, char *msg) {
134  int i, j;
135  char to[LINE];
136
137  j=owl_list_get_size(&(z->recips));
138  if (j>0) {
139    char *tmpmsg=NULL;
140    char toline[LINE];
141
142    if (z->cc) {
143      strcpy(toline, "CC: ");
144      for (i=0; i<j; i++) {
145        if (strcmp(z->realm, "")) {
146          sprintf(toline, "%s%s@%s ", toline, (char *) owl_list_get_element(&(z->recips), i), z->realm);
147        } else {
148          sprintf(toline, "%s%s ", toline, (char *) owl_list_get_element(&(z->recips), i));
149        }
150      }
151      tmpmsg=owl_malloc(strlen(msg)+strlen(toline)+30);
152      sprintf(tmpmsg, "%s\n%s", toline, msg);
153    }
154
155    for (i=0; i<j; i++) {
156      if (strcmp(z->realm, "")) {
157        sprintf(to, "%s@%s", (char *) owl_list_get_element(&(z->recips), i), z->realm);
158      } else {
159        strcpy(to, owl_list_get_element(&(z->recips), i));
160      }
161      if (z->cc) {
162        send_zephyr(z->opcode, NULL, z->class, z->inst, to, tmpmsg);
163      } else {
164        send_zephyr(z->opcode, NULL, z->class, z->inst, to, msg);
165      }
166    }
167    if (z->cc) {
168      owl_free(tmpmsg);
169    }
170  } else {
171    sprintf(to, "@%s", z->realm);
172    send_zephyr(z->opcode, NULL, z->class, z->inst, to, msg);
173  }
174}
175
176char *owl_zwrite_get_class(owl_zwrite *z) {
177  return(z->class);
178}
179
180char *owl_zwrite_get_instance(owl_zwrite *z) {
181  return(z->inst);
182}
183
184char *owl_zwrite_get_opcode(owl_zwrite *z) {
185  return(z->opcode);
186}
187
188char *owl_zwrite_get_realm(owl_zwrite *z) {
189  return(z->realm);
190}
191
192void owl_zwrite_get_recipstr(owl_zwrite *z, char *buff) {
193  int i, j;
194
195  strcpy(buff, "");
196  j=owl_list_get_size(&(z->recips));
197  for (i=0; i<j; i++) {
198    strcat(buff, owl_list_get_element(&(z->recips), i));
199    strcat(buff, " ");
200  }
201  buff[strlen(buff)-1]='\0';
202}
203
204int owl_zwrite_get_numrecips(owl_zwrite *z) {
205  return(owl_list_get_size(&(z->recips)));
206}
207
208char *owl_zwrite_get_recip_n(owl_zwrite *z, int n) {
209  return(owl_list_get_element(&(z->recips), n));
210}
211
212int owl_zwrite_is_personal(owl_zwrite *z) {
213  /* return true if at least one of the recipients is personal */
214  int i, j;
215  char *foo;
216
217  j=owl_list_get_size(&(z->recips));
218  for (i=0; i<j; i++) {
219    foo=owl_list_get_element(&(z->recips), i);
220    if (foo[0]!='@') return(1);
221  }
222  return(0);
223}
224 
225void owl_zwrite_free(owl_zwrite *z) {
226  owl_list_free_all(&(z->recips), &owl_free);
227}
Note: See TracBrowser for help on using the repository browser.