|
@@ -0,0 +1,93 @@
|
|
|
+
|
|
|
+
|
|
|
+set -euo pipefail
|
|
|
+mailing_list_name=$1
|
|
|
+form_dir=$2
|
|
|
+excluded=$3
|
|
|
+
|
|
|
+
|
|
|
+db_file=~/.local/share/evolution/addressbook/system/contacts.db
|
|
|
+
|
|
|
+
|
|
|
+cp "$db_file" "$db_file.backup"
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+mapfile -t contacts < <(find ${form_dir} -type f -name "*.txt" -exec awk -F ":" '
|
|
|
+/Name:/ { name = $2 } /Email:/ { email = $2 } END {
|
|
|
+ printf "%s <%s>\n", substr(name,2), substr(email,2)
|
|
|
+}
|
|
|
+' {} \;)
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+for contact_email in "${contacts[@]}"; do
|
|
|
+
|
|
|
+
|
|
|
+ grep -Fx "$contact_email" >/dev/null < "$excluded" && echo "Skipped (excluded): '$contact_email'" && continue
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ exists=$(sqlite3 "$db_file" <<EOF
|
|
|
+.parameter init
|
|
|
+.parameter set @email "'$contact_email'"
|
|
|
+SELECT EXISTS (SELECT * FROM folder_id_email_list WHERE value = @email);
|
|
|
+EOF
|
|
|
+)
|
|
|
+ [ "$exists" == "1" ] && echo "Skipped (exists): '$contact_email'" && continue
|
|
|
+ vcard=$(sqlite3 "$db_file" <<EOF
|
|
|
+.parameter init
|
|
|
+.parameter set @list "'${mailing_list_name,,}'"
|
|
|
+SELECT vcard FROM folder_id WHERE file_as = @list;
|
|
|
+EOF
|
|
|
+)
|
|
|
+
|
|
|
+ vcard=$(awk \
|
|
|
+ -v new_email="EMAIL;X-EVOLUTION-DEST-HTML-MAIL=FALSE;X-EVOLUTION-PARENT-UID=0:$contact_email" \
|
|
|
+ -v max_width=75 '
|
|
|
+BEGIN { FS=":"; OFS=":"; found=0 }
|
|
|
+/BEGIN:VCARD/ { print $0; next }
|
|
|
+/EMAIL/ {
|
|
|
+ wrapped_email = new_email
|
|
|
+ while (length(wrapped_email) > max_width) {
|
|
|
+ print substr(wrapped_email, 1, max_width)
|
|
|
+ wrapped_email = " " substr(wrapped_email, max_width + 1)
|
|
|
+ }
|
|
|
+ print wrapped_email
|
|
|
+ print $0
|
|
|
+ found=1
|
|
|
+ next
|
|
|
+}
|
|
|
+{ buffer = buffer $0 ORS } END {
|
|
|
+ if (found == 0) {
|
|
|
+ wrapped_email = new_email
|
|
|
+ while (length(wrapped_email) > max_width) {
|
|
|
+ print substr(wrapped_email, 1, max_width)
|
|
|
+ wrapped_email = " " substr(wrapped_email, max_width + 1)
|
|
|
+ }
|
|
|
+ print wrapped_email
|
|
|
+ }
|
|
|
+ print buffer
|
|
|
+}
|
|
|
+' <<< "$vcard")
|
|
|
+ vcard=$(awk '{printf "%s\\n", $0}' <<< "$vcard")
|
|
|
+
|
|
|
+
|
|
|
+ sqlite3 "$db_file" <<EOF && echo "Added: '$contact_email'"
|
|
|
+.parameter init
|
|
|
+.parameter set @list "'${mailing_list_name,,}'"
|
|
|
+.parameter set @vcard "'${vcard}'"
|
|
|
+.parameter set @email "'$contact_email'"
|
|
|
+UPDATE folder_id SET vcard = @vcard WHERE file_as = @list;
|
|
|
+INSERT INTO folder_id_email_list (uid, value)
|
|
|
+ VALUES ((SELECT uid FROM folder_id WHERE file_as = @list), @email);
|
|
|
+EOF
|
|
|
+done
|
|
|
+
|
|
|
+echo "Restart evolution (File -> Quit) to load the changes"
|
|
|
+
|