emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* how to put into a journal info about the email sent
@ 2014-10-24 14:36 David Belohrad
  2014-10-24 15:43 ` Eric Abrahamsen
  0 siblings, 1 reply; 7+ messages in thread
From: David Belohrad @ 2014-10-24 14:36 UTC (permalink / raw)
  To: notmuch@notmuchmail.org, mailing-list-org-mode

Dear All,

i'm using org. And I'm using notmuch (that's why I address both mailing
lists). Now, writing an email in everyday bussiness requires a
non-significant time of your workhours. So I'd like to have this event
in my org agenda. So any time I send some email with a given subject,
I'd like to 'automatically' entry the information about it into
e.g. sentmails.org in form of a diary entry, with appropriate tag.

In example:

I'm sending a mail to Tom, with subject 'dealing vme register
mapping'. 

At the moment I send this email (using smtpmail), I'd like an entry in
the sentmails.org as follows:

--------------------------------------------------------------------------------
** 2014-10 October
*** 2014-10-02 Thursday
**** dealing vme register mapping                                                 :mail:
[[notmuch:id:7a97bb93e66a41878edd4c04fa764963-uuKonhrYUq+qwiivBfVWcw@public.gmane.org][dealing
vme register mapping]]
--------------------------------------------------------------------------------

I thought that I can use following

(add-hook 'message-send-hook '<mysuperfunction>)

to hook on sending and generate a capture entry. In fact this works
pretty well _EXCEPT_ the link to the mail sent. The org-store-link
cannot apparently store a link to an email, which so far was not sent
(and not received?) because it claims that

'org-gnus-store-link: Can not create link: No Gcc header found'

Hence this is pretty fatal for my diary entry. My question is: is there
any way how to link not-yet-sent/received email as an org-link? Or is
there any way to generate Gcc header before the email is sent and use
this header during sending? Or is
there any other way how to put into my agenda sent emails?

many thanks

david

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: how to put into a journal info about the email sent
  2014-10-24 14:36 how to put into a journal info about the email sent David Belohrad
@ 2014-10-24 15:43 ` Eric Abrahamsen
       [not found]   ` <87ppdhh3rh.fsf-5ibeKGLO59aIK5dEoMBc7KxOck334EZe@public.gmane.org>
  0 siblings, 1 reply; 7+ messages in thread
From: Eric Abrahamsen @ 2014-10-24 15:43 UTC (permalink / raw)
  To: emacs-orgmode

David Belohrad <david@belohrad.ch> writes:

> Dear All,
>
> i'm using org. And I'm using notmuch (that's why I address both mailing
> lists). Now, writing an email in everyday bussiness requires a
> non-significant time of your workhours. So I'd like to have this event
> in my org agenda. So any time I send some email with a given subject,
> I'd like to 'automatically' entry the information about it into
> e.g. sentmails.org in form of a diary entry, with appropriate tag.

I do something like this in Gnorb, which I'd recommend you use except
it's mostly Gnus specific.

I do it in two parts, but you could do it in one. Basically I add a
function to the `message-header-hook' (which ensures that all the
message headers have been generated properly).

The important bits look like:

