yoshinari-nomura / mhc

MHC -- Message Harmonized Calendaring system
http://www.quickhack.net/mhc/
Other
20 stars 12 forks source link

iCalendarファイルをMHCに取り込むためのパッチ #44

Open koie opened 6 years ago

koie commented 6 years ago

添付ファイルで送られてきたicsファイルをMewで開いてMHCに取り込むのを想定したパッチです。

diff --git a/bin/mhc b/bin/mhc
--- a/bin/mhc
+++ b/bin/mhc
@@ -143,6 +143,19 @@ class MhcCLI < Thor
   end # todo

   ################################################################
+  # Command: ics2mhc
+  ################################################################
+  desc "ics2mhc ICSFILE", "convert iCalender to MHC"
+
+  def ics2mhc(icalfile)
+    File.open(icalfile, "r") do |file|
+      ics_string = file.read
+      ev = Mhc::Event.new_from_ics(ics_string)
+      puts Mhc::Converter::Emacs.new.to_emacs(ev.dump_header)
+    end
+  end
+
+  ################################################################
   # Command: completions
   ################################################################
   desc "completions [COMMAND]", "List available commands or options for COMMAND", :hide => true
diff --git a/emacs/mhc.el b/emacs/mhc.el
--- a/emacs/mhc.el
+++ b/emacs/mhc.el
@@ -823,6 +823,14 @@ the default action of this command is ch
   (interactive)
   (mhc-import-from-string (current-kill 0)))

+(defun mhc-import-from-ics ()
+  (interactive)
+  (let ((mhc-header (mhc-process-send-command-with-buffer "ics2mhc" (current-buffer))))
+    (mhc-window-push)
+    (mhc-draft-new mhc-header
+                   `(("x-sc-record-id" . ,(mhc-record-create-id))
+                     ("x-sc-sequence"  . 0)))))
+
 (defun mhc-import-from-string (string)
   "Create new schedule draft from STRING."
   (with-temp-buffer
yoshinari-nomura commented 9 months ago

ありがとうございます.ちょっと考えさせてください.

手元では,mhc compose/add というコマンドが既にあって,Emacs 以外のエディタや外部ファイルから import できるようになっています.add は file.mhc を想定してたので,mhc add FILE.ical --format=ical のような記法を許すようにしたいです.