emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Store link in message mode
@ 2010-11-15 12:43 Ulf Stegemann
  2010-11-15 15:17 ` Tassilo Horn
  2011-02-08 16:00 ` Bastien
  0 siblings, 2 replies; 9+ messages in thread
From: Ulf Stegemann @ 2010-11-15 12:43 UTC (permalink / raw)
  To: emacs-orgmode

After it's now possible for me to store an org link upon sending a
message[1] I thought it might be even better to approach this problem in
a more general way.  The idea is to use `org-store-link' in message mode
to create a link for the (yet to come) copy of the message.

Currently `org-store-link' seems to be rather pointless in message mode
as it creates a link to a draft (temporary) message file.  Extending
`org-gnus-store-link' to let it create a gnus link to the copy of the
message when in message mode seems to be more reasonable.

However, there are some, er, `issues' with this.

1) This will only work with Gnus.  Message mode is in principle
   independent of Gnus but non-Gnus users will not benefit from
   `org-store-link' in message mode.

2) Storing a link in message mode effectively creates a link to
   something (the mail copy) that's (still) inexistent.  This means that
   the link remains invalid until the message is actually sent (or more
   precisely: the copy is created upon sending).

   Furthermore, the link will be invalid if

   - the message is not sent;
   - the Gcc header is modified to point to a different group;
   - the message id is changed.

   And of course, the link description will be incorrect if Subject,
   From and/or To headers are changed between calling `org-store-link'
   and creating the message's copy.

If you think --despite of those issues-- it's worth adding the creation
of gnus links while in message mode I could provide a patch.  I'd
probably add the functionality to `org-gnus-store-link' but I'm not an
org code expert and a different location may be more appropriate.  What
do you think?

Ulf

References:
[1]  see http://thread.gmane.org/gmane.emacs.orgmode/31280

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

* Re: Store link in message mode
  2010-11-15 12:43 Store link in message mode Ulf Stegemann
@ 2010-11-15 15:17 ` Tassilo Horn
  2010-11-15 16:00   ` Ulf Stegemann
  2010-11-16 13:22   ` Łukasz Stelmach
  2011-02-08 16:00 ` Bastien
  1 sibling, 2 replies; 9+ messages in thread
From: Tassilo Horn @ 2010-11-15 15:17 UTC (permalink / raw)
  To: emacs-orgmode

Ulf Stegemann <ulf-news@zeitform.de> writes:

Hi Ulf,

> If you think --despite of those issues-- it's worth adding the
> creation of gnus links while in message mode I could provide a patch.

I'm curious how you are able to determine where a message will be filed
after sending it off.  I mean, you neither have the Message-Id at that
point (unless that's added to `message-generate-headers-first'), nor do
you know the correct group, at least if there are more than one in the
Gcc header.

Bye,
Tassilo

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

* Re: Store link in message mode
  2010-11-15 15:17 ` Tassilo Horn
@ 2010-11-15 16:00   ` Ulf Stegemann
  2010-11-16 13:22   ` Łukasz Stelmach
  1 sibling, 0 replies; 9+ messages in thread
From: Ulf Stegemann @ 2010-11-15 16:00 UTC (permalink / raw)
  To: emacs-orgmode

Hi Tassilo,

Tassilo Horn <tassilo@member.fsf.org> wrote:

>> If you think --despite of those issues-- it's worth adding the
>> creation of gnus links while in message mode I could provide a patch.
>
> I'm curious how you are able to determine where a message will be filed
> after sending it off.  I mean, you neither have the Message-Id at that
> point (unless that's added to `message-generate-headers-first'),

Touché, good point.  I had set `message-generate-headers-first' to t
ages ago, so obviously I didn't realise that this is not the default.
You are absolutely right that generating the Message-ID during message
setup is a perquisite for creating a link.

It's probably better, to grab all necessary headers after the message
has been sent (and that's what I originally did).  But this means we
cannot use `org-store-link' in message mode and is also impractical when
using `gnus-delay-article'.

Hmmm, thinking about it, maybe `org-store-link' could create the
Message-ID and insert it if it's not already present.  I should have a
look.

