forked from barnowl/barnowl
-
Notifications
You must be signed in to change notification settings - Fork 1
/
functions.c
3582 lines (3042 loc) · 97.7 KB
/
functions.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include "owl.h"
#include "filterproc.h"
#include <stdio.h>
#include <sys/stat.h>
#include <sys/wait.h>
CALLER_OWN char *owl_function_command(const char *cmdbuff)
{
owl_function_debugmsg("executing command: %s", cmdbuff);
return owl_cmddict_execute(owl_global_get_cmddict(&g),
owl_global_get_context(&g), cmdbuff);
}
CALLER_OWN char *owl_function_command_argv(const char *const *argv, int argc)
{
return owl_cmddict_execute_argv(owl_global_get_cmddict(&g),
owl_global_get_context(&g),
argv, argc);
}
void owl_function_command_norv(const char *cmdbuff)
{
char *rv;
rv=owl_function_command(cmdbuff);
g_free(rv);
}
void owl_function_command_alias(const char *alias_from, const char *alias_to)
{
owl_cmddict_add_alias(owl_global_get_cmddict(&g), alias_from, alias_to);
}
const owl_cmd *owl_function_get_cmd(const char *name)
{
return owl_cmddict_find(owl_global_get_cmddict(&g), name);
}
void owl_function_show_commands(void)
{
GPtrArray *l;
owl_fmtext fm;
owl_fmtext_init_null(&fm);
owl_fmtext_append_bold(&fm, "Commands: ");
owl_fmtext_append_normal(&fm, "(use 'show command <name>' for details)\n");
l = owl_cmddict_get_names(owl_global_get_cmddict(&g));
owl_fmtext_append_list(&fm, l, "\n", owl_function_cmd_describe);
owl_fmtext_append_normal(&fm, "\n");
owl_function_popless_fmtext(&fm);
owl_ptr_array_free(l, g_free);
owl_fmtext_cleanup(&fm);
}
void owl_function_show_view(const char *viewname)
{
const owl_view *v;
owl_fmtext fm;
/* we only have the one view right now */
v=owl_global_get_current_view(&g);
if (viewname && strcmp(viewname, owl_view_get_name(v))) {
owl_function_error("No view named '%s'", viewname);
return;
}
owl_fmtext_init_null(&fm);
owl_view_to_fmtext(v, &fm);
owl_function_popless_fmtext(&fm);
owl_fmtext_cleanup(&fm);
}
void owl_function_show_styles(void) {
GPtrArray *l;
owl_fmtext fm;
owl_fmtext_init_null(&fm);
owl_fmtext_append_bold(&fm, "Styles:\n");
l = owl_global_get_style_names(&g);
owl_fmtext_append_list(&fm, l, "\n", owl_function_style_describe);
owl_fmtext_append_normal(&fm, "\n");
owl_function_popless_fmtext(&fm);
owl_ptr_array_free(l, g_free);
owl_fmtext_cleanup(&fm);
}
CALLER_OWN char *owl_function_style_describe(const char *name)
{
const char *desc;
char *s;
const owl_style *style;
style = owl_global_get_style_by_name(&g, name);
if (style) {
desc = owl_style_get_description(style);
} else {
desc = "???";
}
s = g_strdup_printf("%-20s - %s%s", name,
0 == owl_style_validate(style) ? "" : "[INVALID] ",
desc);
return s;
}
CALLER_OWN char *owl_function_cmd_describe(const char *name)
{
const owl_cmd *cmd = owl_cmddict_find(owl_global_get_cmddict(&g), name);
if (cmd) return owl_cmd_describe(cmd);
else return(NULL);
}
void owl_function_show_command(const char *name)
{
owl_function_help_for_command(name);
}
void owl_function_show_license(void)
{
char *text = g_strdup_printf(
"BarnOwl version %s\n"
"Copyright (c) 2006-2011 The BarnOwl Developers. All rights reserved.\n"
"Copyright (c) 2004 James Kretchmar. All rights reserved.\n"
"\n"
"Redistribution and use in source and binary forms, with or without\n"
"modification, are permitted provided that the following conditions are\n"
"met:\n"
"\n"
" * Redistributions of source code must retain the above copyright\n"
" notice, this list of conditions and the following disclaimer.\n"
"\n"
" * Redistributions in binary form must reproduce the above copyright\n"
" notice, this list of conditions and the following disclaimer in\n"
" the documentation and/or other materials provided with the\n"
" distribution.\n"
"\n"
" * Redistributions in any form must be accompanied by information on\n"
" how to obtain complete source code for the BarnOwl software and any\n"
" accompanying software that uses the BarnOwl software. The source code\n"
" must either be included in the distribution or be available for no\n"
" more than the cost of distribution plus a nominal fee, and must be\n"
" freely redistributable under reasonable conditions. For an\n"
" executable file, complete source code means the source code for\n"
" all modules it contains. It does not include source code for\n"
" modules or files that typically accompany the major components of\n"
" the operating system on which the executable file runs.\n"
"\n"
"THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR\n"
"IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\n"
"WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR\n"
"NON-INFRINGEMENT, ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE\n"
"LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR\n"
"CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF\n"
"SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR\n"
"BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,\n"
"WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE\n"
"OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN\n"
"IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n",
version);
owl_function_popless_text(text);
g_free(text);
}
void owl_function_show_quickstart(void)
{
const char *message =
"Move between messages with the arrow keys, and press 'r' to reply.\n"
"For more info, press 'h' or visit http://barnowl.mit.edu/\n\n"
#ifdef HAVE_LIBZEPHYR
"@b(Zephyr:)\n"
"To send a message to a user, type ':zwrite @b(username)'. You can also\n"
"press 'z' and then type the username. To subscribe to a class, type\n"
"':sub @b(class)', and then type ':zwrite -c @b(class)' to send.\n\n"
#endif
"@b(AIM:)\n"
"Log in to AIM with ':aimlogin @b(screenname)'. Use ':aimwrite @b(screenname)',\n"
"or 'a' and then the screen name, to send someone a message.\n\n"
;
if (owl_perlconfig_is_function("BarnOwl::Hooks::_get_quickstart")) {
char *perlquickstart = owl_perlconfig_execute("BarnOwl::Hooks::_get_quickstart()");
if (perlquickstart) {
char *result = g_strdup_printf("%s%s", message, perlquickstart);
owl_function_adminmsg("BarnOwl Quickstart", result);
g_free(result);
g_free(perlquickstart);
return;
}
}
owl_function_adminmsg("BarnOwl Quickstart", message);
}
/* Create an admin message, append it to the global list of messages
* and redisplay if necessary.
*/
void owl_function_adminmsg(const char *header, const char *body)
{
owl_message *m;
m=g_slice_new(owl_message);
owl_message_create_admin(m, header, body);
/* add it to the global list and current view */
owl_messagelist_append_element(owl_global_get_msglist(&g), m);
owl_view_consider_message(owl_global_get_current_view(&g), m);
/* do followlast if necessary */
if (owl_global_should_followlast(&g)) owl_function_lastmsg();
/* redisplay etc. */
owl_mainwin_redisplay(owl_global_get_mainwin(&g));
}
/* Queues outgoing zephyrs; if z sends to n people, queue n messages
* (except in case of cc). If there are no recipients queues 1
* message.
*/
void owl_function_add_outgoing_zephyrs(const owl_zwrite *z)
{
if (z->cc && owl_zwrite_is_personal(z)) {
/* create the message */
owl_message *m = g_slice_new(owl_message);
owl_message_create_from_zwrite(m, z, owl_zwrite_get_message(z), 0);
owl_global_messagequeue_addmsg(&g, m);
} else {
int i;
for (i = 0; i < owl_zwrite_get_numrecips(z); i++) {
owl_message *m;
if (!owl_zwrite_recip_is_personal(owl_zwrite_get_recip_n(z, i)))
continue;
/* create the message */
m = g_slice_new(owl_message);
owl_message_create_from_zwrite(m, z, owl_zwrite_get_message(z), i);
owl_global_messagequeue_addmsg(&g, m);
}
}
}
/* Create an outgoing AIM message, returns a pointer to the created
* message or NULL if we're not logged into AIM (and thus unable to
* create the message). Does not put it on the global queue. Use
* owl_global_messagequeue_addmsg() for that.
*/
CALLER_OWN owl_message *owl_function_make_outgoing_aim(const char *body, const char *to)
{
owl_message *m;
/* error if we're not logged into aim */
if (!owl_global_is_aimloggedin(&g)) return(NULL);
m=g_slice_new(owl_message);
owl_message_create_aim(m,
owl_global_get_aim_screenname(&g),
to,
body,
OWL_MESSAGE_DIRECTION_OUT,
0);
return(m);
}
/* Create an outgoing loopback message and return a pointer to it.
* Does not append it to the global queue, use
* owl_global_messagequeue_addmsg() for that.
*/
CALLER_OWN owl_message *owl_function_make_outgoing_loopback(const char *body)
{
owl_message *m;
/* create the message */
m=g_slice_new(owl_message);
owl_message_create_loopback(m, body);
owl_message_set_direction_out(m);
return(m);
}
owl_editwin *owl_function_start_edit_win(const char *line)
{
owl_editwin *e;
owl_context *ctx;
char *s;
/* create and setup the editwin */
e = owl_global_set_typwin_active(&g, OWL_EDITWIN_STYLE_MULTILINE,
owl_global_get_msg_history(&g));
owl_editwin_set_dotsend(e);
s = g_strdup_printf("----> %s\n", line);
owl_editwin_set_locktext(e, s);
g_free(s);
ctx = owl_editcontext_new(OWL_CTX_EDITMULTI, e, "editmulti",
owl_global_deactivate_editcontext, &g);
owl_global_push_context_obj(&g, ctx);
return e;
}
static void owl_function_write_setup(const char *noun)
{
if (!owl_global_get_lockout_ctrld(&g))
owl_function_makemsg("Type your %s below. "
"End with ^D or a dot on a line by itself."
" ^C will quit.", noun);
else
owl_function_makemsg("Type your %s below. "
"End with a dot on a line by itself. ^C will quit.",
noun);
}
void owl_function_zwrite_setup(owl_zwrite *z)
{
owl_editwin *e;
/* send a ping if necessary */
if (owl_global_is_txping(&g)) {
owl_zwrite_send_ping(z);
}
owl_function_write_setup("zephyr");
e = owl_function_start_edit_win(z->zwriteline);
owl_editwin_set_cbdata(e, z, (void (*)(void *))owl_zwrite_delete);
owl_editwin_set_callback(e, &owl_callback_zwrite);
}
void owl_function_aimwrite_setup(const char *to)
{
owl_editwin *e;
/* TODO: We probably actually want an owl_aimwrite object like
* owl_zwrite. */
char *line = g_strdup_printf("aimwrite %s", to);
owl_function_write_setup("message");
e = owl_function_start_edit_win(line);
owl_editwin_set_cbdata(e, g_strdup(to), g_free);
owl_editwin_set_callback(e, &owl_callback_aimwrite);
g_free(line);
}
void owl_function_loopwrite_setup(void)
{
owl_editwin *e;
owl_function_write_setup("message");
e = owl_function_start_edit_win("loopwrite");
owl_editwin_set_callback(e, &owl_callback_loopwrite);
}
void owl_callback_zwrite(owl_editwin *e, bool success)
{
if (!success) return;
owl_zwrite *z = owl_editwin_get_cbdata(e);
owl_function_zwrite(z, owl_editwin_get_text(e));
}
/* send, log and display outgoing zephyrs. If 'msg' is NULL the
* message is expected to be set from the zwrite line itself
*/
#ifdef HAVE_LIBZEPHYR
void owl_function_zwrite(owl_zwrite *z, const char *msg)
{
int ret;
if(strcmp(z->cmd, "zcrypt") == 0) {
owl_function_zcrypt(z, msg);
return;
}
/* create the zwrite and send the message */
owl_zwrite_populate_zsig(z);
if (msg) {
owl_zwrite_set_message(z, msg);
}
ret = owl_zwrite_send_message(z);
if (ret != 0) {
owl_function_makemsg("Error sending zephyr: %s", error_message(ret));
return;
}
owl_function_makemsg("Waiting for ack...");
/* create the outgoing message */
owl_function_add_outgoing_zephyrs(z);
}
#else
void owl_function_zwrite(owl_zwrite *z, const char *msg) {
}
#endif
/* send, log and display outgoing zcrypt zephyrs. If 'msg' is NULL
* the message is expected to be set from the zwrite line itself
*/
void owl_function_zcrypt(owl_zwrite *z, const char *msg)
{
char *cryptmsg;
const char *argv[7];
char *zcrypt;
int rv, status;
char *old_msg;
/* create the zwrite and send the message */
owl_zwrite_populate_zsig(z);
if (msg) {
owl_zwrite_set_message(z, msg);
}
old_msg = g_strdup(owl_zwrite_get_message(z));
zcrypt = g_build_filename(owl_get_bindir(), "zcrypt", NULL);
argv[0] = zcrypt;
argv[1] = "-E";
argv[2] = "-c"; argv[3] = owl_zwrite_get_class(z);
argv[4] = "-i"; argv[5] = owl_zwrite_get_instance(z);
argv[6] = NULL;
rv = call_filter(argv, owl_zwrite_get_message(z), &cryptmsg, &status);
g_free(zcrypt);
if (rv || status) {
g_free(cryptmsg);
g_free(old_msg);
owl_function_error("Error in zcrypt, possibly no key found. Message not sent.");
owl_function_beep();
return;
}
owl_zwrite_set_message_raw(z, cryptmsg);
owl_zwrite_set_opcode(z, "crypt");
owl_zwrite_send_message(z);
owl_function_makemsg("Waiting for ack...");
/* Create the outgoing message. Restore the un-crypted message for display. */
owl_zwrite_set_message_raw(z, old_msg);
owl_function_add_outgoing_zephyrs(z);
/* Clean up. */
g_free(cryptmsg);
g_free(old_msg);
}
void owl_callback_aimwrite(owl_editwin *e, bool success)
{
if (!success) return;
char *to = owl_editwin_get_cbdata(e);
owl_function_aimwrite(to, owl_editwin_get_text(e), true);
}
void owl_function_aimwrite(const char *to, const char *msg, bool unwrap)
{
int ret;
char *format_msg;
owl_message *m;
/* make a formatted copy of the message */
format_msg = g_strdup(msg);
if (unwrap)
owl_text_wordunwrap(format_msg);
/* send the message */
ret=owl_aim_send_im(to, format_msg);
if (!ret) {
owl_function_makemsg("AIM message sent.");
} else {
owl_function_error("Could not send AIM message.");
}
/* create the outgoing message */
m=owl_function_make_outgoing_aim(msg, to);
if (m) {
owl_global_messagequeue_addmsg(&g, m);
} else {
owl_function_error("Could not create outgoing AIM message");
}
g_free(format_msg);
}
void owl_function_send_aimawymsg(const char *to, const char *msg)
{
int ret;
char *format_msg;
owl_message *m;
/* make a formatted copy of the message */
format_msg=g_strdup(msg);
owl_text_wordunwrap(format_msg);
/* send the message */
ret=owl_aim_send_awaymsg(to, format_msg);
if (!ret) {
/* owl_function_makemsg("AIM message sent."); */
} else {
owl_function_error("Could not send AIM message.");
}
/* create the message */
m=owl_function_make_outgoing_aim(msg, to);
if (m) {
owl_global_messagequeue_addmsg(&g, m);
} else {
owl_function_error("Could not create AIM message");
}
g_free(format_msg);
}
void owl_callback_loopwrite(owl_editwin *e, bool success)
{
if (!success) return;
owl_function_loopwrite(owl_editwin_get_text(e));
}
void owl_function_loopwrite(const char *msg)
{
owl_message *min, *mout;
/* create a message and put it on the message queue. This simulates
* an incoming message */
min=g_slice_new(owl_message);
mout=owl_function_make_outgoing_loopback(msg);
if (owl_global_is_displayoutgoing(&g)) {
owl_global_messagequeue_addmsg(&g, mout);
} else {
owl_message_delete(mout);
}
owl_message_create_loopback(min, msg);
owl_message_set_direction_in(min);
owl_global_messagequeue_addmsg(&g, min);
/* fake a makemsg */
owl_function_makemsg("loopback message sent");
}
/* If filter is non-null, looks for the next message matching
* that filter. If skip_deleted, skips any deleted messages.
* If last_if_none, will stop at the last message in the view
* if no matching messages are found. */
void owl_function_nextmsg_full(const char *filter, int skip_deleted, int last_if_none)
{
int curmsg, i, viewsize, found;
const owl_view *v;
const owl_filter *f = NULL;
const owl_message *m;
v=owl_global_get_current_view(&g);
if (filter) {
f=owl_global_get_filter(&g, filter);
if (!f) {
owl_function_error("No %s filter defined", filter);
return;
}
}
curmsg=owl_global_get_curmsg(&g);
viewsize=owl_view_get_size(v);
found=0;
/* just check to make sure we're in bounds... */
if (curmsg>viewsize-1) curmsg=viewsize-1;
if (curmsg<0) curmsg=0;
for (i=curmsg+1; i<viewsize; i++) {
m=owl_view_get_element(v, i);
if (skip_deleted && owl_message_is_delete(m)) continue;
if (f && !owl_filter_message_match(f, m)) continue;
found = 1;
break;
}
if (i>owl_view_get_size(v)-1) i=owl_view_get_size(v)-1;
if (i<0) i=0;
if (!found) {
owl_function_makemsg("already at last%s message%s%s%s",
skip_deleted?" non-deleted":"",
filter?" in ":"", filter?filter:"",
owl_mainwin_is_curmsg_truncated(owl_global_get_mainwin(&g)) ?
", press Enter to scroll" : "");
/* if (!skip_deleted) owl_function_beep(); */
}
if (last_if_none || found) {
owl_global_set_curmsg(&g, i);
owl_function_calculate_topmsg(OWL_DIRECTION_DOWNWARDS);
owl_mainwin_redisplay(owl_global_get_mainwin(&g));
owl_global_set_direction_downwards(&g);
}
}
void owl_function_prevmsg_full(const char *filter, int skip_deleted, int first_if_none)
{
int curmsg, i, found;
const owl_view *v;
const owl_filter *f = NULL;
const owl_message *m;
v=owl_global_get_current_view(&g);
if (filter) {
f=owl_global_get_filter(&g, filter);
if (!f) {
owl_function_error("No %s filter defined", filter);
return;
}
}
curmsg=owl_global_get_curmsg(&g);
found=0;
/* just check to make sure we're in bounds... */
if (curmsg<0) curmsg=0;
for (i=curmsg-1; i>=0; i--) {
m=owl_view_get_element(v, i);
if (skip_deleted && owl_message_is_delete(m)) continue;
if (f && !owl_filter_message_match(f, m)) continue;
found = 1;
break;
}
if (i<0) i=0;
if (!found) {
owl_function_makemsg("already at first%s message%s%s",
skip_deleted?" non-deleted":"",
filter?" in ":"", filter?filter:"");
/* if (!skip_deleted) owl_function_beep(); */
}
if (first_if_none || found) {
owl_global_set_curmsg(&g, i);
owl_function_calculate_topmsg(OWL_DIRECTION_UPWARDS);
owl_mainwin_redisplay(owl_global_get_mainwin(&g));
owl_global_set_direction_upwards(&g);
}
}
void owl_function_nextmsg(void)
{
owl_function_nextmsg_full(NULL, 0, 1);
}
void owl_function_prevmsg(void)
{
owl_function_prevmsg_full(NULL, 0, 1);
}
void owl_function_nextmsg_notdeleted(void)
{
owl_function_nextmsg_full(NULL, 1, 1);
}
void owl_function_prevmsg_notdeleted(void)
{
owl_function_prevmsg_full(NULL, 1, 1);
}
void owl_function_delete_and_expunge_message(int n)
{
owl_messagelist *ml = owl_global_get_msglist(&g);
owl_view *v = owl_global_get_current_view(&g);
int lastmsgid = owl_function_get_curmsg_id(v);
/* delete and expunge the message */
owl_messagelist_delete_and_expunge_element(ml, n);
owl_function_redisplay_to_nearest(lastmsgid, v);
}
void owl_function_delete_and_expunge_cur(bool exclaim_success)
{
int curmsg;
const owl_view *v = owl_global_get_current_view(&g);
/* bail if there's no current message */
if (owl_view_get_size(v) < 1) {
owl_function_error("No current message to delete");
return;
}
/* delete the current message */
curmsg = owl_global_get_curmsg(&g);
owl_function_delete_and_expunge_message(curmsg);
if (exclaim_success)
owl_function_makemsg("Message deleted and expunged");
}
/* if move_after is 1, moves after the delete */
void owl_function_deletecur(int move_after)
{
int curmsg;
owl_view *v;
v=owl_global_get_current_view(&g);
/* bail if there's no current message */
if (owl_view_get_size(v) < 1) {
owl_function_error("No current message to delete");
return;
}
/* mark the message for deletion */
curmsg=owl_global_get_curmsg(&g);
owl_view_delete_element(v, curmsg);
if (move_after) {
/* move the poiner in the appropriate direction
* to the next undeleted msg */
if (owl_global_get_direction(&g)==OWL_DIRECTION_UPWARDS) {
owl_function_prevmsg_notdeleted();
} else {
owl_function_nextmsg_notdeleted();
}
}
}
void owl_function_undeletecur(int move_after)
{
int curmsg;
owl_view *v;
v=owl_global_get_current_view(&g);
if (owl_view_get_size(v) < 1) {
owl_function_error("No current message to undelete");
return;
}
curmsg=owl_global_get_curmsg(&g);
owl_view_undelete_element(v, curmsg);
if (move_after) {
if (owl_global_get_direction(&g)==OWL_DIRECTION_UPWARDS) {
if (curmsg>0) {
owl_function_prevmsg();
} else {
owl_function_nextmsg();
}
} else {
owl_function_nextmsg();
}
}
owl_mainwin_redisplay(owl_global_get_mainwin(&g));
}
/* returns the current message id, if it exists. Otherwise returns
* -1 if we are past the end of the message list, and 0 otherwise. */
int owl_function_get_curmsg_id(const owl_view *v)
{
int curmsg = owl_global_get_curmsg(&g);
const owl_message *m = owl_view_get_element(v, curmsg);
if (m)
return owl_message_get_id(m);
if (curmsg > 0) /* past the end of the message list (probably) */
return -1;
return 0;
}
/* redisplays the view to the nearest message to the id given.
* if msgid < 0, redisplay to past the end of the message list */
void owl_function_redisplay_to_nearest(int msgid, owl_view *v)
{
int curmsg;
/* update all views (we only have one right now) */
owl_view_recalculate(v);
/* find where the new position should be */
if (msgid < 0) {
/* If already at the end, blank the screen and move curmsg
* past the end of the messages. */
curmsg = owl_view_get_size(v);
owl_global_set_topmsg(&g, curmsg);
owl_global_set_curmsg(&g, curmsg);
} else {
curmsg = owl_view_get_nearest_to_msgid(v, msgid);
if (curmsg > owl_view_get_size(v) - 1)
curmsg = owl_view_get_size(v) - 1;
if (curmsg < 0)
curmsg = 0;
owl_global_set_curmsg(&g, curmsg);
owl_function_calculate_topmsg(OWL_DIRECTION_NONE);
}
/* if there are no messages set the direction to down in case we
* delete everything upwards */
owl_global_set_direction_downwards(&g);
owl_mainwin_redisplay(owl_global_get_mainwin(&g));
}
void owl_function_expunge(void)
{
owl_messagelist *ml = owl_global_get_msglist(&g);
owl_view *v = owl_global_get_current_view(&g);
int lastmsgid = owl_function_get_curmsg_id(v);
/* expunge the message list */
owl_messagelist_expunge(ml);
owl_function_redisplay_to_nearest(lastmsgid, v);
owl_function_makemsg("Messages expunged");
}
void owl_function_firstmsg(void)
{
owl_global_set_curmsg(&g, 0);
owl_global_set_topmsg(&g, 0);
owl_mainwin_redisplay(owl_global_get_mainwin(&g));
owl_global_set_direction_downwards(&g);
}
void owl_function_lastmsg(void)
{
int oldcurmsg, curmsg;
const owl_view *v;
v=owl_global_get_current_view(&g);
oldcurmsg=owl_global_get_curmsg(&g);
curmsg=owl_view_get_size(v)-1;
if (curmsg<0) curmsg=0;
owl_global_set_curmsg(&g, curmsg);
if (oldcurmsg < curmsg) {
owl_function_calculate_topmsg(OWL_DIRECTION_DOWNWARDS);
} else if (curmsg<owl_view_get_size(v)) {
/* If already at the end, blank the screen and move curmsg
* past the end of the messages. */
owl_global_set_topmsg(&g, curmsg+1);
owl_global_set_curmsg(&g, curmsg+1);
}
owl_mainwin_redisplay(owl_global_get_mainwin(&g));
owl_global_set_direction_downwards(&g);
}
void owl_function_shift_right(void)
{
owl_global_set_rightshift(&g, owl_global_get_rightshift(&g)+10);
}
void owl_function_shift_left(void)
{
int shift;
shift=owl_global_get_rightshift(&g);
if (shift > 0) {
owl_global_set_rightshift(&g, MAX(shift - 10, 0));
} else {
owl_function_beep();
owl_function_makemsg("Already full left");
}
}
void owl_function_unsuball(void)
{
if (unsuball())
owl_function_makemsg("Unsubscribed from all messages.");
}
/* Load zephyr subscriptions from the named 'file' and load zephyr's
* default subscriptions as well. An error message is printed if
* 'file' can't be opened or if zephyr reports an error in
* subscribing.
*
* If 'file' is NULL, this look for the default filename
* $HOME/.zephyr.subs. If the file can not be opened in this case
* only, no error message is printed.
*/
void owl_function_loadsubs(const char *file)
{
int ret, ret2, ret3;
char *path;
if (file==NULL) {
ret=owl_zephyr_loadsubs(NULL, 0);
} else {
path = owl_util_makepath(file);
ret=owl_zephyr_loadsubs(path, 1);
g_free(path);
}
/* for backwards compatibility for now */
ret2 = owl_zephyr_loaddefaultsubs();
ret3 = owl_zephyr_loadbarnowldefaultsubs();
if (!owl_context_is_interactive(owl_global_get_context(&g))) return;
if (ret == 0 && ret2 == 0 && ret3 == 0) {
if (!file) {
owl_function_makemsg("Subscribed to messages.");
} else {
owl_function_makemsg("Subscribed to messages from %s", file);
}
} else if (ret == -1) {
owl_function_error("Could not read %s", file ? file : "file");
} else if (ret2 == -1) {
owl_function_error("Error subscribing to messages");
} else {
owl_function_error("Error subscribing to instanced personals");
}
}
void owl_function_loadloginsubs(const char *file)
{
int ret;
ret=owl_zephyr_loadloginsubs(file);
if (!owl_context_is_interactive(owl_global_get_context(&g))) return;
if (ret==0) {
} else if (ret==-1) {
owl_function_error("Could not open file for login subscriptions.");
} else {
owl_function_error("Error subscribing to login messages from file.");
}
}
void owl_callback_aimlogin(owl_editwin *e, bool success)
{
if (!success) return;
char *user = owl_editwin_get_cbdata(e);
owl_function_aimlogin(user,
owl_editwin_get_text(e));
}
void owl_function_aimlogin(const char *user, const char *passwd) {
int ret;
/* clear the buddylist */
owl_buddylist_clear(owl_global_get_buddylist(&g));
/* try to login */
ret=owl_aim_login(user, passwd);
if (ret) owl_function_makemsg("Warning: login for %s failed.\n", user);
}
void owl_function_suspend(void)
{
endwin();
printf("\n");
kill(getpid(), SIGSTOP);
/* resize to reinitialize all the windows when we come back */
owl_command_resize();
}
void owl_function_zaway_toggle(void)
{
if (!owl_global_is_zaway(&g)) {
owl_global_set_zaway_msg(&g, owl_global_get_zaway_msg_default(&g));
owl_function_zaway_on();
} else {
owl_function_zaway_off();
}
}
void owl_function_zaway_on(void)
{
owl_global_set_zaway_on(&g);
owl_function_makemsg("zaway set (%s)", owl_global_get_zaway_msg(&g));
}
void owl_function_zaway_off(void)
{
owl_global_set_zaway_off(&g);
owl_function_makemsg("zaway off");
}
void owl_function_aaway_toggle(void)
{
if (!owl_global_is_aaway(&g)) {
owl_global_set_aaway_msg(&g, owl_global_get_aaway_msg_default(&g));
owl_function_aaway_on();
} else {
owl_function_aaway_off();
}
}
void owl_function_aaway_on(void)
{
owl_global_set_aaway_on(&g);
/* owl_aim_set_awaymsg(owl_global_get_zaway_msg(&g)); */
owl_function_makemsg("AIM away set (%s)", owl_global_get_aaway_msg(&g));
}
void owl_function_aaway_off(void)
{
owl_global_set_aaway_off(&g);
/* owl_aim_set_awaymsg(""); */
owl_function_makemsg("AIM away off");
}
bool owl_function_is_away(void)
{
return owl_global_is_zaway(&g) ||
owl_global_is_aaway(&g) ||
owl_perlconfig_perl_call_bool("BarnOwl::Hooks::_get_is_away", 0, NULL);
}