(save-restriction
  (message-narrow-to-headers)
  (let ((link (and (mail-fetch-field "Gcc")
		   (org-store-link nil)))
	(org-capture-link-is-already-stored t)
	;; Collect date, subject, to, and msg-id with
	;; `mail-fetch-field'. Construct date-ts and date-ts-ia with
	;; (format-time-string
	;; (org-time-stamp-format t [t])
	;; (date-to-time date))
	)
    (if link
	(org-add-link-props
	 :date date
	 :date-timestamp date-ts
	 :date-timestamp-inactive date-ts-ia
	 :annotation link)
      (org-store-link-props
       :subject subject
       :to to
       :date date
       :date-timestamp date-ts
       :date-timestamp-inactive date-ts-ia
       :message-id msg-id
       :annotation link))
    (org-capture nil gnorb-gnus-new-todo-capture-key)))

So, if a "Gcc:" header is present, make the link using `org-store-link',
then add more fields using `org-add-link-props'. If it's not, then fake
it by storing all necessary fields using `org-store-link-props'.

Because we let `org-capture-link-is-already-stored' to t, the capture
process doesn't try to create a new link, but just uses the values we've
stored.

Obviously the downside is that, without a "Gcc:" header, org can't
actually make a real link to the message. It doesn't know where it's
going to be. However if you know that all your sent messages can be
reached with a link that looks like "notmuch:id#Message-id", then you
can make that yourself in your org capture template with something like

"[[notmuch:id#%:message-id][%:subject]]"

I hope that's not too confusing!


See:

https://github.com/girzel/gnorb/blob/master/gnorb-gnus.el#L259
https://github.com/girzel/gnorb/blob/master/gnorb-gnus.el#L437

Yours,
Eric

> In example:
>
> I'm sending a mail to Tom, with subject 'dealing vme register
> mapping'. 
>
> At the moment I send this email (using smtpmail), I'd like an entry in
> the sentmails.org as follows:
>
> --------------------------------------------------------------------------------
> ** 2014-10 October
> *** 2014-10-02 Thursday
> **** dealing vme register mapping                                                 :mail:
> [[notmuch:id:7a97bb93e66a41878edd4c04fa764963@cernfe03.cern.ch][dealing
> vme register mapping]]
> --------------------------------------------------------------------------------
>
> I thought that I can use following
>
> (add-hook 'message-send-hook '<mysuperfunction>)
>
> to hook on sending and generate a capture entry. In fact this works
> pretty well _EXCEPT_ the link to the mail sent. The org-store-link
> cannot apparently store a link to an email, which so far was not sent
> (and not received?) because it claims that
>
> 'org-gnus-store-link: Can not create link: No Gcc header found'
>
> Hence this is pretty fatal for my diary entry. My question is: is there
> any way how to link not-yet-sent/received email as an org-link? Or is
> there any way to generate Gcc header before the email is sent and use
> this header during sending? Or is
> there any other way how to put into my agenda sent emails?
>
> many thanks
>
> david

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: how to put into a journal info about the email sent
       [not found]   ` <87ppdhh3rh.fsf-5ibeKGLO59aIK5dEoMBc7KxOck334EZe@public.gmane.org>
@ 2014-10-24 15:46     ` David Edmondson
  2014-10-24 17:02       ` Eric Abrahamsen
  0 siblings, 1 reply; 7+ messages in thread
From: David Edmondson @ 2014-10-24 15:46 UTC (permalink / raw)
  To: Eric Abrahamsen, emacs-orgmode-mXXj517/zsQ; +Cc: notmuch-gxuj+Tv9EO5zyzON3hdc1g

On Fri, Oct 24 2014, Eric Abrahamsen wrote:
> David Belohrad <david-rZamiVn3bvgfv37vnLkPlQ@public.gmane.org> writes:
>
>> Dear All,
>>
>> i'm using org. And I'm using notmuch (that's why I address both mailing
>> lists). Now, writing an email in everyday bussiness requires a
>> non-significant time of your workhours. So I'd like to have this event
>> in my org agenda. So any time I send some email with a given subject,
>> I'd like to 'automatically' entry the information about it into
>> e.g. sentmails.org in form of a diary entry, with appropriate tag.
>
> I do something like this in Gnorb, which I'd recommend you use except
> it's mostly Gnus specific.
>
> I do it in two parts, but you could do it in one. Basically I add a
> function to the `message-header-hook' (which ensures that all the
> message headers have been generated properly).

Does `message-generate-headers-first' not do what you want for this
specific part?

> Obviously the downside is that, without a "Gcc:" header, org can't
> actually make a real link to the message. It doesn't know where it's
> going to be. However if you know that all your sent messages can be
> reached with a link that looks like "notmuch:id#Message-id", then you
> can make that yourself in your org capture template with something like

As you suggest, know the message-id should be good enough to generate a
notmuch link, though you may have to wait for the notmuch index to be
updated for the link to be valid.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: how to put into a journal info about the email sent
  2014-10-24 15:46     ` David Edmondson
@ 2014-10-24 17:02       ` Eric Abrahamsen
       [not found]         ` <87a94lh04t.fsf-5ibeKGLO59aIK5dEoMBc7KxOck334EZe@public.gmane.org>
  0 siblings, 1 reply; 7+ messages in thread
From: Eric Abrahamsen @ 2014-10-24 17:02 UTC (permalink / raw)
  To: notmuch-gxuj+Tv9EO5zyzON3hdc1g; +Cc: emacs-orgmode-mXXj517/zsQ

David Edmondson <dme-zDQXUQW/Few@public.gmane.org> writes:

> On Fri, Oct 24 2014, Eric Abrahamsen wrote:
>> David Belohrad <david-rZamiVn3bvgfv37vnLkPlQ@public.gmane.org> writes:
>>
>>> Dear All,
>>>
>>> i'm using org. And I'm using notmuch (that's why I address both mailing
>>> lists). Now, writing an email in everyday bussiness requires a
>>> non-significant time of your workhours. So I'd like to have this event
>>> in my org agenda. So any time I send some email with a given subject,
>>> I'd like to 'automatically' entry the information about it into
>>> e.g. sentmails.org in form of a diary entry, with appropriate tag.
>>
>> I do something like this in Gnorb, which I'd recommend you use except
>> it's mostly Gnus specific.
>>
>> I do it in two parts, but you could do it in one. Basically I add a
>> function to the `message-header-hook' (which ensures that all the
>> message headers have been generated properly).
>
> Does `message-generate-headers-first' not do what you want for this
> specific part?

Yeah, I think I looked at that previously. But this thing is going in a
hook anyway, might as well use the hook that *doesn't* require me to
call that function explicitly.

>> Obviously the downside is that, without a "Gcc:" header, org can't
>> actually make a real link to the message. It doesn't know where it's
>> going to be. However if you know that all your sent messages can be
>> reached with a link that looks like "notmuch:id#Message-id", then you
>> can make that yourself in your org capture template with something like
>
> As you suggest, know the message-id should be good enough to generate a
> notmuch link, though you may have to wait for the notmuch index to be
> updated for the link to be valid.

Yup, I've got the same issue with nnimap -- you have to wait for the
next sync to get access to the message. So far it hasn't been a problem,
though.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: how to put into a journal info about the email sent
       [not found]         ` <87a94lh04t.fsf-5ibeKGLO59aIK5dEoMBc7KxOck334EZe@public.gmane.org>
@ 2014-10-29 13:09           ` David Belohrad
       [not found]             ` <uaxd29bt43r.fsf-l29r6ovuLp4041QeWSbL1u1GAupnlqi7@public.gmane.org>
  0 siblings, 1 reply; 7+ messages in thread
From: David Belohrad @ 2014-10-29 13:09 UTC (permalink / raw)
  To: Eric Abrahamsen, notmuch-gxuj+Tv9EO5zyzON3hdc1g; +Cc: emacs-orgmode-mXXj517/zsQ

dear all,

thanks for fruitful hints. Based on what you've done I have setup it as
follows:

1) the capture template, which uses clipboard buffer to setup the
   data. So my org-capture-templates contains this entry:
   
   ("@" "Email outgoing sync. USED INTERNALLY" entry (file+datetree (concat my-org-files "emails_sent.org"))
   "* EMAIL %c :EMAIL:\n%?\nEntered on %T\n")

2) function which generates the notmuch link based on the message id:

  (defun org-notmuch-track-outgoing-emails()
         (save-restriction
         (message-narrow-to-headers)
            (let ((link (mail-fetch-field "Message-ID"))
                  (subject (mail-fetch-field "Subject"))
                  (to (mail-fetch-field "To"))
                  (date (mail-fetch-field "Date"))
                  (msg-id (mail-fetch-field "Message-ID"))
                  ;; `mail-fetch-field'. Construct date-ts and date-ts-ia with
                  ;;(date-ts (format-time-string (org-time-stamp-format t [t]) (date-to-time (mail-fetch-field "Date"))))
                  )
                  (if link
                      ;; messageid exists, we can link it
                      (kill-new (concat "[[notmuch:id:" msg-id "][" subject "]]")))
            ;; use special template to fill in
                  (org-capture nil "@")
                    )
                  )
            )

3) hook to run the function when headers are created:

(add-hook 'message-header-hook 'org-notmuch-track-outgoing-emails)



The three what they do is that whenever I send an email, a new diary
style entry is setup in the editting buffer, where the timestamp, email
link and an EMAIL tag are already pre-filled. So unless I want to add
another tags, sending email is by default a -two times- C-c C-c combo. 

Bettern than nothing, but still far from being perfect due to two
things:

- 'standard' behaviour is, that the email sent becomes read-only so with
  'q' keystroke I can bury the buffer with the email. However when I
  have implemented this, I have noticed that when I 'confirm' the
  template, I go back into the buffer 'sent mail to...', but this the
  *THE BUFFER IS NOT READ ONLY* and 'q' will just generate a character,
  and then I have to kill this buffer using C-x k with additional 'yes'
  because the buffer was modified. Quite annoying and I don't know how
  to resolve this

- second thing is, that I'd like to avoid at all opening the capture
  template and just dump it into the file without any modifications
  ongoing. The only 'modification' which comes into my mind is a setup
  of an additional tag describing the email being attached to some
  project...

Any help on those two is highly appreciated :)

.d.



Eric Abrahamsen <eric-5ibeKGLO59aIK5dEoMBc7KxOck334EZe@public.gmane.org> writes:

> David Edmondson <dme-zDQXUQW/Few@public.gmane.org> writes:
>
>> On Fri, Oct 24 2014, Eric Abrahamsen wrote:
>>> David Belohrad <david-rZamiVn3bvgfv37vnLkPlQ@public.gmane.org> writes:
>>>
>>>> Dear All,
>>>>
>>>> i'm using org. And I'm using notmuch (that's why I address both mailing
>>>> lists). Now, writing an email in everyday bussiness requires a
>>>> non-significant time of your workhours. So I'd like to have this event
>>>> in my org agenda. So any time I send some email with a given subject,
>>>> I'd like to 'automatically' entry the information about it into
>>>> e.g. sentmails.org in form of a diary entry, with appropriate tag.
>>>
>>> I do something like this in Gnorb, which I'd recommend you use except
>>> it's mostly Gnus specific.
>>>
>>> I do it in two parts, but you could do it in one. Basically I add a
>>> function to the `message-header-hook' (which ensures that all the
>>> message headers have been generated properly).
>>
>> Does `message-generate-headers-first' not do what you want for this
>> specific part?
>
> Yeah, I think I looked at that previously. But this thing is going in a
> hook anyway, might as well use the hook that *doesn't* require me to
> call that function explicitly.
>
>>> Obviously the downside is that, without a "Gcc:" header, org can't
>>> actually make a real link to the message. It doesn't know where it's
>>> going to be. However if you know that all your sent messages can be
>>> reached with a link that looks like "notmuch:id#Message-id", then you
>>> can make that yourself in your org capture template with something like
>>
>> As you suggest, know the message-id should be good enough to generate a
>> notmuch link, though you may have to wait for the notmuch index to be
>> updated for the link to be valid.
>
> Yup, I've got the same issue with nnimap -- you have to wait for the
> next sync to get access to the message. So far it hasn't been a problem,
> though.
>
> _______________________________________________
> notmuch mailing list
> notmuch-gxuj+Tv9EO5zyzON3hdc1g@public.gmane.org
> http://notmuchmail.org/mailman/listinfo/notmuch

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: how to put into a journal info about the email sent
       [not found]             ` <uaxd29bt43r.fsf-l29r6ovuLp4041QeWSbL1u1GAupnlqi7@public.gmane.org>
@ 2014-10-29 13:41               ` David Edmondson
       [not found]                 ` <cuny4rzngbr.fsf-cKoGAlAyRl4B6mVx8Gbmpr8CxMaF4oN5@public.gmane.org>
  0 siblings, 1 reply; 7+ messages in thread
From: David Edmondson @ 2014-10-29 13:41 UTC (permalink / raw)
  To: David Belohrad, Eric Abrahamsen, notmuch-gxuj+Tv9EO5zyzON3hdc1g
  Cc: emacs-orgmode-mXXj517/zsQ

On Wed, Oct 29 2014, David Belohrad wrote:
> - 'standard' behaviour is, that the email sent becomes read-only so with
>   'q' keystroke I can bury the buffer with the email. However when I
>   have implemented this, I have noticed that when I 'confirm' the
>   template, I go back into the buffer 'sent mail to...', but this the
>   *THE BUFFER IS NOT READ ONLY* and 'q' will just generate a character,
>   and then I have to kill this buffer using C-x k with additional 'yes'
>   because the buffer was modified. Quite annoying and I don't know how
>   to resolve this

I'm unsure about this. The change below may fix it accidentally.

> - second thing is, that I'd like to avoid at all opening the capture
>   template and just dump it into the file without any modifications
>   ongoing. The only 'modification' which comes into my mind is a setup
>   of an additional tag describing the email being attached to some
>   project...

Change the template to...

    ("@" "Email outgoing sync. USED INTERNALLY" entry (file+datetree (concat my-org-files "emails_sent.org"))
    "* EMAIL %c :EMAIL:\n%?\nEntered on %T\n" :immediate-finish t)
(i.e. add ":immediate-finish t")

...and you will never see the capture buffer for this entry.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: how to put into a journal info about the email sent
       [not found]                 ` <cuny4rzngbr.fsf-cKoGAlAyRl4B6mVx8Gbmpr8CxMaF4oN5@public.gmane.org>
@ 2014-10-29 13:49                   ` David Belohrad
  0 siblings, 0 replies; 7+ messages in thread
From: David Belohrad @ 2014-10-29 13:49 UTC (permalink / raw)
  To: David Edmondson, Eric Abrahamsen, notmuch-gxuj+Tv9EO5zyzON3hdc1g
  Cc: emacs-orgmode-mXXj517/zsQ

Hi David,

yes. That works perfectly and solves both issues at the same time. Now
it is perfect!

.d.



David Edmondson <dme-zDQXUQW/Few@public.gmane.org> writes:

> On Wed, Oct 29 2014, David Belohrad wrote:
>> - 'standard' behaviour is, that the email sent becomes read-only so with
>>   'q' keystroke I can bury the buffer with the email. However when I
>>   have implemented this, I have noticed that when I 'confirm' the
>>   template, I go back into the buffer 'sent mail to...', but this the
>>   *THE BUFFER IS NOT READ ONLY* and 'q' will just generate a character,
>>   and then I have to kill this buffer using C-x k with additional 'yes'
>>   because the buffer was modified. Quite annoying and I don't know how
>>   to resolve this
>
> I'm unsure about this. The change below may fix it accidentally.
>
>> - second thing is, that I'd like to avoid at all opening the capture
>>   template and just dump it into the file without any modifications
>>   ongoing. The only 'modification' which comes into my mind is a setup
>>   of an additional tag describing the email being attached to some
>>   project...
>
> Change the template to...
>
>     ("@" "Email outgoing sync. USED INTERNALLY" entry (file+datetree (concat my-org-files "emails_sent.org"))
>     "* EMAIL %c :EMAIL:\n%?\nEntered on %T\n" :immediate-finish t)
> (i.e. add ":immediate-finish t")
>
> ...and you will never see the capture buffer for this entry.

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2014-10-29 13:49 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-10-24 14:36 how to put into a journal info about the email sent David Belohrad
2014-10-24 15:43 ` Eric Abrahamsen
     [not found]   ` <87ppdhh3rh.fsf-5ibeKGLO59aIK5dEoMBc7KxOck334EZe@public.gmane.org>
2014-10-24 15:46     ` David Edmondson
2014-10-24 17:02       ` Eric Abrahamsen
     [not found]         ` <87a94lh04t.fsf-5ibeKGLO59aIK5dEoMBc7KxOck334EZe@public.gmane.org>
2014-10-29 13:09           ` David Belohrad
     [not found]             ` <uaxd29bt43r.fsf-l29r6ovuLp4041QeWSbL1u1GAupnlqi7@public.gmane.org>
2014-10-29 13:41               ` David Edmondson
     [not found]                 ` <cuny4rzngbr.fsf-cKoGAlAyRl4B6mVx8Gbmpr8CxMaF4oN5@public.gmane.org>
2014-10-29 13:49                   ` David Belohrad

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).