> nor do you know the correct group, at least if there are more than one
> in the Gcc header.

With multiple groups in Gcc I currently use the last one ... but it
could also be the first one, all, a user specified or whatever else
seems feasible.

Ulf

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

* Re: Store link in message mode
  2010-11-15 15:17 ` Tassilo Horn
  2010-11-15 16:00   ` Ulf Stegemann
@ 2010-11-16 13:22   ` Łukasz Stelmach
  2010-11-17 14:29     ` Tassilo Horn
  1 sibling, 1 reply; 9+ messages in thread
From: Łukasz Stelmach @ 2010-11-16 13:22 UTC (permalink / raw)
  To: emacs-orgmode

Tassilo Horn <tassilo@member.fsf.org> writes:

> Ulf Stegemann <ulf-news@zeitform.de> writes:
>
>> If you think --despite of those issues-- it's worth adding the
>> creation of gnus links while in message mode I could provide a patch.
>
> I'm curious how you are able to determine where a message will be filed
> after sending it off.  I mean, you neither have the Message-Id at that
> point (unless that's added to `message-generate-headers-first'), nor do
> you know the correct group, at least if there are more than one in the
> Gcc header.

There is a facility in Gnus called <info:(gnus)The Gnus Registry>
which I havn't investigated yet but it looks promising. From what I've
browsed the info it looks like it registers all the message ids and
remembers the folders. So it would be enough to remember the MID and
then make Gnus find it.

-- 
Miłego dnia,
Łukasz Stelmach

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

* Re: Store link in message mode
  2010-11-16 13:22   ` Łukasz Stelmach
@ 2010-11-17 14:29     ` Tassilo Horn
  2010-11-20 19:05       ` Łukasz Stelmach
  0 siblings, 1 reply; 9+ messages in thread
From: Tassilo Horn @ 2010-11-17 14:29 UTC (permalink / raw)
  To: emacs-orgmode

Łukasz Stelmach <lukasz.stelmach@iem.pw.edu.pl> writes:

Hi Łukasz,

>>> If you think --despite of those issues-- it's worth adding the
>>> creation of gnus links while in message mode I could provide a
>>> patch.
>>
>> I'm curious how you are able to determine where a message will be
>> filed after sending it off.  I mean, you neither have the Message-Id
>> at that point (unless that's added to
>> `message-generate-headers-first'), nor do you know the correct group,
>> at least if there are more than one in the Gcc header.
>
> There is a facility in Gnus called <info:(gnus)The Gnus Registry>
> which I havn't investigated yet but it looks promising. From what I've
> browsed the info it looks like it registers all the message ids and
> remembers the folders. So it would be enough to remember the MID and
> then make Gnus find it.

But I think a user needs to enable that explicitly, so one cannot rely
on this feature being available...  And the user has to setup
`gnus-refer-article-method' properly...

,----[ (info "(gnus)Registry Article Refer Method") ]
|    The `nnregistry' refer method does exactly that.  It has the
| advantage that an article may be found regardless of the group it's
| in--provided its `Message-ID' is known to the registry.  It can be
| enabled by augmenting the start-up file with something along these
| lines:
| 
|      ;; Keep enough entries to have a good hit rate when referring to an
|      ;; article using the registry.  Use long group names so that Gnus
|      ;; knows where the article is.
|      (setq gnus-registry-max-entries 2500
|            gnus-registry-use-long-group-names t)
| 
|      (gnus-registry-initialize)
| 
|      (setq gnus-refer-article-method
|            '(current
|              (nnregistry)
|              (nnweb "gmane" (nnweb-type gmane))))
`----

Bye,
Tassilo

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

* Re: Store link in message mode
  2010-11-17 14:29     ` Tassilo Horn
@ 2010-11-20 19:05       ` Łukasz Stelmach
  0 siblings, 0 replies; 9+ messages in thread
