|
161 | 161 | #include <dirent.h>
|
162 | 162 | #include <locale.h>
|
163 | 163 |
|
164 |
| - |
165 | 164 | #include "asterisk/paths.h" /* use various paths */
|
166 | 165 | #include "asterisk/lock.h"
|
167 | 166 | #include "asterisk/file.h"
|
|
542 | 541 | #define SENDMAIL "/usr/sbin/sendmail -t"
|
543 | 542 |
|
544 | 543 | #define SOUND_INTRO "vm-intro"
|
545 |
| -#define B64_BASEMAXINLINE 256 /*!< Buffer size for Base 64 attachment encoding */ |
546 |
| -#define B64_BASELINELEN 72 /*!< Line length for Base 64 encoded messages */ |
547 | 544 | #define EOL "\r\n"
|
548 | 545 |
|
549 | 546 | #define MAX_DATETIME_FORMAT 512
|
@@ -659,15 +656,6 @@ struct leave_vm_options {
|
659 | 656 | signed char record_gain;
|
660 | 657 | };
|
661 | 658 |
|
662 |
| -/*! \brief Structure for base64 encoding */ |
663 |
| -struct b64_baseio { |
664 |
| - int iocp; |
665 |
| - int iolen; |
666 |
| - int linelength; |
667 |
| - int ateof; |
668 |
| - unsigned char iobuf[B64_BASEMAXINLINE]; |
669 |
| -}; |
670 |
| - |
671 | 659 | /*! \brief Voicemail time zones */
|
672 | 660 | struct minivm_zone {
|
673 | 661 | char name[80]; /*!< Name of this time zone */
|
@@ -853,134 +841,6 @@ static void message_destroy_list(void)
|
853 | 841 | AST_LIST_UNLOCK(&message_templates);
|
854 | 842 | }
|
855 | 843 |
|
856 |
| -/*!\internal |
857 |
| - * \brief read buffer from file (base64 conversion) */ |
858 |
| -static int b64_inbuf(struct b64_baseio *bio, FILE *fi) |
859 |
| -{ |
860 |
| - int l; |
861 |
| - |
862 |
| - if (bio->ateof) |
863 |
| - return 0; |
864 |
| - |
865 |
| - if ((l = fread(bio->iobuf, 1, B64_BASEMAXINLINE, fi)) != B64_BASEMAXINLINE) { |
866 |
| - bio->ateof = 1; |
867 |
| - if (l == 0) { |
868 |
| - /* Assume EOF */ |
869 |
| - return 0; |
870 |
| - } |
871 |
| - } |
872 |
| - |
873 |
| - bio->iolen = l; |
874 |
| - bio->iocp = 0; |
875 |
| - |
876 |
| - return 1; |
877 |
| -} |
878 |
| - |
879 |
| -/*!\internal |
880 |
| - * \brief read character from file to buffer (base64 conversion) */ |
881 |
| -static int b64_inchar(struct b64_baseio *bio, FILE *fi) |
882 |
| -{ |
883 |
| - if (bio->iocp >= bio->iolen) { |
884 |
| - if (!b64_inbuf(bio, fi)) |
885 |
| - return EOF; |
886 |
| - } |
887 |
| - |
888 |
| - return bio->iobuf[bio->iocp++]; |
889 |
| -} |
890 |
| - |
891 |
| -/*!\internal |
892 |
| - * \brief write buffer to file (base64 conversion) */ |
893 |
| -static int b64_ochar(struct b64_baseio *bio, int c, FILE *so) |
894 |
| -{ |
895 |
| - if (bio->linelength >= B64_BASELINELEN) { |
896 |
| - if (fputs(EOL,so) == EOF) |
897 |
| - return -1; |
898 |
| - |
899 |
| - bio->linelength= 0; |
900 |
| - } |
901 |
| - |
902 |
| - if (putc(((unsigned char) c), so) == EOF) |
903 |
| - return -1; |
904 |
| - |
905 |
| - bio->linelength++; |
906 |
| - |
907 |
| - return 1; |
908 |
| -} |
909 |
| - |
910 |
| -/*!\internal |
911 |
| - * \brief Encode file to base64 encoding for email attachment (base64 conversion) */ |
912 |
| -static int base_encode(char *filename, FILE *so) |
913 |
| -{ |
914 |
| - unsigned char dtable[B64_BASEMAXINLINE]; |
915 |
| - int i,hiteof= 0; |
916 |
| - FILE *fi; |
917 |
| - struct b64_baseio bio; |
918 |
| - |
919 |
| - memset(&bio, 0, sizeof(bio)); |
920 |
| - bio.iocp = B64_BASEMAXINLINE; |
921 |
| - |
922 |
| - if (!(fi = fopen(filename, "rb"))) { |
923 |
| - ast_log(LOG_WARNING, "Failed to open file: %s: %s\n", filename, strerror(errno)); |
924 |
| - return -1; |
925 |
| - } |
926 |
| - |
927 |
| - for (i= 0; i<9; i++) { |
928 |
| - dtable[i]= 'A'+i; |
929 |
| - dtable[i+9]= 'J'+i; |
930 |
| - dtable[26+i]= 'a'+i; |
931 |
| - dtable[26+i+9]= 'j'+i; |
932 |
| - } |
933 |
| - for (i= 0; i < 8; i++) { |
934 |
| - dtable[i+18]= 'S'+i; |
935 |
| - dtable[26+i+18]= 's'+i; |
936 |
| - } |
937 |
| - for (i= 0; i < 10; i++) { |
938 |
| - dtable[52+i]= '0'+i; |
939 |
| - } |
940 |
| - dtable[62]= '+'; |
941 |
| - dtable[63]= '/'; |
942 |
| - |
943 |
| - while (!hiteof){ |
944 |
| - unsigned char igroup[3], ogroup[4]; |
945 |
| - int c,n; |
946 |
| - |
947 |
| - igroup[0]= igroup[1]= igroup[2]= 0; |
948 |
| - |
949 |
| - for (n= 0; n < 3; n++) { |
950 |
| - if ((c = b64_inchar(&bio, fi)) == EOF) { |
951 |
| - hiteof= 1; |
952 |
| - break; |
953 |
| - } |
954 |
| - igroup[n]= (unsigned char)c; |
955 |
| - } |
956 |
| - |
957 |
| - if (n> 0) { |
958 |
| - ogroup[0]= dtable[igroup[0]>>2]; |
959 |
| - ogroup[1]= dtable[((igroup[0]&3)<<4) | (igroup[1]>>4)]; |
960 |
| - ogroup[2]= dtable[((igroup[1]&0xF)<<2) | (igroup[2]>>6)]; |
961 |
| - ogroup[3]= dtable[igroup[2]&0x3F]; |
962 |
| - |
963 |
| - if (n<3) { |
964 |
| - ogroup[3]= '='; |
965 |
| - |
966 |
| - if (n<2) |
967 |
| - ogroup[2]= '='; |
968 |
| - } |
969 |
| - |
970 |
| - for (i= 0;i<4;i++) |
971 |
| - b64_ochar(&bio, ogroup[i], so); |
972 |
| - } |
973 |
| - } |
974 |
| - |
975 |
| - /* Put end of line - line feed */ |
976 |
| - if (fputs(EOL, so) == EOF) |
977 |
| - return 0; |
978 |
| - |
979 |
| - fclose(fi); |
980 |
| - |
981 |
| - return 1; |
982 |
| -} |
983 |
| - |
984 | 844 | static int get_date(char *s, int len)
|
985 | 845 | {
|
986 | 846 | struct ast_tm tm;
|
@@ -1481,7 +1341,7 @@ static int sendmail(struct minivm_template *template, struct minivm_account *vmu
|
1481 | 1341 | fprintf(p, "Content-Description: Voicemail sound attachment.\n");
|
1482 | 1342 | fprintf(p, "Content-Disposition: attachment; filename=\"voicemail%s.%s\"\n\n", counter ? counter : "", format);
|
1483 | 1343 |
|
1484 |
| - base_encode(fname, p); |
| 1344 | + ast_base64_encode_file_path(fname, p, EOL); |
1485 | 1345 | fprintf(p, "\n\n--%s--\n.\n", bound);
|
1486 | 1346 | }
|
1487 | 1347 | fclose(p);
|
|
0 commit comments