This repository has been archived by the owner on Feb 3, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathlumail.lua
1334 lines (1108 loc) · 30.2 KB
/
lumail.lua
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
----
----
--
-- When lumail launches it will look for the following configuration files:
--
-- /etc/lumail.lua
-- /etc/lumail.d/*.lua
-- ~/.lumail/config.lua
--
-- Each of these files will be loaded in turn. If none are present then
-- the client will abort with an error message.
--
-- If you wish to load additional configuration file(s) you may do so via
-- the "--rcfile" argument. Multiple additional files may be specified:
--
-- $ lumail --rcfile ./one.lua --rcfile ./two.lua
--
-- NOTE: This file will also load anything matching the pattern
-- ~/.lumail.d/*.lua - This is implemented via a call to the "load_directory"
-- primitive, which is one of the primitives that Lumail supplies.
--
---
---
--
-- The configuration file(s) are responsible for determining which keystrokes
-- are recognized, and what they will do.
--
-- The configuration file(s) can contain functions you define yourself, using
-- the Lua primitives that lumail implements internally. You can see several
-- examples online here:
--
-- http://lumail.org/examples/
--
-- The lumail primitives themselves, from which the examples are built, are
-- documented here:
--
-- http://lumail.org/lua/
--
----
----
--
--
-- This setting is used to specify the prefix for your maildir hierarchy.
--
-- (The directory specified will be processed recursively.)
--
prefix = os.getenv( "HOME" ) .. "/Maildir"
--
-- Ensure the directory exists, and abort with an error if it doesn't.
--
if ( is_directory(prefix) ) then
maildir_prefix(prefix)
else
abort( "The specified Maildir prefix isn't a directory: " .. prefix )
end
--
-- There is only one folder which is special, and that is the one where
-- lumail will record copies of outgoing mail(s).
--
-- The sent-mail folder may be specified here, if it exists:
--
-- NOTE: This is commented out by default.
--
-- if ( is_maildir( maildir_prefix() .. "/sent-mail" ) ) then
-- sent_mail( maildir_prefix() .. "/sent-mail" )
--end
--
-- Set the from address for yourself, which is used for composing/replying.
--
-- This can be changed in one of the available hooks.
--
-- In this configuration file we use the `on_folder_selection()` function
-- later on to change this on a per-folder basis.
--
default_email = "Steve Kemp <[email protected]>"
from( default_email )
--
-- Specify the outgoing mail binary.
--
-- Prefer /usr/lib/sendmail, but use /usr/sbin/sendmail if that exists
--
if ( executable( "/usr/sbin/sendmail" ) ) then
sendmail_path( "/usr/sbin/sendmail -t" )
end
if ( executable( "/usr/lib/sendmail" ) ) then
sendmail_path( "/usr/lib/sendmail -t" )
end
--
-- Specify the editor to use for composing/replying to email messages.
--
-- If this isn't set lumail will default to using the value of the
-- environmental variable "EDITOR", and if that is unset it will use
-- "vim" with no default PATH specified.
--
--
-- Here we try to use "vi", but will use "vim" in preference if both
-- are present.
--
if ( executable( "/usr/bin/vi" ) ) then
editor( "/usr/bin/vi" )
end
if ( executable( "/usr/bin/vim" ) ) then
editor( "/usr/bin/vim" )
end
--
-- Show all folders by default
--
-- When called with no arguments this function will return the current
-- setting, otherwise it will update it. This is a common pattern for lumail,
-- each of the functions which can get/set a value works in the same way.
--
-- The maildir limit can be set to three values:
--
-- all -> Show all maildir folders.
-- new -> Show all maildir folders which contain unread messages.
-- "pat" -> Show all maildir folders which match the regular expression "pat".
--
-- See "all_folders", "new_folders", and "livejournal_folders" functions for
-- example of use.
--
maildir_limit( "all" )
--
-- The maildir format controls how maildirs are displayed in maildir-mode.
--
-- Valid options are currently limited to:
--
-- $CHECK - "[x]" if the folder is selected, "[ ]" otherwise.
-- $TOTAL - The total number of messages in the maildir.
-- $NEW - The number of unread/new messages in the maildir.
-- $UNREAD - The number of unread/new messages in the maildir.
-- $READ - The number of read/old messages in the maildir.
-- $PATH - The maildir path.
-- $NAME - The maildir name (i.e. dirname($PATH)).
--
maildir_format( "$CHECK - $UNREAD/$TOTAL - $PATH" )
--
-- When opening folders we'll show all messages.
--
-- Valid options are:
--
-- all -> Show all message.
-- new -> Show all unread messages.
-- "pat" -> Show all messages which match the regular expression "pat".
--
index_limit( "all" )
--
-- The index format controls how messages are displayed inside folder lists.
--
-- Valid options are currently limited to:
--
-- $DAY (day of week)
-- $MONTH (month name)
-- $MON (month abbreviation)
-- $YEAR (year)
-- $DATE
-- $FLAGS
-- $FROM
-- $SUBJECT
-- $TO
--
--
index_format( "[$FLAGS] $DAY/$MONTH/$YEAR $FROM - $SUBJECT" )
--
-- The headers we show when displaying a mail.
--
-- (The headers displayed are presented in the order they are specified here.)
--
headers = { "$TO", "$CC", "$FROM", "$DATE", "$SUBJECT" }
--
-- Choose the highlight mode for the selected column in maildir and index mode.
-- Valid options are:
--
-- underline,standout,reverse,blink,dim,bold.
--
-- These settings might be useful if you run inside a terminal multiplexer such as tmux.
--
-- NOTE: You can use multiple values here:
--
index_highlight_mode('bold standout')
maildir_highlight_mode('bold standout')
--
-- When viewing the contents of a message it is possible to pipe
-- the body through a filter. Filters can be useful for trimming
-- excessive quotes, etc.
--
-- The utility "t-prot" is a well-known example of a filter that
-- can make an email nicer to view, and it can be used with a
-- setting such as this one:
--
-- display_filter( "t-prot -cmekatlS --bigq --pgp-move-vrf -Mmutt -L/etc/t-prot/footers -A/etc/t-prot/ads" )
--
-- The following would convert each message to be 100% upper-case
--
-- display_filter( "tr '[:lower:]' '[:upper:]'" )
--
-- Note: There is no filter by default.
--
--
-- When viewing a message the display will consist of:
--
-- The message headers.
-- The list of attachments.
-- The body of the message.
--
-- Due to recent changes in the way that attachments are viewed
-- the list of attachments will consist of both external and inline
-- attachments.
--
-- Set this value to true to disable the former:
--
-- view_inline_attachments = false
--
-- See also `view_attachments`
--
--
-- This function will invoke offlineimap, if it is installed
-- and configured for the current user.
--
-- It is called via the on_idle() function defined later.
--
function offlineimap()
if ( not file_exists( os.getenv( "HOME" ) .. "/.offlineimaprc" ) ) then
return false
end
if ( not executable( "/usr/bin/offlineimap" ) ) then
return false
end
exec( "/usr/bin/offlineimap" )
clear()
return true
end
--
-- This function is called when the client is launched.
--
-- You might consider something useful like this:
--
-- function on_start()
-- offlineimap()
-- end
--
function on_start()
show_version()
end
--
-- When there is an error in an invoked Lua function this method
-- will be called. This is true regardless of whether the error
-- came from the lua-prompt, or a function in an initialization file.
--
-- Here we display the error to the user, but only in debug-builds.
--
-- This is a trade-off, we don't want to spoil the user-experience of
-- a new user by showing too many errors, and somebody who is suspicious
-- of their function can remove the debug-check.
--
-- NOTE: DEBUG is a special defined variable, just like VERSION:
--
-- http://lumail.org/lua/DEBUG.html
--
function on_error( text )
if ( DEBUG == true ) then
msg( text )
end
end
--
-- This function is called when a folder is added/removed/toggled
-- within the selected set.
--
-- This function is a perfect place to run per-folder hooks.
--
-- Remember: More than one folder might be selected at any given time.
--
function on_folder_selection( folder )
--
-- Change the email address we use depending on our folder.
--
if ( string.find( folder, "debian-administration", 1, true ) ) then
from ("Steve <[email protected]>")
elseif ( string.find( folder, "debian" , 1, true ) ) then
from("Steve <[email protected]>")
else
from( default_email )
end
msg( "There are " .. count_messages() .. " messages present." )
end
--
-- Jump to the end of the screen, regardless of mode.
--
function jump_to_end()
mode = global_mode()
mode = string.lower( mode )
if ( string.find( mode, "maildir" ) ) then
-- Jump to last Maildir in the list.
jump_maildir_to( count_maildirs() - 1 )
elseif (string.find(mode, "index" ) ) then
-- Jump to the last message in the list.
jump_index_to( count_messages() - 1 )
else
--
-- TODO: Fix this for messages.
--
-- Jump to the end of the message.
jump_message_to( count_lines() - 2 )
end
end
--
-- Jump to the start of the screen, regardless of mode.
--
function jump_to_start()
mode = global_mode()
mode = string.lower( mode )
if ( string.find( mode, "maildir" ) ) then
-- Jump to the first Maildir
jump_maildir_to( 0 )
elseif (string.find(mode, "index" ) ) then
-- Jump to the first message.
jump_index_to( 0 )
else
--
-- TODO: Fix this for message/text
--
-- Jump to the start of the message.
jump_message_to( 0 )
end
end
--
-- This function is called when a message is displayed.
--
-- The argument is the path to the message on-disk.
--
-- Here we use the "is_new()" and "mark_read()" functions with that path.
--
-- (If the path were omitted then the current-message would be implicit.)
--
function on_read_message( path )
if ( is_new() ) then
mark_read()
end
end
--
-- This is called if the user replies "no" to the "send message?"
-- prompt which is issued at the end of the compose() and reply()
-- functions.
--
function on_message_aborted( path )
msg( "Sending message aborted." )
end
--
-- This function is called when a message is deleted.
--
-- You might save the message to ~/Maildir/.trash, or similar.
--
function on_delete_message( path )
msg( "Message deleted: " .. path )
end
--
-- Show the version of this client.
--
function show_version()
msg("This is lumail version " .. VERSION .. " from http://lumail.org/" )
end
--
-- This function is called at run-time when TAB-completion is invoked.
--
-- The function is expected to return a Lua table, the values of which
-- will be used for completion. (The keys being ignored.)
--
-- Here we add the known colours for the various colour-related primitives,
-- as well as any user-defined function.
--
-- NOTE: User-functions come from the global Lua "_G" table.
--
--
function on_complete()
--
-- Add the colours we support for the various display functions,
-- as well as the highlight options.
--
ret = {
"blue", "cyan", "green", "magenta", "red", "white", "yellow",
"blink", "bold", "dim", "reverse", "standout", "underline"
}
--
-- Add in all user-defined functions.
--
for k,v in pairs(_G) do
ret[k] = k
end
return(ret)
end
--
-- This function is called when the client exits.
--
-- It could also be used to run a final imap-sync, or similar.
--
function on_exit()
print("Lumail has now terminated.")
io.write( "That's it man, game over man, game over!\n")
end
--
-- The 'on_idle()' function is called approximately once a second,
-- when the client is idle.
--
-- Here we wrap that function up a little such that we can regularly
-- shell out to sync our mail from the remote location it is delivered.
--
-- Every second we also update the status-area to show a message.
--
do
-- Last sync time, in seconds-past-epoch.
local ls = os.time()
function on_idle()
m = global_mode()
m = string.lower( m )
str = ""
-- Set the message we'll display
if ( string.find( m, "maildir" ) ) then
str = "mode:" .. m .. " limit:" .. maildir_limit()
else
str = "mode:" .. m
end
-- Show the message & the time.
msg( str .. " time:" .. os.date("%X" ) )
-- Dump the internal Lua-stack for debug-purposes.
dump_stack()
--
-- If the time between the last sync is more than
-- five minutes resync mail.
--
ct = os.time()
if ( ( ct - ls ) >= ( 60 * 5 ) ) then
ls = ct
if ( offlineimap() ) then
msg( "offlineimap has synced your mail" )
else
msg("offlineimap not available." )
end
end
end
end
--
-- Switch to the index-view mode.
--
-- This will display the messages contained in all currently-selected folders.
--
-- (Selected folders will be displayed with a "[x]" next to them in maildir-mode.)
--
function index()
global_mode( "index" )
clear()
end
--
-- This function will be called when the global mode changes
--
-- Here we define a closure so that the previous mode can be
-- returned to easily.
--
-- (In our case this is so that when viewing a file you can revert
-- to the previous mode. See the `display_file` primitive and the
-- function named 'show_file` later in this file.)
--
do
-- We store the previous global-mode here, when changing the mode.
local pmode = ''
function on_mode_change( old, new )
-- check if we are switching from maildir to index mode, if so try to jump
-- the first unread mail or go to the last one
if string.find(old,'maildir') and string.find(new,'index') then
if (newmail_displayed()) then
jump_to_first_unread()
else
jump_to_end()
end
end
pmode = old
end
function previous_mode()
global_mode( pmode )
end
end
--
-- Test if there is currently a new message displayed
--
function newmail_displayed()
--
-- save old limit + mode
--
-- See also: http://lumail.org/examples/state.html
--
old_index_limit = index_limit()
old_global_mode = global_mode()
-- check if we can count any new messages
index_limit( "new" )
global_mode( "index" )
c = count_messages()
-- restore
index_limit( old_index_limit )
global_mode( old_global_mode )
if ( c > 0 ) then
return true
else
return false
end
end
--
-- Jump to the first unread mail starting from pos.
--
-- Do nothing if all mails are marked read
--
function jump_to_next_unread_from_pos(pos)
cur = index_offset()
count = count_messages()
i = pos
while( i < count ) do
jump_index_to( i )
if is_new() then
break
end
i = i + 1
end
if i == count then
jump_index_to(cur)
end
end
--
-- This function will jump to the first unread message. If all messages are read
-- to nothing
--
function jump_to_first_unread()
jump_to_next_unread_from_pos(0)
end
--
-- This function will jump to the next unread message.
-- If all are read do nothing
--
function jump_to_next_unread()
cur = index_offset()
jump_to_next_unread_from_pos(cur+1)
end
--
-- Switch to the maildir-mode.
--
function maildir()
global_mode( "maildir" )
clear()
end
--
-- Move to message-mode with the currently selected message.
--
function view_message()
global_mode( "message")
clear()
end
--
-- Show a file.
--
function show_file( filename )
show_file_contents(filename)
global_mode( "text" )
clear()
end
--
-- When in maildir-mode show all folders.
--
function all_folders()
maildir_limit( "all" )
clear()
end
--
-- When in maildir-mode show all folders which contain unread messages.
--
function new_folders()
maildir_limit( "new" )
clear()
end
--
-- When in maildir-mode show all folders which have a path matching
-- the given regular expression.
--
function livejournal_folders()
maildir_limit( "livejournal.[0-9]" )
clear()
end
--
-- Navigation function: Scroll "something" down.
--
function down()
m = global_mode()
if ( string.find( m, "maildir" ) ) then
scroll_maildir_down( 1 )
elseif (string.find(m, "index" ) ) then
scroll_index_down( 1 )
elseif (string.find(m, 'message') ) then
scroll_message_down( 1 )
elseif (string.find(m, 'text') ) then
scroll_text_down( 1 )
else
msg( "down() not implemented for mode:" .. m )
end
end
--
-- Navigation function: Scroll "something" up.
--
function up()
m = global_mode()
if ( string.find( m, "maildir" ) ) then
scroll_maildir_up( 1 )
elseif (string.find(m, "index" ) ) then
scroll_index_up( 1 )
elseif (string.find(m, 'message') ) then
scroll_message_up( 1 )
elseif (string.find(m, 'text') ) then
scroll_text_up( 1 )
else
msg( "up() not implemented for mode:" .. m )
end
end
--
-- Navigation function: Scroll "something" down a page.
--
function page_down()
m = global_mode()
if ( string.find( m, "maildir" ) ) then
-- The minus-two is to account for the status-area
scroll_maildir_down( screen_height() - 2 )
elseif (string.find(m, "index" ) ) then
-- The minus-two is to account for the status-area
scroll_index_down( screen_height() - 2 )
elseif (string.find(m, 'message') ) then
-- The minus-two is to account for the status-area
scroll_message_down( screen_height() - 2 )
elseif (string.find(m, 'text') ) then
-- The minus-two is to account for the status-area
scroll_text_down( screen_height() - 2 )
else
msg( "page_down() not implemented for mode:" .. m )
end
end
--
-- Navigation function: Scroll "something" up a page.
--
function page_up()
m = global_mode()
if ( string.find( m, "maildir" ) ) then
-- The minus-two is to account for the status-area
scroll_maildir_up( screen_height() - 2 )
elseif (string.find(m, "index" ) ) then
-- The minus-two is to account for the status-area
scroll_index_up( screen_height() - 2 )
elseif (string.find(m, 'message') ) then
-- The minus-two is to account for the status-area
scroll_message_up( screen_height() - 2 )
elseif (string.find(m, 'text') ) then
-- The minus-two is to account for the status-area
scroll_text_up( screen_height() - 2 )
else
msg( "page_up() not implemented for mode:" .. m )
end
end
--
-- Should we wrap lines when showing a message?
--
function toggle_line_wrapping ()
if wrap_lines == nil then
wrap_lines = true
elseif wrap_lines == true then
wrap_lines = false
elseif wrap_lines == false then
wrap_lines = true
end
end
--
-- Should we show attachments when displaying a message?
--
-- See also `view_inline_attachments`.
--
function toggle_show_attachments ()
if show_attachments == nil then
show_attachments = false
elseif show_attachments == true then
show_attachments = false
elseif show_attachments == false then
show_attachments = true
end
end
do
--
-- This variable is used to allow searches to reuse prior input.
--
local search_next_prev = ''
--
-- Search forwards given the user-specified pattern.
--
function search_next()
--
-- The search pattern.
--
x = prompt("/:" )
--
-- If the user didn't enter anything then use the previous input.
--
if ( x == "" ) then x = search_next_prev end
--
-- Save the input for the next search.
--
search_next_prev = x
--
-- Get the mode, so we can perform the correct type of search.
--
m = global_mode()
if ( string.find( m, "maildir" ) ) then
scroll_maildir_to( x )
elseif (string.find(m, "index" ) ) then
scroll_index_to( x )
elseif (string.find(m, "message" ) ) then
scroll_message_to( x )
elseif (string.find(m, "text" ) ) then
scroll_text_to( x )
else
msg( "search_next() not implemented for mode:" .. m )
end
end
end
--
-- Open a folder exclusively.
--
-- If called with no arguments it will open the folder under the
-- cursor in maildir-mode.
--
-- If called with the name of a folder it will open that specified
-- folder.
--
function open_folder(folder)
clear_selected_folders()
if ( folder ) then
set_selected_folder(folder)
else
add_selected_folder()
end
index()
end
--
-- Open my most important folders.
--
function faves()
global_mode( "index" )
-- ensure all folders are available
maildir_limit( "all" )
-- clear the currently selected folders.
clear_selected_folders()
-- The folders we care about
interesting = { "/.steve.org.uk", "/.people.kirsi", "/.edinburgh-portraits.com" }
-- For each one we're going to open
for index,name in ipairs( interesting ) do
-- Jump to first folder.
jump_maildir_to( 0 )
-- Scroll forward until we find the matching folder
scroll_maildir_to( name )
--
-- Note: "current_maildir" will return the value we've found.
--
-- We could check if the folder returned matches that which
-- we've found here. In my case I don't need to.
--
-- Add it to the selected set.
add_selected_folder()
end
-- Now we've selected our folders, open them.
global_mode( "index" )
clear()
end
--
-- Mark all messages in the current folder as read.
--
function mark_all_read()
count = count_messages()
i = 0
while( i < count ) do
jump_index_to( i )
mark_read()
i = i + 1
end
end
--
-- Return contents of the given file.
--
-- Note: Called by get_signature()
--
function file_contents(file)
local f = io.open(file, "rb")
if ( f ) then
local content = f:read("*all")
f:close()
return( content )
else
return( "Error reading file: \"" .. file .. "\"" )
end
end
--
-- This function is called when you compose an email, the return value
-- is the signature text to insert at the end of the new mail.
--
-- In this example we try to lookup a signature based on the domains of
-- the sender and the recipient. We stop at the first match.
--
-- If neither of those succeed we return the content of ~/.signature,
-- if it is present.
--
-- For example:
--
-- Given a sender of "[email protected]", and recipient of [email protected]
--
-- 1. We'd read and return the contents of ~/.sigs/example.com if present.
--
-- 2. If not we'd read and return the contents of ~/.sigs/steve.org.uk if present.
--
-- 3. If not we'd read and return the contents of ~/.signature
--
-- 4. We give up and return "".
--
function get_signature( from, to, subject )
--
-- Get the home directory, if this fails we'll return
-- an empty string.
--
home = os.getenv( "HOME" )
if ( not home ) then
return ""
end
--
-- The two addresses we'll try to process.
--
addresses = {}