From: Łukasz Stelmach @ 2010-11-20 19:05 UTC (permalink / raw)
  To: emacs-orgmode

Tassilo Horn <tassilo@member.fsf.org> writes:

> Łukasz Stelmach <lukasz.stelmach@iem.pw.edu.pl> writes:
>
>>>> If you think --despite of those issues-- it's worth adding the
>>>> creation of gnus links while in message mode I could provide a
>>>> patch.
>>>
>>> I'm curious how you are able to determine where a message will be
>>> filed after sending it off.  I mean, you neither have the Message-Id
>>> at that point (unless that's added to
>>> `message-generate-headers-first'), nor do you know the correct group,
>>> at least if there are more than one in the Gcc header.
>>
>> There is a facility in Gnus called <info:(gnus)The Gnus Registry>
>> which I havn't investigated yet but it looks promising. From what I've
>> browsed the info it looks like it registers all the message ids and
>> remembers the folders. So it would be enough to remember the MID and
>> then make Gnus find it.
>
> ,----[ (info "(gnus)Registry Article Refer Method") ]
[...]
> `----

I haven't seen this piece yet. Interesting.

> But I think a user needs to enable that explicitly, so one cannot rely
> on this feature being available...  And the user has to setup
> `gnus-refer-article-method' properly...

And install Gnus and Emacs too ;-) Of course the default setup not
necessarily provide for what we are talking about. But it doesn't either
way and the registry looks as a cleaner solution (however, I am not sure
yet how to set it up on several machines in parallel) then noting Gcc
during sending. There is no simple solution to this. By simple I mean
"available without touching anything ousite org-mode". Theoretically
org-mode could implement a function that searches through Gnus' database
but thats against the DRY principle since such code itself exists in
Gnus it just needs to be configured.

-- 
Miłego dnia,
Łukasz Stelmach

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

* Re: Store link in message mode
  2010-11-15 12:43 Store link in message mode Ulf Stegemann
  2010-11-15 15:17 ` Tassilo Horn
@ 2011-02-08 16:00 ` Bastien
  2011-02-09 14:41   ` Ulf Stegemann
  2011-02-09 16:01   ` Bastien
  1 sibling, 2 replies; 9+ messages in thread
From: Bastien @ 2011-02-08 16:00 UTC (permalink / raw)
  To: Ulf Stegemann; +Cc: emacs-orgmode

Hi Ulf,

Ulf Stegemann <ulf-news@zeitform.de> writes:

> If you think --despite of those issues-- it's worth adding the creation
> of gnus links while in message mode I could provide a patch.  

FWIW, I think it would be useful.

> I'd probably add the functionality to `org-gnus-store-link' but I'm
> not an org code expert and a different location may be more
> appropriate.  What do you think?

Such a change belongs to `org-gnus-store-link' -- I'd be glad to apply a
patch to this effect.

Thanks!

-- 
 Bastien

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

* Re: Store link in message mode
  2011-02-08 16:00 ` Bastien
@ 2011-02-09 14:41   ` Ulf Stegemann
  2011-02-09 16:01   ` Bastien
  1 sibling, 0 replies; 9+ messages in thread
From: Ulf Stegemann @ 2011-02-09 14:41 UTC (permalink / raw)
  To: emacs-orgmode; +Cc: Bastien

[-- Attachment #1: Type: text/plain, Size: 1059 bytes --]

Bastien <bastien.guerry@wikimedia.fr> wrote:

> Ulf Stegemann <ulf-news@zeitform.de> writes:
>
>> If you think --despite of those issues-- it's worth adding the creation
>> of gnus links while in message mode I could provide a patch.
>
> FWIW, I think it would be useful.
>
>> I'd probably add the functionality to `org-gnus-store-link' but I'm
>> not an org code expert and a different location may be more
>> appropriate.  What do you think?
>
> Such a change belongs to `org-gnus-store-link' -- I'd be glad to apply a
> patch to this effect.

Please find a patch attached. I works for me with latest Emacs, Org,
Gnus from bzr/git but with all the limitations mentioned earlier in this
thread.

The patch includes the generation of the `Message-ID' header if none is
present.  It also removes the `message-deletable' property from that
header to prevent Gnus from re-generating the message id and thus
breaking the org link.  This should (hopefully) work regardless of the
value of `message-generate-headers-first', `message-deletable-headers'
et al.

Ulf


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: org-gnus-store-link-message-mode.diff --]
[-- Type: text/x-patch, Size: 1793 bytes --]

--- org-gnus.el.orig	2011-02-09 10:20:37.003314968 +0100
+++ org-gnus.el	2011-02-09 14:50:55.320440970 +0100
@@ -186,7 +186,35 @@
 	    link (org-gnus-article-link
 		  group	newsgroups message-id x-no-archive))
       (org-add-link-props :link link :description desc)
-      link))))
+      link))
+   ((eq major-mode 'message-mode)
+    (setq org-store-link-plist nil)  ; reset
+    (save-excursion
+      (save-restriction
+        (message-narrow-to-headers)
+        (and (not (message-fetch-field "Message-ID"))
+             (message-generate-headers '(Message-ID)))
+        (goto-char (point-min))
+        (re-search-forward "^Message-ID: *.*$" nil t)
+        (put-text-property (match-beginning 0) (match-end 0) 'message-deletable nil)
+        (let ((gcc (car (last
+                         (message-unquote-tokens
+                          (message-tokenize-header (mail-fetch-field "gcc" nil t) " ,")))))
+              (id (org-remove-angle-brackets (mail-fetch-field "Message-ID")))
+              (to (mail-fetch-field "To"))
+              (from (mail-fetch-field "From"))
+              (subject (mail-fetch-field "Subject"))
+              desc link
+              newsgroup xarchive)       ; those are always nil for gcc
+          (and (not gcc)
+               (error "Can not create link: No Gcc header found."))
+          (org-store-link-props :type "gnus" :from from :subject subject
+                                :message-id id :group gcc :to to)
+          (setq desc (org-email-link-description)
+                link (org-gnus-article-link
+                      gcc newsgroup id xarchive))
+          (org-add-link-props :link link :description desc)
+          link))))))
 
 (defun org-gnus-open-nntp (path)
   "Follow the nntp: link specified by PATH."

[-- Attachment #3: Type: text/plain, Size: 201 bytes --]

_______________________________________________
Emacs-orgmode mailing list
Please use `Reply All' to send replies to the list.
Emacs-orgmode@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-orgmode

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

* Re: Store link in message mode
  2011-02-08 16:00 ` Bastien
  2011-02-09 14:41   ` Ulf Stegemann
@ 2011-02-09 16:01   ` Bastien
  1 sibling, 0 replies; 9+ messages in thread
From: Bastien @ 2011-02-09 16:01 UTC (permalink / raw)
  To: Ulf Stegemann; +Cc: emacs-orgmode

Bastien <bastien.guerry@wikimedia.fr> writes:

> Such a change belongs to `org-gnus-store-link' -- I'd be glad to apply a
> patch to this effect.

Ulf sent me a patch that I just applied.

It allows Gnusers to create org-links from message-mode.  

This is a move toward a more general solution "org-message.el", 
handling not only Gnus but any Emacs MUA storing sent messages,
ideas and patches welcome.

Note that the link will not find drafts, just sent emails.

Thanks to Ulf for this contribution, quite useful!

-- 
 Bastien

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

end of thread, other threads:[~2011-02-09 16:01 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-11-15 12:43 Store link in message mode Ulf Stegemann
2010-11-15 15:17 ` Tassilo Horn
2010-11-15 16:00   ` Ulf Stegemann
2010-11-16 13:22   ` Łukasz Stelmach
2010-11-17 14:29     ` Tassilo Horn
2010-11-20 19:05       ` Łukasz Stelmach
2011-02-08 16:00 ` Bastien
2011-02-09 14:41   ` Ulf Stegemann
2011-02-09 16:01   ` Bastien

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).